[treadpool] Fix flaky System.Threading.ThreadTest.SetNameInThreadPoolThread test...
[mono.git] / mcs / class / corlib / Test / System.Threading / ThreadTest.cs
index 4c6694f1e17f137b4112f86e51c0081a24041b53..a84fa27a77d742a5faaebda98b46758d2bff70e6 100644 (file)
@@ -13,6 +13,7 @@ using System;
 using System.Globalization;
 using System.Security.Principal;
 using System.Threading;
+using System.Threading.Tasks;
 using System.Reflection;
 using System.Collections.Generic;
 using SD = System.Diagnostics;
@@ -908,6 +909,23 @@ namespace MonoTests.System.Threading
                }
 #endif // MONO_FEATURE_MULTIPLE_APPDOMAINS
 
+               [Test]
+               public void SetNameInThreadPoolThread ()
+               {
+                       Task t = Task.Run (delegate () {
+                               Thread.CurrentThread.Name = "ThreadName1";
+                               Assert.AreEqual (Thread.CurrentThread.Name, "ThreadName1", "#1");
+
+                               try {
+                                       Thread.CurrentThread.Name = "ThreadName2";
+                                       Assert.Fail ("#2");
+                               } catch (InvalidOperationException) {
+                               }
+                       });
+
+                       t.Wait ();
+               }
+
                void CheckIsRunning (string s, Thread t)
                {
                        int c = counter;