Start tests in sorted order also with multiple threads#141
Conversation
Since #119, each test is bound to its own task at spawn time, and all tasks race to acquire the semaphore. With a single thread tasks happen to reach the semaphore in spawn order, but with multiple threads the acquisition order is arbitrary, defeating the descending-historical- duration sort (#139). Instead, hand out tests in sorted order at acquisition time, via an atomic fetch-add index claimed only once a task holds a semaphore slot and a worker. Fixes #139. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
To demonstrate that this PR does solve #139, in this CI run I reverted the fix introduced in this PR, but only kept running the CI jobs with multiple Julia threads: in 11 out of 20 jobs, the tests introduced in #140 failed, as expected. Tests are instead all green when running Julia with multiple threads and applying the proposed fix. |
|
This seems to also work for me! |
|
Ok, I verified the new tests would occasionally fail before this PR, when running Julia with multiple threads, so this is ready to go from my side. |
This comment was marked as resolved.
This comment was marked as resolved.
|
I'm inclined to merge this PR if there are no objections in the next few days. The fix is very simple, and there are new tests to finally make sure jobs are started in the expected order (and the ones in #140 also catch this bug when running julia with multiple threads) |
Since #119, each test is bound to its own task at spawn time, and all tasks race to acquire the semaphore. With a single thread tasks happen to reach the semaphore in spawn order, but with multiple threads the acquisition order is arbitrary, defeating the descending-historical- duration sort (#139).
Instead, hand out tests in sorted order at acquisition time, via an atomic fetch-add index claimed only once a task holds a semaphore slot and a worker.
Fixes #139. @christiangnrd can you please test this PR? It does seem to work for me, tests introduced in #140 now pass when using multiple Julia threads, which instead very frequently currently fail, as explained in #140 (comment).