Browse files

Fix race condition tests.

- on affected tests: add an extra pair of rules to workaround a deadlock scenario caused by the race condition tests themselves
  • Loading branch information...
1 parent f41071b commit 8f0a8a00e7ae23a567ce11eda0e31bd334783efe @fl4via fl4via committed Dec 29, 2012
View
3 .../org/jboss/msc/racecondition/TransitiveDependencyUnavailableDuringServiceRemovalTest.java
@@ -65,6 +65,9 @@ public void test() throws Exception {
final Future<ServiceController<?>> serviceAStop = testListener.expectServiceStop(serviceNameA);
final Future<ServiceController<?>> serviceCStop = testListener.expectServiceStop(serviceNameC);
serviceDController.setMode(Mode.REMOVE);
+ Thread.sleep(50); //avoid a scenario where we fail to reproduce the test case: service B is removed before D
+ // if this happens, the result is the rule for "service B on removing state" being triggered on teardown, which
+ // results in thread waiting forever
serviceBController.setMode(Mode.REMOVE);
assertController(serviceBController, serviceBRemoval);
assertController(serviceDController, serviceDRemoval);
View
27 ...rces/org/jboss/msc/racecondition/ImmediateDependencyAvailableOnRemovedServiceTestCase.btm
@@ -57,6 +57,26 @@ DO
debug("signaled immediateDependencyAvailable")
ENDRULE
+RULE prevent deadlock with UndemandDependenciesTask - I
+CLASS org.jboss.msc.service.ServiceRegistrationImpl
+METHOD removeDemand
+AT EXIT
+IF $0.name.getSimpleName().equals("C") AND incrementCounter("run once prevent deadlock I") == 1
+DO
+ debug("unlocking C install thread"),
+ signalWake("service C undemanded", true)
+ENDRULE
+
+RULE prevent deadlock with UndemandDependenciesTask - II
+CLASS org.jboss.msc.racecondition.ImmediateDependencyAvailableDuringServiceRemovalTest$InstallService
+METHOD run
+AT ENTRY
+IF incrementCounter("run once prevent deadlock II") == 1
+DO
+ debug("waiting for service c to be undemanded before proceeding with service C installation - to avoid a deadlock"),
+ waitFor("service C undemanded")
+ENDRULE
+
RULE clear counters and flags
CLASS org.jboss.msc.service.AbstractServiceTest
METHOD tearDown
@@ -66,6 +86,7 @@ DO
debug("clearing counters and flags"),
deleteCounter("run once before ServiceControllerImpl.immediateDependencyAvailable"),
deleteCounter("run once service B REMOVING"),
- deleteCounter("run once service B REMOVED")
-ENDRULE
-
+ deleteCounter("run once service B REMOVED"),
+ deleteCounter("run once prevent deadlock I"),
+ deleteCounter("run once prevent deadlock II")
+ENDRULE
View
26 ...ces/org/jboss/msc/racecondition/ImmediateDependencyAvailableOnRemovingServiceTestCase.btm
@@ -27,7 +27,7 @@ BIND serviceName = $0.primaryRegistration.name.getSimpleName();
IF serviceName.equals("B") AND incrementCounter("run once before ServiceControllerImpl.immediateDependencyAvailable") == 1
DO
debug("wait for service enter REMOVING state: " + $0),
- waitFor("service REMOVING", 10000),
+ waitFor("service REMOVING"),
debug("proceed with immediateDependencyAvailable")
ENDRULE
@@ -55,6 +55,26 @@ DO
debug("signaled immediateDependencyAvailable")
ENDRULE
+RULE prevent deadlock with UndemandDependenciesTask - I
+CLASS org.jboss.msc.service.ServiceRegistrationImpl
+METHOD removeDemand
+AT EXIT
+IF $0.name.getSimpleName().equals("C") AND incrementCounter("run once prevent deadlock I") == 1
+DO
+ debug("unlocking C install thread"),
+ signalWake("service C undemanded", true)
+ENDRULE
+
+RULE prevent deadlock with UndemandDependenciesTask - II
+CLASS org.jboss.msc.racecondition.ImmediateDependencyAvailableDuringServiceRemovalTest$InstallService
+METHOD run
+AT ENTRY
+IF incrementCounter("run once prevent deadlock II") == 1
+DO
+ debug("waiting for service c to be undemanded before proceeding with service C installation - to avoid a deadlock"),
+ waitFor("service C undemanded")
+ENDRULE
+
RULE clear counters and flags
CLASS org.jboss.msc.service.AbstractServiceTest
METHOD tearDown
@@ -64,5 +84,7 @@ DO
debug("clearing counters and flags"),
deleteCounter("run once before ServiceControllerImpl.immediateDependencyAvailable"),
deleteCounter("run once after ServiceControllerImpl.immediateDependencyAvailable"),
- deleteCounter("run once service B REMOVING")
+ deleteCounter("run once service B REMOVING"),
+ deleteCounter("run once prevent deadlock I"),
+ deleteCounter("run once prevent deadlock II")
ENDRULE
View
26 ...s/org/jboss/msc/racecondition/TransitiveDependencyUnavailableOnRemovedServiceTestCase.btm
@@ -68,6 +68,27 @@ DO
debug("signaled transitiveDependencyUnavailable")
ENDRULE
+RULE prevent deadlock with UndemandDependenciesTask - I
+CLASS org.jboss.msc.service.ServiceRegistrationImpl
+METHOD removeDemand
+AT EXIT
+IF flagged("service D on REMOVE mode") AND $0.name.getSimpleName().equals("C") AND incrementCounter("run once prevent deadlock I") == 1
+DO
+ debug("unlocking C.immediateDepedencyUnavailable thread"),
+ flag("service C undemanded"),
+ signalWake("service C undemanded")
+ENDRULE
+
+RULE prevent deadlock with UndemandDependenciesTask - II
+CLASS org.jboss.msc.service.ServiceControllerImpl
+METHOD immediateDependencyUnavailable
+AT ENTRY
+IF !flagged ("service C undemanded") AND flagged("service D on REMOVE mode") AND $0.primaryRegistration.name.getSimpleName().equals("C") AND incrementCounter("run once prevent deadlock II") == 1
+DO
+ debug("waiting for service c to be undemanded before proceeding with service C immediateDependencyUnavailable - to avoid a deadlock"),
+ waitFor("service C undemanded", 1000)
+ENDRULE
+
RULE clear counters and flags
CLASS org.jboss.msc.service.AbstractServiceTest
METHOD tearDown
@@ -76,7 +97,10 @@ IF TRUE
DO
debug("clearing counters and flags"),
clear("service D on REMOVE mode"),
+ clear("service C undemanded"),
deleteCounter("run once before ServiceControllerImpl.transitiveDependencyUnavailable"),
deleteCounter("run once service B REMOVING"),
- deleteCounter("run once service B REMOVED")
+ deleteCounter("run once service B REMOVED"),
+ deleteCounter("run once prevent deadlock I"),
+ deleteCounter("run once prevent deadlock II")
ENDRULE
View
26 .../org/jboss/msc/racecondition/TransitiveDependencyUnavailableOnRemovingServiceTestCase.btm
@@ -66,6 +66,27 @@ DO
debug("signaled transitiveDependencyUnavailable")
ENDRULE
+RULE prevent deadlock with UndemandDependenciesTask - I
+CLASS org.jboss.msc.service.ServiceRegistrationImpl
+METHOD removeDemand
+AT EXIT
+IF flagged("service D on REMOVE mode") AND $0.name.getSimpleName().equals("C") AND incrementCounter("run once prevent deadlock I") == 1
+DO
+ debug("unlocking C.immediateDepedencyUnavailable thread"),
+ flag("service C undemanded"),
+ signalWake("service C undemanded")
+ENDRULE
+
+RULE prevent deadlock with UndemandDependenciesTask - II
+CLASS org.jboss.msc.service.ServiceControllerImpl
+METHOD immediateDependencyUnavailable
+AT ENTRY
+IF !flagged ("service C undemanded") AND flagged("service D on REMOVE mode") AND $0.primaryRegistration.name.getSimpleName().equals("C") AND incrementCounter("run once prevent deadlock II") == 1
+DO
+ debug("waiting for service c to be undemanded before proceeding with service C immediateDependencyUnavailable - to avoid a deadlock"),
+ waitFor("service C undemanded", 1000)
+ENDRULE
+
RULE clear counters and flags
CLASS org.jboss.msc.service.AbstractServiceTest
METHOD tearDown
@@ -74,7 +95,10 @@ IF TRUE
DO
debug("clearing counters and flags"),
clear("service D on REMOVE mode"),
+ clear("service C undemanded"),
deleteCounter("run once before ServiceControllerImpl.transitiveDependencyUnavailable"),
deleteCounter("run once after ServiceControllerImpl.transitiveDependencyUnavailable"),
- deleteCounter("run once service B REMOVING")
+ deleteCounter("run once service B REMOVING"),
+ deleteCounter("run once prevent deadlock I"),
+ deleteCounter("run once prevent deadlock II")
ENDRULE

0 comments on commit 8f0a8a0

Please sign in to comment.