Skip to content

Start tests in sorted order also with multiple threads#141

Open
giordano wants to merge 3 commits into
mainfrom
mg/start-mt
Open

Start tests in sorted order also with multiple threads#141
giordano wants to merge 3 commits into
mainfrom
mg/start-mt

Conversation

@giordano

@giordano giordano commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator

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).

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>
Comment thread test/runtests.jl
@giordano

giordano commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator Author

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.

@christiangnrd

Copy link
Copy Markdown
Contributor

This seems to also work for me!

@giordano giordano marked this pull request as ready for review July 3, 2026 15:54
@giordano

giordano commented Jul 3, 2026

Copy link
Copy Markdown
Collaborator Author

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.

@giordano

This comment was marked as resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tests not launching in descending runtime order when JULIA_NUM_THREADS > 1

2 participants