changeset 1062:216eb7ac12cd

Reduce likelihood of AgentApplicationTest deadlocking. Reviewed-by: omajid Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2013-April/006295.html
author Severin Gehwolf <sgehwolf@redhat.com>
date Thu, 04 Apr 2013 19:24:22 +0200
parents 0b250145abf3
children c1edec7797bd
files agent/cli/src/test/java/com/redhat/thermostat/agent/cli/impl/AgentApplicationTest.java
diffstat 1 files changed, 14 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- 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)