Skip to content

Commit

Permalink
Timeout option (#330)
Browse files Browse the repository at this point in the history
* - Intoduced timeout infinite as default value for Compile-comfiguration command.
- add `--timeout` option for all remote commands.

* fix failing tests, use options without Substitute

---------

Co-authored-by: Kirill Krylov <k.krylov@reatio.om>
  • Loading branch information
kirillkrylov and Kirill Krylov authored Oct 31, 2024
1 parent 69fdee3 commit c9f27c6
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using System.Threading;
using Clio.Command;
using FluentAssertions;
using NUnit.Framework;

namespace Clio.Tests.Command.ApplicationCommand;

[TestFixture]
public class CompileConfigurationOptionsTestFixture {

[Test]
public void CanSetTimeout(){
//Arrange
RemoteCommandOptions options = new() {
TimeOut = 50
};

//Assert
options.TimeOut.Should().Be(50);
}

[Test]
public void DefaultTimeout_ShouldBe_Infinite(){
//Arrange
CompileConfigurationOptions options = new();

//Assert
options.TimeOut.Should().Be(Timeout.Infinite);
}

[Test]
public void DefaultTimeoutInReomoe_ShouldBe_100K(){
//Arrange
RemoteCommandOptions options = new();

//Assert
options.TimeOut.Should().Be(100_000);
}


[Test]
public void RestartOPtions(){
//Arrange
RestartOptions options = new();

//Assert
options.TimeOut.Should().Be(100_000);
}
}
4 changes: 2 additions & 2 deletions clio.tests/Command/RedisCommand.Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public void ClearRedisDb_FormsCorrectApplicationRequest_WhenApplicationRunsUnder
IsNetCore = false
};
RedisCommand redisCommand = new RedisCommand(applicationClient, settings);
var clearRedisOptions = Substitute.For<ClearRedisOptions>();
ClearRedisOptions clearRedisOptions = new();

//Act
redisCommand.Execute(clearRedisOptions);
Expand All @@ -39,7 +39,7 @@ public void ClearRedisDb_FormsCorrectApplicationRequest_WhenApplicationRunsUnder
IsNetCore = true
};
RedisCommand redisCommand = new RedisCommand(applicationClient, settings);
var clearRedisOptions = Substitute.For<ClearRedisOptions>();
ClearRedisOptions clearRedisOptions = new();

//Act
redisCommand.Execute(clearRedisOptions);
Expand Down
4 changes: 2 additions & 2 deletions clio.tests/Command/RestartCommand.Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public void RestartCommand_FormsCorrectApplicationRequest_WhenApplicationRunsUnd
Uri = "http://test.domain.com"
};
RestartCommand restartCommand = new RestartCommand(applicationClient, environmentSettings);
var options = Substitute.For<RestartOptions>();
RestartOptions options = new();

//Act
restartCommand.Execute(options);
Expand All @@ -44,7 +44,7 @@ public void RestartCommand_FormsCorrectApplicationRequest_WhenApplicationRunsUnd
Uri = "http://test.domain.com"
};
RestartCommand restartCommand = new RestartCommand(applicationClient, environmentSettings);
var options = Substitute.For<RestartOptions>();
RestartOptions options = new();

//Act
restartCommand.Execute(options);
Expand Down
4 changes: 3 additions & 1 deletion clio/Command/CompileConfigurationCommand.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Threading;
using Clio.Common;
using CommandLine;

Expand All @@ -15,7 +16,8 @@ public class CompileConfigurationOptions : RemoteCommandOptions
public bool All {
get; set;
}

protected override int DefaultTimeout => Timeout.Infinite;

}

#endregion
Expand Down
13 changes: 12 additions & 1 deletion clio/Command/RemoteCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,23 @@
using System.Reflection;
using Clio.Common;
using CommandLine;
using DocumentFormat.OpenXml.Spreadsheet;

namespace Clio.Command;

public class RemoteCommandOptions : EnvironmentOptions
{
public int TimeOut { get; internal set; } = 100_000;

private int? _timeOut;
protected virtual int DefaultTimeout { get; set; } = 100_000;


[Option("timeout", Required = false, HelpText = "Request timeout in milliseconds", Default = 100_000)]
public int TimeOut {
get => _timeOut ?? DefaultTimeout;
internal set => _timeOut = value;
}

public int RetryCount { get; internal set; } = 3;
public int RetryDelay { get; internal set; } = 1;

Expand Down

0 comments on commit c9f27c6

Please sign in to comment.