Skip to content

Commit

Permalink
Merge pull request #87 from ktmitton/cancellationTokenExtensionsRemoval
Browse files Browse the repository at this point in the history
Removed CancellationTokenExtensions
  • Loading branch information
ktmitton authored Apr 17, 2022
2 parents 91c1b13 + 669ef5d commit 97d3089
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,13 @@ public class ReportingEnvironmentFixture : DockerEnvironmentFixture, Xunit.IAsyn
public SftpContainer SftpContainer { get; set; }

public override Task InitializeAsync()
=> base.InitializeAsync(new CancellationToken().CreateLinkedTimeoutToken(TimeSpan.FromMinutes(5)));
=> base.InitializeAsync(CreateTimeoutCancellationToken(TimeSpan.FromMinutes(5)));

private static CancellationToken CreateTimeoutCancellationToken(TimeSpan timeout)
{
var timeoutCancellationTokenSource = new CancellationTokenSource();
timeoutCancellationTokenSource.CancelAfter(timeout);

return timeoutCancellationTokenSource.Token;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,7 @@ public async Task ExecuteCommand_WhenCalled_ExpectResultsToBeReturned()

for (var i = 0; i < 10; ++i)
{
var health = await containerGateway.ExecuteCommandAsync(containerId, "ps aux | grep -v grep | grep sshd || exit 1", (new CancellationToken()).CreateLinkedTimeoutToken(TimeSpan.FromSeconds(5)));
var health = await containerGateway.ExecuteCommandAsync(containerId, "ps aux | grep -v grep | grep sshd || exit 1", _cancellationToken);

if (health.Any())
{
Expand All @@ -765,7 +765,7 @@ public async Task ExecuteCommand_WhenCalled_ExpectResultsToBeReturned()
}

// Act
var results = await containerGateway.ExecuteCommandAsync(containerId, "ssh-keygen -l -E md5 -f /etc/ssh/ssh_host_rsa_key.pub", (new CancellationToken()).CreateLinkedTimeoutToken(TimeSpan.FromSeconds(5)));
var results = await containerGateway.ExecuteCommandAsync(containerId, "ssh-keygen -l -E md5 -f /etc/ssh/ssh_host_rsa_key.pub", _cancellationToken);

// Assert
using var proc = new Process();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public async Task CreateAsync_WhenCalled_ExpectNetworkToBeCreatedWithTheProvided
_networkNames.Add(uniqueName);

// Act
await networkGateway.CreateAsync(uniqueName, Enumerable.Empty<Option>(), _cancellationToken.CreateLinkedTimeoutToken(TimeSpan.FromSeconds(5)));
await networkGateway.CreateAsync(uniqueName, Enumerable.Empty<Option>(), _cancellationToken);

// Assert
using var proc = new Process();
Expand Down Expand Up @@ -110,7 +110,7 @@ public async Task CreateAsync_WhenCalledWithLabels_ExpectLabelsToBeAttachedToThe
_networkNames.Add(uniqueName);

// Act
await networkGateway.CreateAsync(uniqueName, expectedOptions, _cancellationToken.CreateLinkedTimeoutToken(TimeSpan.FromSeconds(5)));
await networkGateway.CreateAsync(uniqueName, expectedOptions, _cancellationToken);

// Assert
using var proc = new Process();
Expand Down Expand Up @@ -141,7 +141,7 @@ public async Task RemoveAsync_WhenCalled_ExpectNetworkToBeRemoved()

_networkNames.Add(uniqueName);

await networkGateway.CreateAsync(uniqueName, Enumerable.Empty<Option>(), _cancellationToken.CreateLinkedTimeoutToken(TimeSpan.FromSeconds(5)));
await networkGateway.CreateAsync(uniqueName, Enumerable.Empty<Option>(), _cancellationToken);

// Act
await networkGateway.RemoveAsync(uniqueName, _cancellationToken);
Expand Down Expand Up @@ -176,7 +176,7 @@ public async Task ConnectAsync_WhenCalled_ExpectContainerToBeConnectedToNetwork(

_networkNames.Add(uniqueName);

await networkGateway.CreateAsync(uniqueName, Enumerable.Empty<Option>(), _cancellationToken.CreateLinkedTimeoutToken(TimeSpan.FromSeconds(5)));
await networkGateway.CreateAsync(uniqueName, Enumerable.Empty<Option>(), _cancellationToken);

// Act
await networkGateway.ConnectAsync(uniqueName, containerId, "test.example.com", _cancellationToken);
Expand Down
6 changes: 2 additions & 4 deletions Mittons.Fixtures/Docker/Containers/Container.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,9 @@ public Task EmptyDirectoryAsync(string directory, CancellationToken cancellation

private async Task<string> EnsureHealthyAsync(CancellationToken cancellationToken)
{
var timeoutToken = cancellationToken.CreateLinkedTimeoutToken(TimeSpan.FromMinutes(1));

while (true)
{
var healthStatus = await _containerGateway.GetHealthStatusAsync(Id, timeoutToken).ConfigureAwait(false);
var healthStatus = await _containerGateway.GetHealthStatusAsync(Id, cancellationToken).ConfigureAwait(false);

if ((healthStatus == HealthStatus.Running) || (healthStatus == HealthStatus.Healthy))
{
Expand All @@ -128,7 +126,7 @@ private async Task<string> EnsureHealthyAsync(CancellationToken cancellationToke

await Task.Delay(TimeSpan.FromMilliseconds(50)).ConfigureAwait(false);

timeoutToken.ThrowIfCancellationRequested();
cancellationToken.ThrowIfCancellationRequested();
}

return Id;
Expand Down
2 changes: 1 addition & 1 deletion Mittons.Fixtures/Docker/Containers/SftpContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public Task EmptyUserDirectoryAsync(string user, CancellationToken cancellationT

private async Task<string> GetFingerprintAsync(IContainerGateway containerGateway, string algorithm, string hash, CancellationToken cancellationToken)
{
var execResults = (await containerGateway.ExecuteCommandAsync(Id, $"ssh-keygen -l -E {hash} -f /etc/ssh/ssh_host_{algorithm}_key.pub", cancellationToken.CreateLinkedTimeoutToken(TimeSpan.FromSeconds(5))).ConfigureAwait(false)).ToArray();
var execResults = (await containerGateway.ExecuteCommandAsync(Id, $"ssh-keygen -l -E {hash} -f /etc/ssh/ssh_host_{algorithm}_key.pub", cancellationToken).ConfigureAwait(false)).ToArray();

if (execResults.Length != 1)
{
Expand Down
16 changes: 0 additions & 16 deletions Mittons.Fixtures/Extensions/CancellationTokenExtensions.cs

This file was deleted.

0 comments on commit 97d3089

Please sign in to comment.