Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit b5a755e

Browse files
authored
Change monitor test (#15727)
Relevant to https://github.com/dotnet/coreclr/issues/15592: - Not sure what is actually happening, guessing there is an exception during TryEnter() and the exception from Exit() from the finally block is hiding the actual exception - Moved TryEnter() to before the try block - Fixed pass/fail condition for some similar monitor tests
1 parent f3796c7 commit b5a755e

File tree

10 files changed

+23
-20
lines changed

10 files changed

+23
-20
lines changed

tests/src/baseservices/threading/generics/Monitor/EnterExit02.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public static void EnterExitTest<U>()
4747
if(myHelper.Error == true || myHelper2.Error == true)
4848
break;
4949
}
50-
Test.Eval(!(myHelper.Error && myHelper2.Error));
50+
Test.Eval(!(myHelper.Error || myHelper2.Error));
5151
}
5252
}
5353

tests/src/baseservices/threading/generics/Monitor/EnterExit04.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public static void EnterExitTest<U>()
5252
if(myHelper.Error == true || myHelper2.Error == true)
5353
break;
5454
}
55-
Test.Eval(!(myHelper.Error && myHelper2.Error));
55+
Test.Eval(!(myHelper.Error || myHelper2.Error));
5656
}
5757
}
5858

tests/src/baseservices/threading/generics/Monitor/EnterExit06.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public static void EnterExitTest<U>()
5050
if(myHelper.Error == true || myHelper2.Error == true)
5151
break;
5252
}
53-
Test.Eval(!(myHelper.Error && myHelper2.Error));
53+
Test.Eval(!(myHelper.Error || myHelper2.Error));
5454
}
5555

5656
}

tests/src/baseservices/threading/generics/Monitor/EnterExit08.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public static void EnterExitTest<U>()
5050
if(myHelper.Error == true || myHelper2.Error == true)
5151
break;
5252
}
53-
Test.Eval(!(myHelper.Error && myHelper2.Error));
53+
Test.Eval(!(myHelper.Error || myHelper2.Error));
5454
}
5555

5656
}

tests/src/baseservices/threading/generics/Monitor/EnterExit10.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public static void EnterExitTest()
5050
if(myHelper.Error == true || myHelper2.Error == true)
5151
break;
5252
}
53-
Test.Eval(!(myHelper.Error && myHelper2.Error));
53+
Test.Eval(!(myHelper.Error || myHelper2.Error));
5454
}
5555

5656
}

tests/src/baseservices/threading/generics/Monitor/EnterExit12.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public static void EnterExitTest<U>()
5555
if(myHelper.Error == true || myHelper2.Error == true)
5656
break;
5757
}
58-
Test.Eval(!(myHelper.Error && myHelper2.Error));
58+
Test.Eval(!(myHelper.Error || myHelper2.Error));
5959
}
6060

6161

tests/src/baseservices/threading/generics/Monitor/EnterExit14.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public static void EnterExitTest<U>()
5454
if(myHelper.Error == true || myHelper2.Error == true)
5555
break;
5656
}
57-
Test.Eval(!(myHelper.Error && myHelper2.Error));
57+
Test.Eval(!(myHelper.Error || myHelper2.Error));
5858
}
5959

6060

tests/src/baseservices/threading/generics/Monitor/MonitorHelper.cs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -54,27 +54,30 @@ public void DoWork()
5454
}
5555
if(m_iSharedData == m_iRequestedEntries)
5656
m_Event.Set();
57-
}
57+
}
58+
5859
public void Consumer(object monitor)
5960
{
6061
lock(monitor)
6162
{
6263
DoWork();
6364
}
6465
}
65-
public void ConsumerTryEnter(object monitor,int timeout)
66+
67+
public void ConsumerTryEnter(object monitor, int timeout)
6668
{
67-
try
68-
{
69-
bool tookLock = false;
70-
71-
Monitor.TryEnter(monitor,timeout, ref tookLock);
69+
bool tookLock = false;
7270

73-
while(!tookLock) {
74-
Thread.Sleep(0);
75-
Monitor.TryEnter(monitor,timeout, ref tookLock);
76-
}
71+
Monitor.TryEnter(monitor, timeout, ref tookLock);
7772

73+
while (!tookLock)
74+
{
75+
Thread.Sleep(0);
76+
Monitor.TryEnter(monitor, timeout, ref tookLock);
77+
}
78+
79+
try
80+
{
7881
DoWork();
7982
}
8083
finally

tests/src/baseservices/threading/generics/Monitor/TryEnter03.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public static void TryEnterTest<U>(bool TisU)
4444
if(myHelper.Error == true || myHelper2.Error == true)
4545
break;
4646
}
47-
Test.Eval(!(myHelper.Error && myHelper2.Error));
47+
Test.Eval(!(myHelper.Error || myHelper2.Error));
4848

4949
}
5050

tests/src/baseservices/threading/generics/Monitor/TryEnter06.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public static void TryEnterTest<U>(bool TisU)
4444
if(myHelper.Error == true || myHelper2.Error == true)
4545
break;
4646
}
47-
Test.Eval(!(myHelper.Error && myHelper2.Error));
47+
Test.Eval(!(myHelper.Error || myHelper2.Error));
4848

4949
}
5050

0 commit comments

Comments
 (0)