diff --git a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/di/extensions/ServiceSupplierTestCase.java b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/di/extensions/ServiceSupplierTestCase.java index ca6db748117..8fffa968ea3 100644 --- a/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/di/extensions/ServiceSupplierTestCase.java +++ b/runtime/tests/org.eclipse.e4.core.javax.tests/src/org/eclipse/e4/core/internal/tests/di/extensions/ServiceSupplierTestCase.java @@ -73,11 +73,11 @@ public static class TestDisabledBean { @Inject @Optional @Service(filterExpression = "(component=disabled)") - TestService disabledService; + volatile TestService disabledService; @Inject @Service(filterExpression = "(component=disabled)") - List services; + volatile List services; } private final List> registrations = new ArrayList<>(); @@ -250,28 +250,30 @@ public void testOptionalReferences() throws Exception { try { enabler.enableDisabledServiceA(); // wait for asynchronous service registry and injection to finish - waitForCondition(() -> bean.services.size() == 1, timeoutInMillis); + waitForCondition(() -> bean.services.size() == 1 && bean.disabledService != null, timeoutInMillis); assertNotNull(bean.disabledService); assertEquals(1, bean.services.size()); assertSame(DisabledServiceA.class, bean.disabledService.getClass()); enabler.enableDisabledServiceB(); // wait for asynchronous service registry and injection to finish - waitForCondition(() -> bean.services.size() == 2, timeoutInMillis); + waitForCondition(() -> bean.services.size() == 2 && bean.disabledService instanceof DisabledServiceB, + timeoutInMillis); assertNotNull(bean.disabledService); assertEquals(2, bean.services.size()); assertSame(DisabledServiceB.class, bean.disabledService.getClass()); enabler.disableDisabledServiceB(); // wait for asynchronous service registry and injection to finish - waitForCondition(() -> bean.services.size() == 1, timeoutInMillis); + waitForCondition(() -> bean.services.size() == 1 && bean.disabledService instanceof DisabledServiceA, + timeoutInMillis); assertNotNull(bean.disabledService); assertEquals(1, bean.services.size()); assertSame(DisabledServiceA.class, bean.disabledService.getClass()); enabler.disableDisabledServiceA(); // wait for asynchronous service registry and injection to finish - waitForCondition(() -> bean.services.size() == 0, timeoutInMillis); + waitForCondition(() -> bean.services.size() == 0 && bean.disabledService == null, timeoutInMillis); assertNull(bean.disabledService); assertEquals(0, bean.services.size()); } finally { @@ -279,7 +281,7 @@ public void testOptionalReferences() throws Exception { enabler.disableDisabledServiceB(); // wait for asynchronous service registry and injection to ensure // clear state after this test - waitForCondition(() -> bean.services.size() == 0, timeoutInMillis); + waitForCondition(() -> bean.services.size() == 0 && bean.disabledService == null, timeoutInMillis); } } diff --git a/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/di/extensions/ServiceSupplierTestCase.java b/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/di/extensions/ServiceSupplierTestCase.java index a5d8610a6a6..864c5ea56de 100644 --- a/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/di/extensions/ServiceSupplierTestCase.java +++ b/runtime/tests/org.eclipse.e4.core.tests/src/org/eclipse/e4/core/internal/tests/di/extensions/ServiceSupplierTestCase.java @@ -257,14 +257,16 @@ public void testOptionalReferences() throws Exception { enabler.enableDisabledServiceB(); // wait for asynchronous service registry and injection to finish - waitForCondition(() -> bean.services.size() == 2, timeoutInMillis); + waitForCondition(() -> bean.services.size() == 2 && bean.disabledService instanceof DisabledServiceB, + timeoutInMillis); assertNotNull(bean.disabledService); assertEquals(2, bean.services.size()); assertSame(DisabledServiceB.class, bean.disabledService.getClass()); enabler.disableDisabledServiceB(); // wait for asynchronous service registry and injection to finish - waitForCondition(() -> bean.services.size() == 1, timeoutInMillis); + waitForCondition(() -> bean.services.size() == 1 && bean.disabledService instanceof DisabledServiceA, + timeoutInMillis); assertNotNull(bean.disabledService); assertEquals(1, bean.services.size()); assertSame(DisabledServiceA.class, bean.disabledService.getClass()); @@ -279,7 +281,7 @@ public void testOptionalReferences() throws Exception { enabler.disableDisabledServiceB(); // wait for asynchronous service registry and injection to ensure // clear state after this test - waitForCondition(() -> bean.services.size() == 0, timeoutInMillis); + waitForCondition(() -> bean.services.size() == 0 && bean.disabledService == null, timeoutInMillis); } }