# HG changeset patch # User Severin Gehwolf # Date 1365096262 -7200 # Node ID 216eb7ac12cdc63f2842d0f0fff56b4d0ac28eae # Parent 0b250145abf3e76a34afcc7da0e81e053eaf02fc Reduce likelihood of AgentApplicationTest deadlocking. Reviewed-by: omajid Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2013-April/006295.html diff -r 0b250145abf3 -r 216eb7ac12cd agent/cli/src/test/java/com/redhat/thermostat/agent/cli/impl/AgentApplicationTest.java --- a/agent/cli/src/test/java/com/redhat/thermostat/agent/cli/impl/AgentApplicationTest.java Thu Apr 04 17:28:12 2013 -0400 +++ b/agent/cli/src/test/java/com/redhat/thermostat/agent/cli/impl/AgentApplicationTest.java Thu Apr 04 19:24:22 2013 +0200 @@ -85,7 +85,6 @@ import com.redhat.thermostat.storage.dao.BackendInfoDAO; import com.redhat.thermostat.testutils.StubBundleContext; -@PrepareForTest({ AgentApplication.class }) @RunWith(PowerMockRunner.class) public class AgentApplicationTest { @@ -168,6 +167,19 @@ } + /* + * Having the PrepareForTest annotation on method level does not seem to + * deadlock the test, which seems to be more or less reliably reproducible + * if this annotation is at class level instead. Steps to reproduce the + * deadlock is: + * 1. Attach the PrepareForTest annotation to the class (over the test + * method) + * 2. Run the test multiple times. 5-20 times seemed sufficient for me to + * make the deadlock show up. This deadlock does not seem to happen + * otherwise (can run up to 30 times head-to-head without deadlock). + * + */ + @PrepareForTest({ AgentApplication.class }) @SuppressWarnings("unchecked") @Test public void verifyBackendRegistryProblemsSetsExitStatus() throws Exception { @@ -184,6 +196,7 @@ verify(exitStatus).setExitStatus(ExitStatus.EXIT_ERROR); } + @PrepareForTest({ AgentApplication.class }) @Test public void verifyAgentLaunchExceptionSetsExitStatus() throws Exception { whenNew(BackendRegistry.class).withParameterTypes(BundleContext.class)