From bcb075c380359f53bcb68f314b14826d5ec93439 Mon Sep 17 00:00:00 2001 From: Andre Hofmeister <9199345+HofmeisterAn@users.noreply.github.com> Date: Thu, 7 Nov 2024 18:44:49 +0100 Subject: [PATCH] chore: Revert changes after cherry-pick --- .../ISystemOperations.Tests.cs | 27 +++++++++---------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/test/Docker.DotNet.Tests/ISystemOperations.Tests.cs b/test/Docker.DotNet.Tests/ISystemOperations.Tests.cs index 8cc13ad0..d32e0a34 100644 --- a/test/Docker.DotNet.Tests/ISystemOperations.Tests.cs +++ b/test/Docker.DotNet.Tests/ISystemOperations.Tests.cs @@ -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 } @@ -63,7 +63,7 @@ public async Task MonitorEventsAsync_EmptyContainersList_CanBeCancelled() var progress = new Progress(); using var cts = new CancellationTokenSource(); - cts.Cancel(); + await cts.CancelAsync(); await Task.Delay(1); await Assert.ThrowsAsync(() => _dockerClient.System.MonitorEventsAsync(new ContainerEventsParameters(), progress, cts.Token)); @@ -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(() => task).ConfigureAwait(false); @@ -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( @@ -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) { @@ -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(() => task);