Skip to content

Commit 0adfd82

Browse files
committed
Harden test to avoid random failures
1 parent 55b8867 commit 0adfd82

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

activemq-unit-tests/src/test/java/org/apache/activemq/EmbeddedBrokerTestSupport.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,10 @@ protected void tearDown() throws Exception {
6363
if (broker != null) {
6464
try {
6565
broker.stop();
66+
broker.waitUntilStopped();
6667
} catch (Exception e) {
68+
} finally {
69+
broker = null;
6770
}
6871
}
6972
}

activemq-unit-tests/src/test/java/org/apache/activemq/JmsMultipleClientsTestSupport.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import org.apache.activemq.command.ActiveMQQueue;
4444
import org.apache.activemq.command.ActiveMQTopic;
4545
import org.apache.activemq.util.MessageIdList;
46+
import org.apache.activemq.util.Wait;
4647
import org.junit.After;
4748
import org.junit.Before;
4849
import org.junit.Rule;
@@ -316,8 +317,13 @@ public String getName(boolean original) {
316317
}
317318

318319
public void assertDestinationMemoryUsageGoesToZero() throws Exception {
319-
assertEquals("destination memory is back to 0", 0,
320-
TestSupport.getDestination(broker, ActiveMQDestination.transform(destination)).getMemoryUsage().getPercentUsage());
320+
final ActiveMQDestination activeMQDestination = ActiveMQDestination.transform(destination);
321+
assertTrue("destination memory is back to 0", Wait.waitFor(new Wait.Condition() {
322+
@Override
323+
public boolean isSatisified() throws Exception {
324+
return TestSupport.getDestination(broker, activeMQDestination).getMemoryUsage().getPercentUsage() == 0;
325+
}
326+
}));
321327
}
322328

323329

0 commit comments

Comments
 (0)