Skip to content

Use AtomicInteger in JobGroupTest.testShouldCancel_4#2668

Open
trancexpress wants to merge 1 commit into
eclipse-platform:masterfrom
trancexpress:gh2667
Open

Use AtomicInteger in JobGroupTest.testShouldCancel_4#2668
trancexpress wants to merge 1 commit into
eclipse-platform:masterfrom
trancexpress:gh2667

Conversation

@trancexpress
Copy link
Copy Markdown
Contributor

Adjusts JobGroupTest.testShouldCancel_4() to use an atomic data structure, to avoid concurrency issues with incrementing an integer from multiple jobs.

See: #2667

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 19, 2026

Test Results

    54 files  ±0      54 suites  ±0   34m 35s ⏱️ -59s
 4 667 tests ±0   4 645 ✅ ±0   22 💤 ±0  0 ❌ ±0 
11 895 runs  ±0  11 742 ✅ ±0  153 💤 ±0  0 ❌ ±0 

Results for commit 4842788. ± Comparison against base commit 3b9b910.

♻️ This comment has been updated with latest results.

Copy link
Copy Markdown
Member

@fedejeanne fedejeanne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch, thank you for the contribution!

Just a nit: would it be possible to use AssertJ for more expressive assertions?

Other than that, the PR is fine.

return true;
}
return false;
return numShouldCancelCalled.incrementAndGet() >= NUM_JOBS_LIMIT;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch, checking for == was wrong because of the race condition (2 threads executing numShouldCancelCalled[0]++; before one of them reached the if below would skip numbers).

FTR it is now safe to simply do:

return numShouldCancelCalled.incrementAndGet() == NUM_JOBS_LIMIT;

... because the comparison (==) uses the now stable value that comes from incrementAndGet() (no race condition there).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather be safe here with >=.

Adjusts JobGroupTest.testShouldCancel_4() to use an atomic data structure,
to avoid concurrency issues with incrementing an integer from multiple jobs.

See: eclipse-platform#2667
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.

2 participants