Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanwoctopusdeploy committed Dec 1, 2023
1 parent 9cc9aca commit 3e09659
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,11 @@ public async Task WhenRpcRetriesTimeOut_DuringUploadFile_TheRpcCallIsCancelled(T
// Start the script which will wait for a file to exist
var duration = Stopwatch.StartNew();
var executeScriptTask = clientAndTentacle.TentacleClient.UploadFile(remotePath, dataStream, CancellationToken, inMemoryLog);

var expectedException = new ExceptionContractAssertionBuilder(FailureScenario.ConnectionFaulted, tentacleConfigurationTestCase, clientAndTentacle)
.ForFileTransferService(FileTransferServiceOperation.UploadFile).Build();

Func<Task> action = async () => await executeScriptTask;
await action.Should().ThrowAsync<HalibutClientException>();
await AssertionExtensions.Should(async () => await executeScriptTask).ThrowExceptionContractAsync(expectedException);
duration.Stop();

methodUsages.For(nameof(IAsyncClientFileTransferService.UploadFileAsync)).Started.Should().BeGreaterOrEqualTo(2);
Expand Down Expand Up @@ -123,8 +125,10 @@ public async Task WhenUploadFileFails_AndTakesLongerThanTheRetryDuration_TheCall
var dataStream = DataStream.FromString("The Stream");
var executeScriptTask = clientAndTentacle.TentacleClient.UploadFile(remotePath, dataStream, CancellationToken, inMemoryLog);

Func<Task> action = async () => await executeScriptTask;
await action.Should().ThrowAsync<HalibutClientException>();
var expectedException = new ExceptionContractAssertionBuilder(FailureScenario.ConnectionFaulted, tentacleConfigurationTestCase, clientAndTentacle)
.ForFileTransferService(FileTransferServiceOperation.UploadFile).Build();

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

methodUsages.For(nameof(IAsyncClientFileTransferService.UploadFileAsync)).Started.Should().Be(1);
methodUsages.For(nameof(IAsyncClientFileTransferService.DownloadFileAsync)).Started.Should().Be(0);
Expand Down Expand Up @@ -183,8 +187,11 @@ public async Task WhenRpcRetriesTimeOut_DuringDownloadFile_TheRpcCallIsCancelled
var duration = Stopwatch.StartNew();
var executeScriptTask = clientAndTentacle.TentacleClient.DownloadFile(tempFile.File.FullName, CancellationToken, inMemoryLog);

Func<Task<DataStream>> action = async () => await executeScriptTask;
await action.Should().ThrowAsync<HalibutClientException>();
var expectedException = new ExceptionContractAssertionBuilder(FailureScenario.ConnectionFaulted, tentacleConfigurationTestCase, clientAndTentacle)
.ForFileTransferService(FileTransferServiceOperation.DownloadFile).Build();

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

duration.Stop();

recordedUsages.For(nameof(IAsyncClientFileTransferService.DownloadFileAsync)).Started.Should().BeGreaterOrEqualTo(2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public async Task FailedUploadsAreNotRetriedAndFail(TentacleConfigurationTestCas
var remotePath = Path.Combine(clientTentacle.TemporaryDirectory.DirectoryPath, "UploadFile.txt");
var uploadFileTask = clientTentacle.TentacleClient.UploadFile(remotePath, DataStream.FromString("Hello"), CancellationToken);

var expectedException = new ExceptionContractAssertionBuilder(FailureScenario.ConnectionRejected, tentacleConfigurationTestCase, clientTentacle)
var expectedException = new ExceptionContractAssertionBuilder(FailureScenario.ConnectionFaulted, tentacleConfigurationTestCase, clientTentacle)
.ForFileTransferService(FileTransferServiceOperation.UploadFile).Build();

await AssertionExtensions.Should(async () => await uploadFileTask).ThrowExceptionContractAsync(expectedException);
Expand Down Expand Up @@ -86,7 +86,7 @@ public async Task FailedDownloadsAreNotRetriedAndFail(TentacleConfigurationTestC
await clientTentacle.TentacleClient.UploadFile(remotePath, DataStream.FromString("Hello"), CancellationToken);
var downloadFileTask = clientTentacle.TentacleClient.DownloadFile(remotePath, CancellationToken);

var expectedException = new ExceptionContractAssertionBuilder(FailureScenario.ConnectionRejected, tentacleConfigurationTestCase, clientTentacle)
var expectedException = new ExceptionContractAssertionBuilder(FailureScenario.ConnectionFaulted, tentacleConfigurationTestCase, clientTentacle)
.ForFileTransferService(FileTransferServiceOperation.DownloadFile).Build();

await AssertionExtensions.Should(async () => await downloadFileTask).ThrowExceptionContractAsync(expectedException);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,24 +123,28 @@ public ExceptionContract Build()

if (fileTransferServiceOperation != null)
{
if (failureScenario == FailureScenario.ConnectionRejected && tentacleConfigurationTestCase.TentacleType == TentacleType.Listening)
if (failureScenario == FailureScenario.ConnectionFaulted)
{
return new ExceptionContract(typeof(HalibutClientException), new[] { $"An error occurred when sending a request to '{clientAndTentacle.ServiceEndPoint}/', after the request began: Attempted to read past the end of the stream." });
switch (tentacleConfigurationTestCase.TentacleType)
{
case TentacleType.Listening:
return new ExceptionContract(typeof(HalibutClientException), new[]
{
$"An error occurred when sending a request to '{clientAndTentacle.ServiceEndPoint}/', after the request began: Attempted to read past the end of the stream.",
$"An error occurred when sending a request to '{clientAndTentacle.ServiceEndPoint}/', after the request began: Unable to write data to the transport connection: An established connection was aborted by the software in your host machine",
$"An error occurred when sending a request to '{clientAndTentacle.ServiceEndPoint}/', after the request began: Unable to read data from the transport connection: An established connection was aborted by the software in your host machine"
});
case TentacleType.Polling:
return new ExceptionContract(typeof(HalibutClientException), new[]
{
"Attempted to read past the end of the stream.",
"Unable to write data to the transport connection: An established connection was aborted by the software in your host machine",
"Unable to read data from the transport connection: An established connection was aborted by the software in your host machine"
});
default:
throw new ArgumentOutOfRangeException();
}
}

if (failureScenario == FailureScenario.ConnectionRejected && tentacleConfigurationTestCase.TentacleType == TentacleType.Polling)
{
return new ExceptionContract(typeof(HalibutClientException), new[] { "Attempted to read past the end of the stream." });
}

//if (fileTransferServiceOperation == FileTransferServiceOperation.UploadFile)
//{

//}
//else if (fileTransferServiceOperation == FileTransferServiceOperation.DownloadFile)
//{
// //return new ExceptionContract(typeof(DownloadFileException), new[] { "DownloadFileException" });
//}
}
else
{
Expand Down Expand Up @@ -179,7 +183,7 @@ public enum FileTransferServiceOperation
}

public enum FailureScenario
{
ConnectionRejected
{
ConnectionFaulted
}
}

0 comments on commit 3e09659

Please sign in to comment.