From c1f686df14edbdee85a482bfa52a92c5966ac49d Mon Sep 17 00:00:00 2001 From: Koundinya Veluri Date: Wed, 11 Aug 2021 15:19:17 -0700 Subject: [PATCH 1/2] Try to fix and enable a ThreadPool.CompletedWorkItemCount test and add more info about failures - Not sure why it would be failing. The test seems to be calling a different sub-test method than intended. Fixed that, updated the test to use a different temp file name in case the two relevant tests run in parallel, and added more info if it happens to fail again. - Closes https://github.com/dotnet/runtime/issues/47979 - Closes https://github.com/dotnet/runtime/issues/49700 --- .../ThreadPoolBoundHandle_IntegrationTests.cs | 7 ++++--- ...BoundHandle_IntegrationTests.netcoreapp.cs | 19 ++++++++++++++++--- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/libraries/System.Threading.Overlapped/tests/ThreadPoolBoundHandle_IntegrationTests.cs b/src/libraries/System.Threading.Overlapped/tests/ThreadPoolBoundHandle_IntegrationTests.cs index f7a3fff90cdf5..316b12557886f 100644 --- a/src/libraries/System.Threading.Overlapped/tests/ThreadPoolBoundHandle_IntegrationTests.cs +++ b/src/libraries/System.Threading.Overlapped/tests/ThreadPoolBoundHandle_IntegrationTests.cs @@ -47,13 +47,14 @@ public unsafe void SingleOperationOverSingleHandle() Assert.Equal(DATA_SIZE, result.BytesWritten); } - [Fact] + [Theory] + [InlineData(nameof(MultipleOperationsOverSingleHandle))] [PlatformSpecific(TestPlatforms.Windows)] // ThreadPoolBoundHandle.BindHandle is not supported on Unix - public unsafe void MultipleOperationsOverSingleHandle() + public unsafe void MultipleOperationsOverSingleHandle(string tempFileNamePrefix) { const int DATA_SIZE = 2; - SafeHandle handle = HandleFactory.CreateAsyncFileHandleForWrite(Path.Combine(TestDirectory, @"MultipleOperationsOverSingleHandle.tmp")); + SafeHandle handle = HandleFactory.CreateAsyncFileHandleForWrite(Path.Combine(TestDirectory, $"{tempFileNamePrefix}.tmp")); ThreadPoolBoundHandle boundHandle = ThreadPoolBoundHandle.BindHandle(handle); OverlappedContext result1 = new OverlappedContext(); diff --git a/src/libraries/System.Threading.Overlapped/tests/ThreadPoolBoundHandle_IntegrationTests.netcoreapp.cs b/src/libraries/System.Threading.Overlapped/tests/ThreadPoolBoundHandle_IntegrationTests.netcoreapp.cs index 9b18dc3fd8f57..9f3831b280240 100644 --- a/src/libraries/System.Threading.Overlapped/tests/ThreadPoolBoundHandle_IntegrationTests.netcoreapp.cs +++ b/src/libraries/System.Threading.Overlapped/tests/ThreadPoolBoundHandle_IntegrationTests.netcoreapp.cs @@ -1,6 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +using System; using System.Threading; using System.Threading.Tests; using Xunit; @@ -9,11 +10,23 @@ public partial class ThreadPoolBoundHandleTests { [Fact] [PlatformSpecific(TestPlatforms.Windows)] // ThreadPoolBoundHandle.BindHandle is not supported on Unix - [ActiveIssue("https://github.com/dotnet/runtime/issues/49700")] public unsafe void MultipleOperationsOverSingleHandle_CompletedWorkItemCountTest() { long initialCompletedWorkItemCount = ThreadPool.CompletedWorkItemCount; - MultipleOperationsOverMultipleHandles(); - ThreadTestHelpers.WaitForCondition(() => ThreadPool.CompletedWorkItemCount - initialCompletedWorkItemCount >= 2); + MultipleOperationsOverSingleHandle(nameof(MultipleOperationsOverSingleHandle_CompletedWorkItemCountTest)); + long changeInCompletedWorkItemCount = 0; + try + { + ThreadTestHelpers.WaitForCondition(() => + { + changeInCompletedWorkItemCount = ThreadPool.CompletedWorkItemCount - initialCompletedWorkItemCount; + return changeInCompletedWorkItemCount >= 2; + }); + } + catch (Exception ex) + { + // Test likely timed out, include the change for more information + throw new AggregateException($"changeInCompletedWorkItemCount: {changeInCompletedWorkItemCount}", ex); + } } } From 31405881eb66aefe9f25bf10da17c285da94f7b1 Mon Sep 17 00:00:00 2001 From: Koundinya Veluri Date: Fri, 13 Aug 2021 02:10:26 -0700 Subject: [PATCH 2/2] Undo temp file name change --- .../tests/ThreadPoolBoundHandle_IntegrationTests.cs | 7 +++---- .../ThreadPoolBoundHandle_IntegrationTests.netcoreapp.cs | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/libraries/System.Threading.Overlapped/tests/ThreadPoolBoundHandle_IntegrationTests.cs b/src/libraries/System.Threading.Overlapped/tests/ThreadPoolBoundHandle_IntegrationTests.cs index 316b12557886f..f7a3fff90cdf5 100644 --- a/src/libraries/System.Threading.Overlapped/tests/ThreadPoolBoundHandle_IntegrationTests.cs +++ b/src/libraries/System.Threading.Overlapped/tests/ThreadPoolBoundHandle_IntegrationTests.cs @@ -47,14 +47,13 @@ public unsafe void SingleOperationOverSingleHandle() Assert.Equal(DATA_SIZE, result.BytesWritten); } - [Theory] - [InlineData(nameof(MultipleOperationsOverSingleHandle))] + [Fact] [PlatformSpecific(TestPlatforms.Windows)] // ThreadPoolBoundHandle.BindHandle is not supported on Unix - public unsafe void MultipleOperationsOverSingleHandle(string tempFileNamePrefix) + public unsafe void MultipleOperationsOverSingleHandle() { const int DATA_SIZE = 2; - SafeHandle handle = HandleFactory.CreateAsyncFileHandleForWrite(Path.Combine(TestDirectory, $"{tempFileNamePrefix}.tmp")); + SafeHandle handle = HandleFactory.CreateAsyncFileHandleForWrite(Path.Combine(TestDirectory, @"MultipleOperationsOverSingleHandle.tmp")); ThreadPoolBoundHandle boundHandle = ThreadPoolBoundHandle.BindHandle(handle); OverlappedContext result1 = new OverlappedContext(); diff --git a/src/libraries/System.Threading.Overlapped/tests/ThreadPoolBoundHandle_IntegrationTests.netcoreapp.cs b/src/libraries/System.Threading.Overlapped/tests/ThreadPoolBoundHandle_IntegrationTests.netcoreapp.cs index 9f3831b280240..97fd672ba9614 100644 --- a/src/libraries/System.Threading.Overlapped/tests/ThreadPoolBoundHandle_IntegrationTests.netcoreapp.cs +++ b/src/libraries/System.Threading.Overlapped/tests/ThreadPoolBoundHandle_IntegrationTests.netcoreapp.cs @@ -13,7 +13,7 @@ public partial class ThreadPoolBoundHandleTests public unsafe void MultipleOperationsOverSingleHandle_CompletedWorkItemCountTest() { long initialCompletedWorkItemCount = ThreadPool.CompletedWorkItemCount; - MultipleOperationsOverSingleHandle(nameof(MultipleOperationsOverSingleHandle_CompletedWorkItemCountTest)); + MultipleOperationsOverSingleHandle(); long changeInCompletedWorkItemCount = 0; try {