Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix random failing ServiceSupplierTestCase.testOptionalReferences #488 #829

Merged
merged 1 commit into from
Nov 6, 2023

Conversation

HeikoKlare
Copy link
Contributor

The ServiceSupplierTestCase.testOptionalReferences test case randomly fails. The test aims to wait for services to be enabled or disabled, but it only waits until a single value is changed although it asserts that multiple values are changed afterwards. This is a race condition, as the order in which the values are changed or in which the changes are visible is non-deterministic, also due to missing memory barriers.

This change addresses this issue via two means:

  1. it makes the fields of the asserted values volatile to ensure that changed values eventually become visible to the UI thread
  2. it waits for all values to be changed before asserting their values to allow different orders of value changes

…ipse-platform#488

The ServiceSupplierTestCase.testOptionalReferences test case randomly
fails. The test aims to wait for services to be enabled or disabled, but
it only waits until a single value is changed although it asserts that
multiple values are changed afterwards. This is a race condition, as the
order in which the values are changed or in which the changes are
visible is non-deterministic, also due to missing memory barriers.

This change addresses this issue via two means:
1. it makes the fields of the asserted values volatile to ensure that
changed values eventually become visible to the UI thread
2. it waits for all values to be changed before asserting their values
to allow different orders of value changes
Copy link
Contributor

github-actions bot commented Nov 6, 2023

Test Results

     591 files  +  18       591 suites  +18   1h 21m 37s ⏱️ + 12m 13s
  3 837 tests ±    0    3 832 ✔️ +    3    5 💤 ±0  0  - 3 
12 117 runs  +147  12 081 ✔️ +150  36 💤 ±0  0  - 3 

Results for commit aaefc90. ± Comparison against base commit 5c0e07b.

@HeikoKlare HeikoKlare marked this pull request as ready for review November 6, 2023 12:38
@HeikoKlare HeikoKlare merged commit 9a8ef47 into eclipse-platform:master Nov 6, 2023
14 checks passed
@HeikoKlare HeikoKlare deleted the issue-488 branch November 6, 2023 14:57
@@ -73,11 +73,11 @@ public static class TestDisabledBean {
@Inject
@Optional
@Service(filterExpression = "(component=disabled)")
TestService disabledService;
volatile TestService disabledService;
Copy link
Contributor

Choose a reason for hiding this comment

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

if this Lists are used concurrently its not enough to use volatile, they need to be Concurrent Lists, or synchronized

Copy link
Contributor Author

Choose a reason for hiding this comment

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

True. The volatile was an attempt to introduce a memory barrier to ensure that changed values become eventually visible, but, of course, that does not apply to content changes of the list.

Copy link
Contributor Author

@HeikoKlare HeikoKlare Nov 29, 2023

Choose a reason for hiding this comment

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

Since the field is injected, one cannot easily influence the type of list, i.e., ensure that it is thread-safe. But gladly OSGi handles that case:

By far the easiest method is to use field injection of a list of services. If you make this field volatile then DS will inject a new list whenever the set of tracked services changes.

See https://enroute.osgi.org/FAQ/300-declarative-services.html#tracking-multiple-services

So from my understanding, volatile should be correct here.

HeikoKlare added a commit to HeikoKlare/eclipse.platform that referenced this pull request Nov 29, 2023
…ipse-platform#488

Fixes two issues:
1. The ServiceSupplierTestCase asserts several values that are assigned
by an asynchronous task. To this end, it waits for the conditions to be
fulfilled by the asynchronous task. However, the conditions are
incomplete, leading to a race condition.
2. The ServiceSupplierTestCase has been duplicated for javax and jakarta
and a fix for a random failure has only been applied to a single
implementation in
eclipse-platform#829

This change corrects the conditions the test waits for and aligns both
copies of the test class with each other.

Fixes eclipse-platform#488
HeikoKlare added a commit that referenced this pull request Nov 29, 2023
Fixes two issues:
1. The ServiceSupplierTestCase asserts several values that are assigned
by an asynchronous task. To this end, it waits for the conditions to be
fulfilled by the asynchronous task. However, the conditions are
incomplete, leading to a race condition.
2. The ServiceSupplierTestCase has been duplicated for javax and jakarta
and a fix for a random failure has only been applied to a single
implementation in
#829

This change corrects the conditions the test waits for and aligns both
copies of the test class with each other.

Fixes #488
Michael5601 pushed a commit to CodeLtDave/eclipse.platform that referenced this pull request Feb 12, 2024
…ipse-platform#488

Fixes two issues:
1. The ServiceSupplierTestCase asserts several values that are assigned
by an asynchronous task. To this end, it waits for the conditions to be
fulfilled by the asynchronous task. However, the conditions are
incomplete, leading to a race condition.
2. The ServiceSupplierTestCase has been duplicated for javax and jakarta
and a fix for a random failure has only been applied to a single
implementation in
eclipse-platform#829

This change corrects the conditions the test waits for and aligns both
copies of the test class with each other.

Fixes eclipse-platform#488
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