Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanwoctopusdeploy committed Dec 5, 2023
1 parent 5d8c68d commit ddbc51f
Show file tree
Hide file tree
Showing 4 changed files with 135 additions and 99 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public async Task WhenGetCapabilitiesFails_AndTakesLongerThanTheRetryDuration_Th
await tcpConnectionUtilities.RestartTcpConnection();

// Sleep to make the initial RPC call take longer than the allowed retry duration
await Task.Delay(retryDuration + TimeSpan.FromSeconds(1));
await Task.Delay(retryDuration + TimeSpan.FromSeconds(5));

// Kill the first GetCapabilities call to force the rpc call into retries
responseMessageTcpKiller.KillConnectionOnNextResponse();
Expand All @@ -133,8 +133,11 @@ public async Task WhenGetCapabilitiesFails_AndTakesLongerThanTheRetryDuration_Th
.Build();

var executeScriptTask = clientAndTentacle.TentacleClient.ExecuteScript(startScriptCommand, CancellationToken, null, inMemoryLog);
Func<Task> action = async () => await executeScriptTask;
await action.Should().ThrowAsync<HalibutClientException>();

var expectedException = new ExceptionContractAssertionBuilder(FailureScenario.ConnectionFaulted, tentacleConfigurationTestCase, clientAndTentacle)
.ForScriptService(ScriptServiceOperation.GetCapabilities).Build();

await AssertionExtensions.Should(async () => await executeScriptTask).ThrowExceptionContractAsync(expectedException);

