Skip to content

Commit cfe9056

Browse files
authored
Adjust Test_wait_interrupted_user_apc test timeout to handle deviation due to lowres timers. (#116066)
* Adjust test timeout to handle deviation due to lowres timers. * Acceept 500 ms deviation on wait time. * Reenable test. * Adjust wait time calculation. * Reduce wait delta to 20ms to account for low vs high res timers.
1 parent e9dd250 commit cfe9056

File tree

3 files changed

+15
-20
lines changed

3 files changed

+15
-20
lines changed

src/coreclr/vm/threads.cpp

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3309,12 +3309,12 @@ DWORD Thread::DoAppropriateWaitWorker(int countHandles, HANDLE *handles, BOOL wa
33093309
}
33103310

33113311
ULONGLONG dwStart = 0, dwEnd;
3312-
retry:
33133312
if (millis != INFINITE)
33143313
{
33153314
dwStart = minipal_lowres_ticks();
33163315
}
33173316

3317+
retry:
33183318
if (tryNonblockingWaitFirst)
33193319
{
33203320
// We have a final wait result from the nonblocking wait above
@@ -3344,10 +3344,9 @@ DWORD Thread::DoAppropriateWaitWorker(int countHandles, HANDLE *handles, BOOL wa
33443344
ret = WAIT_TIMEOUT;
33453345
goto WaitCompleted;
33463346
}
3347-
else
3348-
{
3349-
millis -= (DWORD)(dwEnd - dwStart);
3350-
}
3347+
3348+
millis -= (DWORD)(dwEnd - dwStart);
3349+
dwStart = dwEnd;
33513350
}
33523351
goto retry;
33533352
}
@@ -3421,18 +3420,17 @@ DWORD Thread::DoAppropriateWaitWorker(int countHandles, HANDLE *handles, BOOL wa
34213420

34223421
// Compute the new timeout value by assume that the timeout
34233422
// is not large enough for more than one wrap
3424-
dwEnd = minipal_lowres_ticks();
34253423
if (millis != INFINITE)
34263424
{
3425+
dwEnd = minipal_lowres_ticks();
34273426
if (dwEnd - dwStart >= millis)
34283427
{
34293428
ret = WAIT_TIMEOUT;
34303429
goto WaitCompleted;
34313430
}
3432-
else
3433-
{
3434-
millis -= (DWORD)(dwEnd - dwStart);
3435-
}
3431+
3432+
millis -= (DWORD)(dwEnd - dwStart);
3433+
dwStart = dwEnd;
34363434
}
34373435
goto retry;
34383436
}
@@ -3574,11 +3572,9 @@ DWORD Thread::DoSignalAndWaitWorker(HANDLE* pHandles, DWORD millis,BOOL alertabl
35743572
ret = WAIT_TIMEOUT;
35753573
goto WaitCompleted;
35763574
}
3577-
else
3578-
{
3579-
millis -= (DWORD)(dwEnd - dwStart);
3580-
}
3581-
dwStart = minipal_lowres_ticks();
3575+
3576+
millis -= (DWORD)(dwEnd - dwStart);
3577+
dwStart = dwEnd;
35823578
}
35833579
//Retry case we don't want to signal again so only do the wait...
35843580
ret = WaitForSingleObjectEx(pHandles[1],millis,TRUE);

src/tests/baseservices/threading/regressions/115178/115178.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,11 @@ private static void RunTestUsingTimedWait()
165165

166166
stopwatch.Stop();
167167

168-
if (stopwatch.ElapsedMilliseconds < 2000)
168+
long elapsedMilliseconds = stopwatch.ElapsedMilliseconds;
169+
if (elapsedMilliseconds < 1980)
169170
{
170-
Console.WriteLine($"Error waiting on event, wait returned too early.");
171+
// Wait uses low resolution timer, test includes a margin of 20ms to account for timer resolution differences.
172+
Console.WriteLine($"Error waiting on event, wait returned too early. Waited {elapsedMilliseconds} ms, expected at least 1980 ms.");
171173
result = 5;
172174
}
173175

src/tests/issues.targets

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@
3030
<ExcludeList Include="$(XunitTestBinBase)/baseservices/threading/regressions/2164/foreground-shutdown/*">
3131
<Issue>https://github.com/dotnet/runtime/issues/83658</Issue>
3232
</ExcludeList>
33-
<ExcludeList Include="$(XunitTestBinBase)/baseservices/threading/regressions/115178/115178/*">
34-
<Issue>https://github.com/dotnet/runtime/issues/116060</Issue>
35-
</ExcludeList>
3633
<ExcludeList Include="$(XunitTestBinBase)/GC/Coverage/271010/**">
3734
<Issue>https://github.com/dotnet/runtime/issues/5933</Issue>
3835
</ExcludeList>

0 commit comments

Comments
 (0)