Skip to content

Commit

Permalink
Further logging
Browse files Browse the repository at this point in the history
  • Loading branch information
samdanaei committed Nov 7, 2024
1 parent 777d6f2 commit fdb6f03
Showing 1 changed file with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ public class ClientFileTransferRetriesTimeout : IntegrationTest
[TentacleConfigurations(scriptServiceToTest: ScriptServiceVersionToTest.None, additionalParameterTypes: new object[] { typeof(StopPortForwarderAfterFirstCallValues) })]
public async Task WhenRpcRetriesTimeOut_DuringUploadFile_TheRpcCallIsCancelled(TentacleConfigurationTestCase tentacleConfigurationTestCase, bool stopPortForwarderAfterFirstCall)
{
var driveInfos = DriveInfo.GetDrives();

Logger.Information($"WhenRpcRetriesTimeOut_DuringUploadFile_TheRpcCallIsCancelled Available Disk space before starting: {driveInfos.Select(d => $"{d.Name}: {d.AvailableFreeSpace}").ToList().StringJoin(", ")}");

PortForwarder portForwarder = null!;
await using var clientAndTentacle = await tentacleConfigurationTestCase.CreateBuilder()
// Set a short retry duration so we cancel fairly quickly
Expand Down Expand Up @@ -77,6 +81,7 @@ public async Task WhenRpcRetriesTimeOut_DuringUploadFile_TheRpcCallIsCancelled(T
.Build(CancellationToken);

portForwarder = clientAndTentacle.PortForwarder;
Logger.Information($"WhenRpcRetriesTimeOut_DuringUploadFile_TheRpcCallIsCancelled Available Disk space after clientAndTentacle.PortForwarder: {driveInfos.Select(d => $"{d.Name}: {d.AvailableFreeSpace}").ToList().StringJoin(", ")}");

var inMemoryLog = new InMemoryLog();

Expand All @@ -87,13 +92,17 @@ public async Task WhenRpcRetriesTimeOut_DuringUploadFile_TheRpcCallIsCancelled(T
var duration = Stopwatch.StartNew();
var executeScriptTask = clientAndTentacle.TentacleClient.UploadFile(remotePath, dataStream, CancellationToken, inMemoryLog);

Logger.Information($"WhenRpcRetriesTimeOut_DuringUploadFile_TheRpcCallIsCancelled Available Disk space after TentacleClient.UploadFile: {driveInfos.Select(d => $"{d.Name}: {d.AvailableFreeSpace}").ToList().StringJoin(", ")}");

var expectedException = new ExceptionContractAssertionBuilder(FailureScenario.ConnectionFaulted, tentacleConfigurationTestCase.TentacleType, clientAndTentacle).Build();

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

methodUsages.For(nameof(IAsyncClientFileTransferService.UploadFileAsync)).Started.Should().BeGreaterOrEqualTo(2);
methodUsages.For(nameof(IAsyncClientFileTransferService.DownloadFileAsync)).Started.Should().Be(0);

Logger.Information($"WhenRpcRetriesTimeOut_DuringUploadFile_TheRpcCallIsCancelled Available Disk space after assertion: {driveInfos.Select(d => $"{d.Name}: {d.AvailableFreeSpace}").ToList().StringJoin(", ")}");

// Ensure we actually waited and retried until the timeout policy kicked in
duration.Elapsed.Should().BeGreaterOrEqualTo(clientAndTentacle.RpcRetrySettings.RetryDuration - retryIfRemainingDurationAtLeastBuffer - retryBackoffBuffer);
Expand All @@ -104,7 +113,12 @@ public async Task WhenRpcRetriesTimeOut_DuringUploadFile_TheRpcCallIsCancelled(T
[Test]
[TentacleConfigurations(scriptServiceToTest: ScriptServiceVersionToTest.None)]
public async Task WhenUploadFileFails_AndTakesLongerThanTheRetryDuration_TheCallIsNotRetried_AndTimesOut(TentacleConfigurationTestCase tentacleConfigurationTestCase)
{
{

var driveInfos = DriveInfo.GetDrives();

Logger.Information($"WhenUploadFileFails_AndTakesLongerThanTheRetryDuration_TheCallIsNotRetried_AndTimesOut Available Disk space before starting: {driveInfos.Select(d => $"{d.Name}: {d.AvailableFreeSpace}").ToList().StringJoin(", ")}");

var retryDuration = TimeSpan.FromSeconds(15);

await using var clientAndTentacle = await tentacleConfigurationTestCase.CreateBuilder()
Expand Down Expand Up @@ -135,11 +149,14 @@ public async Task WhenUploadFileFails_AndTakesLongerThanTheRetryDuration_TheCall
var executeScriptTask = clientAndTentacle.TentacleClient.UploadFile(remotePath, dataStream, CancellationToken, inMemoryLog);

var expectedException = new ExceptionContractAssertionBuilder(FailureScenario.ConnectionFaulted, tentacleConfigurationTestCase.TentacleType, clientAndTentacle).Build();
Logger.Information($"WhenUploadFileFails_AndTakesLongerThanTheRetryDuration_TheCallIsNotRetried_AndTimesOut Available Disk space after expectedException: {driveInfos.Select(d => $"{d.Name}: {d.AvailableFreeSpace}").ToList().StringJoin(", ")}");

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);

Logger.Information($"WhenUploadFileFails_AndTakesLongerThanTheRetryDuration_TheCallIsNotRetried_AndTimesOut Available Disk space after assertions: {driveInfos.Select(d => $"{d.Name}: {d.AvailableFreeSpace}").ToList().StringJoin(", ")}");

inMemoryLog.ShouldHaveLoggedRetryFailureAndNoRetryAttempts();
}
Expand Down

0 comments on commit fdb6f03

Please sign in to comment.