capabilitiesMethodUsages.For(nameof(IAsyncClientCapabilitiesServiceV2.GetCapabilitiesAsync)).Started.Should().Be(1);
scriptMethodUsages.For(nameof(IAsyncClientScriptServiceV2.StartScriptAsync)).Started.Should().Be(0, "Test should not have not proceeded past GetCapabilities");
Expand Down Expand Up @@ -195,8 +198,12 @@ public async Task WhenRpcRetriesTimeOut_DuringStartScript_TheRpcCallIsCancelled(

var duration = Stopwatch.StartNew();
var executeScriptTask = clientAndTentacle.TentacleClient.ExecuteScript(startScriptCommand, CancellationToken, null, inMemoryLog);
Func<Task> action = async () => await executeScriptTask;
await action.Should().ThrowAsync<HalibutClientException>();

var expectedException = new ExceptionContractAssertionBuilder(FailureScenario.ConnectionFaulted, tentacleConfigurationTestCase, clientAndTentacle)
.ForScriptService(ScriptServiceOperation.StartScript).Build();

await AssertionExtensions.Should(async () => await executeScriptTask).ThrowExceptionContractAsync(expectedException);

duration.Stop();

recordedUsages.For(nameof(IAsyncClientScriptServiceV2.StartScriptAsync)).Started.Should().BeGreaterOrEqualTo(2);
Expand Down Expand Up @@ -244,8 +251,11 @@ public async Task WhenStartScriptFails_AndTakesLongerThanTheRetryDuration_TheCal
.Build();

var executeScriptTask = clientAndTentacle.TentacleClient.ExecuteScript(startScriptCommand, CancellationToken, null, inMemoryLog);
Func<Task> action = async () => await executeScriptTask;
await action.Should().ThrowAsync<HalibutClientException>();

var expectedException = new ExceptionContractAssertionBuilder(FailureScenario.ConnectionFaulted, tentacleConfigurationTestCase, clientAndTentacle)
.ForScriptService(ScriptServiceOperation.StartScript).Build();

await AssertionExtensions.Should(async () => await executeScriptTask).ThrowExceptionContractAsync(expectedException);

recordedUsages.For(nameof(IAsyncClientScriptServiceV2.StartScriptAsync)).Started.Should().Be(1);
recordedUsages.For(nameof(IAsyncClientScriptServiceV2.GetStatusAsync)).Started.Should().Be(0);
Expand Down Expand Up @@ -310,8 +320,12 @@ public async Task WhenRpcRetriesTimeOut_DuringGetStatus_TheRpcCallIsCancelled(Te

var duration = Stopwatch.StartNew();
var executeScriptTask = clientAndTentacle.TentacleClient.ExecuteScript(startScriptCommand, CancellationToken, null, inMemoryLog);
Func<Task> action = async () => await executeScriptTask;
await action.Should().ThrowAsync<HalibutClientException>();

var expectedException = new ExceptionContractAssertionBuilder(FailureScenario.ConnectionFaulted, tentacleConfigurationTestCase, clientAndTentacle)
.ForScriptService(ScriptServiceOperation.GetStatus).Build();

await AssertionExtensions.Should(async () => await executeScriptTask).ThrowExceptionContractAsync(expectedException);

duration.Stop();


Expand Down Expand Up @@ -362,8 +376,11 @@ public async Task WhenGetStatusFails_AndTakesLongerThanTheRetryDuration_TheCallI
.Build();

var executeScriptTask = clientAndTentacle.TentacleClient.ExecuteScript(startScriptCommand, CancellationToken, null, inMemoryLog);
Func<Task> action = async () => await executeScriptTask;
await action.Should().ThrowAsync<HalibutClientException>();

var expectedException = new ExceptionContractAssertionBuilder(FailureScenario.ConnectionFaulted, tentacleConfigurationTestCase, clientAndTentacle)
.ForScriptService(ScriptServiceOperation.GetStatus).Build();

await AssertionExtensions.Should(async () => await executeScriptTask).ThrowExceptionContractAsync(expectedException);

recordedUsages.For(nameof(IAsyncClientScriptServiceV2.StartScriptAsync)).Started.Should().Be(1);
recordedUsages.For(nameof(IAsyncClientScriptServiceV2.GetStatusAsync)).Started.Should().Be(1);
Expand Down Expand Up @@ -443,7 +460,11 @@ public async Task WhenRpcRetriesTimeOut_DuringCancelScript_TheRpcCallIsCancelled
// We cancel script execution via the cancellation token. This should trigger the CancelScript RPC call to be made
testCancellationTokenSource.Cancel();

await action.Should().ThrowAsync<HalibutClientException>();
var expectedException = new ExceptionContractAssertionBuilder(FailureScenario.ConnectionFaulted, tentacleConfigurationTestCase, clientAndTentacle)
.ForScriptService(ScriptServiceOperation.CancelScript).Build();

await AssertionExtensions.Should(async () => await executeScriptTask).ThrowExceptionContractAsync(expectedException);

duration.Stop();

recordedUsages.For(nameof(IAsyncClientScriptServiceV2.StartScriptAsync)).Started.Should().Be(1);
Expand Down Expand Up @@ -507,7 +528,10 @@ public async Task WhenCancelScriptFails_AndTakesLongerThanTheRetryDuration_TheCa
// We cancel script execution via the cancellation token. This should trigger the CancelScript RPC call to be made
testCancellationTokenSource.Cancel();

await action.Should().ThrowAsync<HalibutClientException>();
var expectedException = new ExceptionContractAssertionBuilder(FailureScenario.ConnectionFaulted, tentacleConfigurationTestCase, clientAndTentacle)
.ForScriptService(ScriptServiceOperation.CancelScript).Build();

await AssertionExtensions.Should(async () => await executeScriptTask).ThrowExceptionContractAsync(expectedException);

recordedUsages.For(nameof(IAsyncClientScriptServiceV2.StartScriptAsync)).Started.Should().Be(1);
recordedUsages.For(nameof(IAsyncClientScriptServiceV2.GetStatusAsync)).Started.Should().BeGreaterOrEqualTo(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System.Threading;
using System.Threading.Tasks;
using FluentAssertions;
using Halibut;
using NUnit.Framework;
using Octopus.Tentacle.CommonTestUtils.Builders;
using Octopus.Tentacle.Contracts;
Expand Down Expand Up @@ -54,7 +53,12 @@ public async Task WhenNetworkFailureOccurs_DuringGetCapabilities_TheCallIsNotRet
.WithScriptBody(new ScriptBuilder().Print("hello")).Build();

var logs = new List<ProcessOutput>();
Assert.ThrowsAsync<HalibutClientException>(async () => await clientTentacle.TentacleClient.ExecuteScript(startScriptCommand, logs, CancellationToken));
var executeScriptTask = clientTentacle.TentacleClient.ExecuteScript(startScriptCommand, logs, CancellationToken);

var expectedException = new ExceptionContractAssertionBuilder(FailureScenario.ConnectionFaulted, tentacleConfigurationTestCase, clientTentacle)
.ForScriptService(ScriptServiceOperation.GetCapabilities).Build();

await AssertionExtensions.Should(async () => await executeScriptTask).ThrowExceptionContractAsync(expectedException);

var allLogs = logs.JoinLogs();

Expand Down Expand Up @@ -104,7 +108,12 @@ public async Task WhenANetworkFailureOccurs_DuringStartScript_TheCallIsNotRetrie
.Build();

var logs = new List<ProcessOutput>();
Assert.ThrowsAsync<HalibutClientException>(async () => await clientTentacle.TentacleClient.ExecuteScript(startScriptCommand, logs, CancellationToken));
var executeScriptTask = clientTentacle.TentacleClient.ExecuteScript(startScriptCommand, logs, CancellationToken);

var expectedException = new ExceptionContractAssertionBuilder(FailureScenario.ConnectionFaulted, tentacleConfigurationTestCase, clientTentacle)
.ForScriptService(ScriptServiceOperation.StartScript).Build();

await AssertionExtensions.Should(async () => await executeScriptTask).ThrowExceptionContractAsync(expectedException);

var allLogs = logs.JoinLogs();

Expand Down Expand Up @@ -155,10 +164,14 @@ public async Task WhenANetworkFailureOccurs_DuringGetStatus_TheCallIsNotRetried(
.Print("AllDone"))
.Build();

List<ProcessOutput> logs = new List<ProcessOutput>();
Logger.Information("Starting and waiting for script exec");
Assert.ThrowsAsync<HalibutClientException>(async () => await clientTentacle.TentacleClient.ExecuteScript(startScriptCommand, logs, CancellationToken));
Logger.Information("Exception thrown.");
var logs = new List<ProcessOutput>();

var executeScriptTask = clientTentacle.TentacleClient.ExecuteScript(startScriptCommand, logs, CancellationToken);

var expectedException = new ExceptionContractAssertionBuilder(FailureScenario.ConnectionFaulted, tentacleConfigurationTestCase, clientTentacle)
.ForScriptService(ScriptServiceOperation.GetStatus).Build();

await AssertionExtensions.Should(async () => await executeScriptTask).ThrowExceptionContractAsync(expectedException);

var allLogs = logs.JoinLogs();

Expand Down Expand Up @@ -219,8 +232,13 @@ public async Task WhenANetworkFailureOccurs_DuringCancelScript_TheCallIsNotRetri
.Print("AllDone"))
.Build();

List<ProcessOutput> logs = new List<ProcessOutput>();
Assert.ThrowsAsync<HalibutClientException>(async () => await clientTentacle.TentacleClient.ExecuteScript(startScriptCommand, logs, cts.Token));
var logs = new List<ProcessOutput>();
var executeScriptTask = clientTentacle.TentacleClient.ExecuteScript(startScriptCommand, logs, cts.Token);

var expectedException = new ExceptionContractAssertionBuilder(FailureScenario.ConnectionFaulted, tentacleConfigurationTestCase, clientTentacle)
.ForScriptService(ScriptServiceOperation.CancelScript).Build();

await AssertionExtensions.Should(async () => await executeScriptTask).ThrowExceptionContractAsync(expectedException);

var allLogs = logs.JoinLogs();

Expand Down Expand Up @@ -268,7 +286,7 @@ public async Task WhenANetworkFailureOccurs_DuringCompleteScript_TheCallIsNotRet
.Print("AllDone"))
.Build();

List<ProcessOutput> logs = new List<ProcessOutput>();
var logs = new List<ProcessOutput>();
await clientTentacle.TentacleClient.ExecuteScript(startScriptCommand, logs, CancellationToken);

var allLogs = logs.JoinLogs();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System.Threading;
using System.Threading.Tasks;
using FluentAssertions;
using Halibut;
using NUnit.Framework;
using Octopus.Tentacle.CommonTestUtils.Builders;
using Octopus.Tentacle.Contracts;
Expand Down Expand Up @@ -55,8 +54,13 @@ public async Task WhenANetworkFailureOccurs_DuringStartScript_WithATentacleThatO
.Print("AllDone"))
.Build();

