Fix ListenerWithFilter test (dotnet/corefx#37731)
authorStephen Toub <stoub@microsoft.com>
Fri, 17 May 2019 00:31:47 +0000 (17:31 -0700)
committerGitHub <noreply@github.com>
Fri, 17 May 2019 00:31:47 +0000 (17:31 -0700)
It's searching the output to ensure the id doesn't get written out, so it can't match other IDs that are written out.

Commit migrated from https://github.com/dotnet/corefx/commit/05233fd0c0200f1fda258bab148bbae28592892d

src/libraries/System.Diagnostics.TextWriterTraceListener/tests/XmlWriterTraceListenerTests.cs

index e00f083..b883568 100644 (file)
@@ -103,15 +103,16 @@ namespace System.Diagnostics.TextWriterTraceListenerTests
         [Fact]
         public void ListenerWithFilter()
         {
-            int processId;
+            // Ensure we use an arbitrary ID that doesn't match the process ID or thread ID.
+            int traceTransferId = 1;
             using (Process p = Process.GetCurrentProcess())
             {
-                processId = p.Id;
+                while (traceTransferId == p.Id || traceTransferId == Environment.CurrentManagedThreadId)
+                {
+                    traceTransferId++;
+                }
             }
 
-            // Ensure we use an arbitrary ID that doesn't match the process ID.
-            int traceTransferId = processId + 1;
-
             string file = GetTestFilePath();
             Guid guid = Guid.NewGuid();
             using (var listener = new XmlWriterTraceListener(file))