Skip to content

Commit

Permalink
chore: Revert changes after cherry-pick
Browse files Browse the repository at this point in the history
  • Loading branch information
HofmeisterAn committed Nov 7, 2024
1 parent ecbdcfd commit bcb075c
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions test/Docker.DotNet.Tests/ISystemOperations.Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public ISystemOperationsTests(TestFixture testFixture, ITestOutputHelper outputH
[Fact]
public void Docker_IsRunning()
{
var dockerProcess = Process.GetProcesses().FirstOrDefault(_ => _.ProcessName.Equals("docker", StringComparison.InvariantCultureIgnoreCase) || _.ProcessName.Equals("dockerd", StringComparison.InvariantCultureIgnoreCase));
var dockerProcess = Process.GetProcesses().FirstOrDefault(process => process.ProcessName.Equals("docker", StringComparison.InvariantCultureIgnoreCase) || process.ProcessName.Equals("dockerd", StringComparison.InvariantCultureIgnoreCase));
Assert.NotNull(dockerProcess); // docker is not running
}

Expand All @@ -63,7 +63,7 @@ public async Task MonitorEventsAsync_EmptyContainersList_CanBeCancelled()
var progress = new Progress<Message>();

using var cts = new CancellationTokenSource();
cts.Cancel();
await cts.CancelAsync();
await Task.Delay(1);

await Assert.ThrowsAsync<TaskCanceledException>(() => _dockerClient.System.MonitorEventsAsync(new ContainerEventsParameters(), progress, cts.Token));
Expand Down Expand Up @@ -116,7 +116,7 @@ await _dockerClient.Images.DeleteImageAsync(
// Give it some time for output operation to complete before cancelling task
await Task.Delay(TimeSpan.FromSeconds(1));

cts.Cancel();
await cts.CancelAsync();

await Assert.ThrowsAsync<OperationCanceledException>(() => task).ConfigureAwait(false);

Expand Down Expand Up @@ -144,7 +144,7 @@ public async Task MonitorEventsAsync_IsCancelled_NoStreamCorruption()
cts.Token);

// (2) Wait for some time to make sure we get into blocking IO call
await Task.Delay(100);
await Task.Delay(100, CancellationToken.None);

// (3) Invoke another request that will attempt to grab the same buffer
var listImagesTask1 = _dockerClient.Images.TagImageAsync(
Expand All @@ -153,33 +153,32 @@ public async Task MonitorEventsAsync_IsCancelled_NoStreamCorruption()
{
RepositoryName = _repositoryName,
Tag = newImageTag,
},
default);
}, CancellationToken.None);

// (4) Wait for a short bit again and cancel the monitor task - if we get lucky, we the list images call will grab the same buffer while
sw.Restart();
var iterations = rand.Next(15000000);

for (int j = 0; j < iterations; j++)
for (var j = 0; j < iterations; j++)
{
// noop
}

_output.WriteLine($"Waited for {sw.Elapsed.TotalMilliseconds} ms");

cts.Cancel();
await cts.CancelAsync();

listImagesTask1.GetAwaiter().GetResult();
await listImagesTask1;

_dockerClient.Images.TagImageAsync(
await _dockerClient.Images.TagImageAsync(
$"{_repositoryName}:{_tag}",
new ImageTagParameters
{
RepositoryName = _repositoryName,
Tag = newImageTag,
}
).GetAwaiter().GetResult();
}, CancellationToken.None);

monitorTask.GetAwaiter().GetResult();
await monitorTask;
}
catch (OperationCanceledException)
{
Expand Down Expand Up @@ -262,7 +261,7 @@ await _dockerClient.Images.TagImageAsync(
await _dockerClient.Containers.RemoveContainerAsync(createContainerResponse.ID, new ContainerRemoveParameters(), cts.Token);

await Task.Delay(TimeSpan.FromSeconds(1));
cts.Cancel();
await cts.CancelAsync();

await Assert.ThrowsAsync<OperationCanceledException>(() => task);

Expand Down

0 comments on commit bcb075c

Please sign in to comment.