List<ProcessOutput> logs = new List<ProcessOutput>();
Assert.ThrowsAsync<HalibutClientException>(async () => await clientTentacle.TentacleClient.ExecuteScript(startScriptCommand, logs, CancellationToken));
var logs = new List<ProcessOutput>();
var executeScriptTask = clientTentacle.TentacleClient.ExecuteScript(startScriptCommand, logs, CancellationToken);

var expectedException = new ExceptionContractAssertionBuilder(FailureScenario.ConnectionFaulted, tentacleConfigurationTestCase, clientTentacle)
.ForScriptService(ScriptServiceOperation.StartScript).Build();

await AssertionExtensions.Should(async () => await executeScriptTask).ThrowExceptionContractAsync(expectedException);

// Let the script finish.
File.WriteAllText(waitForFile, "");
Expand Down Expand Up @@ -109,10 +113,13 @@ public async Task WhenANetworkFailureOccurs_DuringGetStatus_WithATentacleThatOnl
.Print("AllDone"))
.Build();

List<ProcessOutput> logs = new List<ProcessOutput>();
Logger.Information("Starting and waiting for script exec");
Assert.ThrowsAsync<HalibutClientException>(async () => await clientTentacle.TentacleClient.ExecuteScript(startScriptCommand, logs, CancellationToken));
Logger.Information("Exception thrown.");
var logs = new List<ProcessOutput>();
var executeScriptTask = clientTentacle.TentacleClient.ExecuteScript(startScriptCommand, logs, CancellationToken);

var expectedException = new ExceptionContractAssertionBuilder(FailureScenario.ConnectionFaulted, tentacleConfigurationTestCase, clientTentacle)
.ForScriptService(ScriptServiceOperation.GetStatus).Build();

await AssertionExtensions.Should(async () => await executeScriptTask).ThrowExceptionContractAsync(expectedException);

// Let the script finish.
File.WriteAllText(waitForFile, "");
Expand Down Expand Up @@ -176,7 +183,12 @@ public async Task WhenANetworkFailureOccurs_DuringCancelScript_WithATentacleThat

var logs = new List<ProcessOutput>();

Assert.ThrowsAsync<HalibutClientException>(async () => await clientTentacle.TentacleClient.ExecuteScript(startScriptCommand, logs, cts.Token));
var executeScriptTask = clientTentacle.TentacleClient.ExecuteScript(startScriptCommand, logs, cts.Token);

var expectedException = new ExceptionContractAssertionBuilder(FailureScenario.ConnectionFaulted, tentacleConfigurationTestCase, clientTentacle)
.ForScriptService(ScriptServiceOperation.CancelScript).Build();

await AssertionExtensions.Should(async () => await executeScriptTask).ThrowExceptionContractAsync(expectedException);

var allLogs = logs.JoinLogs();
allLogs.Should().NotContain("AllDone");
Expand Down Expand Up @@ -219,13 +231,16 @@ public async Task WhenANetworkFailureOccurs_DuringCompleteScript_WithATentacleTh

var startScriptCommand = new LatestStartScriptCommandBuilder().WithScriptBody(new ScriptBuilder().Print("hello")).Build();

List<ProcessOutput> logs = new List<ProcessOutput>();
Assert.ThrowsAsync<HalibutClientException>(async () => await clientTentacle.TentacleClient.ExecuteScript(startScriptCommand, logs, CancellationToken));
var logs = new List<ProcessOutput>();
var executeScriptTask = clientTentacle.TentacleClient.ExecuteScript(startScriptCommand, logs, CancellationToken);

// We Can not verify what will be in the logs because of race conditions in tentacle.
// The last complete script which we fail might come back with the logs.
var expectedException = new ExceptionContractAssertionBuilder(FailureScenario.ConnectionFaulted, tentacleConfigurationTestCase, clientTentacle)
.ForScriptService(ScriptServiceOperation.CompleteScript).Build();

await AssertionExtensions.Should(async () => await executeScriptTask).ThrowExceptionContractAsync(expectedException);

// We Can not verify what will be in the logs because of race conditions in tentacle.
// The last complete script which we fail might come back with the logs.
recordedUsages.For(nameof(IAsyncClientScriptService.CompleteScriptAsync)).LastException.Should().NotBeNull();
recordedUsages.For(nameof(IAsyncClientScriptService.StartScriptAsync)).Started.Should().Be(1);
recordedUsages.For(nameof(IAsyncClientScriptService.CompleteScriptAsync)).Started.Should().Be(1);
Expand Down
Loading

0 comments on commit ddbc51f

Please sign in to comment.