Skip to content

Commit 3a88c10

Browse files
authored
Relax timeouts and macOS exclusions + small fixes (#1673)
1 parent c4255bd commit 3a88c10

9 files changed

Lines changed: 283 additions & 230 deletions

activemq-unit-tests/pom.xml

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -953,7 +953,6 @@
953953
<exclude>org/apache/activemq/transport/SoWriteTimeoutTest.*</exclude>
954954
<exclude>org/apache/activemq/transport/TopicClusterTest.*</exclude>
955955
<exclude>org/apache/activemq/transport/discovery/DiscoveryNetworkReconnectTest.*</exclude>
956-
<exclude>org/apache/activemq/transport/discovery/DiscoveryTransportBrokerTest.*</exclude>
957956
<exclude>org/apache/activemq/transport/discovery/DiscoveryTransportNoBrokerTest.*</exclude>
958957
<exclude>org/apache/activemq/transport/discovery/DiscoveryUriTest.*</exclude>
959958
<exclude>org/apache/activemq/transport/discovery/MasterSlaveDiscoveryTest.*</exclude>
@@ -1144,6 +1143,29 @@
11441143
</plugins>
11451144
</build>
11461145
</profile>
1146+
<profile>
1147+
<id>activemq.tests.mac.excludes</id>
1148+
<activation>
1149+
<os>
1150+
<family>mac</family>
1151+
</os>
1152+
</activation>
1153+
<build>
1154+
<plugins>
1155+
<plugin>
1156+
<artifactId>maven-surefire-plugin</artifactId>
1157+
<configuration>
1158+
<excludes combine.children="append">
1159+
<!-- Multicast and UDP based tests are unreliable on macOS CI (no proper multicast interfaces) -->
1160+
<exclude>org/apache/activemq/transport/peer/PeerTransportTest.*</exclude>
1161+
<exclude>org/apache/activemq/transport/multicast/MulticastTransportTest.*</exclude>
1162+
<exclude>org/apache/activemq/network/MulticastNetworkTest.*</exclude>
1163+
</excludes>
1164+
</configuration>
1165+
</plugin>
1166+
</plugins>
1167+
</build>
1168+
</profile>
11471169
<profile>
11481170
<id>activemq.tests.aix.excludes</id>
11491171
<activation>

activemq-unit-tests/src/test/java/org/apache/activemq/bugs/DuplicateFromStoreTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ public void stopBroker() throws Exception {
123123
}
124124
}
125125

126-
@Test
126+
@Test(timeout = 120_000)
127127
public void testDuplicateMessage() throws Exception {
128128
LOG.info("Testing for duplicate messages.");
129129

@@ -134,10 +134,10 @@ public void testDuplicateMessage() throws Exception {
134134
createOpenwireClients(producers, consumers);
135135

136136
LOG.info("All producers and consumers got started. Awaiting their termination");
137-
producersFinished.await(100, TimeUnit.MINUTES);
137+
producersFinished.await(2, TimeUnit.MINUTES);
138138
LOG.info("All producers have terminated. remaining to send: " + totalMessagesToSend.get() + ", sent:" + totalMessagesSent.get());
139139

140-
consumersFinished.await(100, TimeUnit.MINUTES);
140+
consumersFinished.await(2, TimeUnit.MINUTES);
141141
LOG.info("All consumers have terminated.");
142142

143143
producers.shutdownNow();

activemq-unit-tests/src/test/java/org/apache/activemq/network/DurableSyncNetworkBridgeTest.java

Lines changed: 50 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@
4949
import org.apache.activemq.store.kahadb.KahaDBPersistenceAdapter;
5050
import org.apache.activemq.store.kahadb.disk.journal.Journal.JournalDiskSyncStrategy;
5151
import org.apache.activemq.util.Wait;
52-
import org.apache.activemq.util.Wait.Condition;
5352
import org.junit.After;
5453
import org.junit.Assume;
5554
import org.junit.Before;
@@ -83,7 +82,7 @@ public class DurableSyncNetworkBridgeTest extends DynamicNetworkTestSupport {
8382
private final FLOW flow;
8483

8584
@Rule
86-
public Timeout globalTimeout = new Timeout(30, TimeUnit.SECONDS);
85+
public Timeout globalTimeout = new Timeout(60, TimeUnit.SECONDS);
8786

8887
@Parameters
8988
public static Collection<Object[]> data() {
@@ -531,7 +530,6 @@ public void testAddOnlineSubscriptionsWithBridgeOffline() throws Exception {
531530
session1.createDurableSubscriber(topic, "sub3");
532531
session1.createDurableSubscriber(excludeTopic, "sub-exclude");
533532

534-
Thread.sleep(1000);
535533
assertNCDurableSubsCount(broker2, topic, 1);
536534
assertNCDurableSubsCount(broker2, excludeTopic, 0);
537535

@@ -570,13 +568,10 @@ public void testAddOnlineSubscriptionsTwoBridges() throws Exception {
570568
secondConnector.start();
571569

572570
//Make sure both bridges are connected
573-
assertTrue(Wait.waitFor(new Condition() {
574-
@Override
575-
public boolean isSatisified() throws Exception {
576-
return localBroker.getNetworkConnectors().get(0).activeBridges().size() == 1 &&
577-
localBroker.getNetworkConnectors().get(1).activeBridges().size() == 1;
578-
}
579-
}, 10000, 500));
571+
assertTrue(Wait.waitFor(() ->
572+
localBroker.getNetworkConnectors().get(0).activeBridges().size() == 1 &&
573+
localBroker.getNetworkConnectors().get(1).activeBridges().size() == 1,
574+
TimeUnit.SECONDS.toMillis(10), 500));
580575

581576
//Make sure NC durables exist for both bridges
582577
assertNCDurableSubsCount(broker2, topic2, 1);
@@ -637,13 +632,7 @@ public void testVirtualDestSubForceDurableSync() throws Exception {
637632
final DestinationStatistics remoteDestStatistics2 = remoteBroker.getDestination(
638633
new ActiveMQQueue("include.test.bar.bridge")).getDestinationStatistics();
639634

640-
assertTrue(Wait.waitFor(new Condition() {
641-
642-
@Override
643-
public boolean isSatisified() throws Exception {
644-
return remoteDestStatistics2.getMessages().getCount() == 501;
645-
}
646-
}));
635+
assertTrue(Wait.waitFor(() -> remoteDestStatistics2.getMessages().getCount() == 501));
647636

648637
}
649638

@@ -723,8 +712,36 @@ protected void doSetUp(boolean deleteAllMessages, boolean startNetworkConnector,
723712
included = new ActiveMQTopic(testTopicName);
724713
doSetUpRemoteBroker(deleteAllMessages, remoteDataDir, 0);
725714
doSetUpLocalBroker(deleteAllMessages, startNetworkConnector, localDataDir);
726-
//Give time for advisories to propagate
727-
Thread.sleep(1000);
715+
//Wait for the bridge to be fully started (advisory consumers registered).
716+
//Note: activeBridges().size() == 1 is NOT sufficient because bridges are added
717+
//to the map before start() completes asynchronously. We must wait for the
718+
//startedLatch which counts down after advisory consumers are registered.
719+
if (startNetworkConnector) {
720+
waitForBridgeFullyStarted();
721+
}
722+
}
723+
724+
private void waitForBridgeFullyStarted() throws Exception {
725+
// Wait for the local bridge to be fully started (advisory consumers registered)
726+
assertTrue("Local bridge should be fully started", Wait.waitFor(() -> {
727+
if (localBroker.getNetworkConnectors().get(0).activeBridges().isEmpty()) {
728+
return false;
729+
}
730+
final NetworkBridge bridge = localBroker.getNetworkConnectors().get(0).activeBridges().iterator().next();
731+
if (bridge instanceof DemandForwardingBridgeSupport) {
732+
return ((DemandForwardingBridgeSupport) bridge).startedLatch.getCount() == 0;
733+
}
734+
return true;
735+
}, TimeUnit.SECONDS.toMillis(10), 100));
736+
737+
// Also wait for the duplex bridge on the remote broker to be fully started.
738+
// The duplex connector creates a separate DemandForwardingBridge on the remote side
739+
// that also needs its advisory consumers registered before it can process events.
740+
assertTrue("Duplex bridge should be fully started", Wait.waitFor(() -> {
741+
final DemandForwardingBridge duplexBridge = findDuplexBridge(
742+
remoteBroker.getTransportConnectors().get(0));
743+
return duplexBridge != null && duplexBridge.startedLatch.getCount() == 0;
744+
}, TimeUnit.SECONDS.toMillis(10), 100));
728745
}
729746

730747
protected void restartLocalBroker(boolean startNetworkConnector) throws Exception {
@@ -757,12 +774,12 @@ protected void doSetUpLocalBroker(boolean deleteAllMessages, boolean startNetwor
757774
localConnection.start();
758775

759776
if (startNetworkConnector) {
760-
Wait.waitFor(new Condition() {
761-
@Override
762-
public boolean isSatisified() throws Exception {
763-
return localBroker.getNetworkConnectors().get(0).activeBridges().size() == 1;
764-
}
765-
}, 5000, 500);
777+
// Best-effort wait for the bridge to appear. Do NOT use assertTrue here
778+
// because some tests restart localBroker before remoteBroker is running,
779+
// relying on the bridge connecting later when remoteBroker restarts.
780+
// Tests that need the bridge to be fully started call assertBridgeStarted() explicitly.
781+
Wait.waitFor(() -> localBroker.getNetworkConnectors().get(0).activeBridges().size() == 1,
782+
TimeUnit.SECONDS.toMillis(10), 500);
766783
}
767784
localSession = localConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
768785

@@ -881,19 +898,16 @@ protected BrokerService createRemoteBroker(File dataDir, int port) throws Except
881898
protected void waitForSubscriptionInactive(final BrokerService brokerService,
882899
final ActiveMQTopic topic,
883900
final String subName) throws Exception {
884-
assertTrue("Subscription should become inactive", Wait.waitFor(new Condition() {
885-
@Override
886-
public boolean isSatisified() throws Exception {
887-
List<org.apache.activemq.broker.region.DurableTopicSubscription> subs = getSubscriptions(brokerService, topic);
888-
for (org.apache.activemq.broker.region.DurableTopicSubscription sub : subs) {
889-
if (sub.getSubscriptionKey().getSubscriptionName().equals(subName)) {
890-
return !sub.isActive();
891-
}
901+
assertTrue("Subscription should become inactive", Wait.waitFor(() -> {
902+
final List<org.apache.activemq.broker.region.DurableTopicSubscription> subs = getSubscriptions(brokerService, topic);
903+
for (final org.apache.activemq.broker.region.DurableTopicSubscription sub : subs) {
904+
if (sub.getSubscriptionKey().getSubscriptionName().equals(subName)) {
905+
return !sub.isActive();
892906
}
893-
// If subscription doesn't exist, it's considered inactive
894-
return true;
895907
}
896-
}, 5000, 100));
908+
// If subscription doesn't exist, it's considered inactive
909+
return true;
910+
}, TimeUnit.SECONDS.toMillis(10), 100));
897911
}
898912

899913
}

activemq-unit-tests/src/test/java/org/apache/activemq/network/DynamicNetworkTestSupport.java

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import java.lang.reflect.Field;
2525
import java.util.ArrayList;
2626
import java.util.List;
27+
import java.util.concurrent.TimeUnit;
2728

2829
import jakarta.jms.Connection;
2930
import jakarta.jms.JMSException;
@@ -45,7 +46,6 @@
4546
import org.apache.activemq.command.RemoveSubscriptionInfo;
4647
import org.apache.activemq.util.SubscriptionKey;
4748
import org.apache.activemq.util.Wait;
48-
import org.apache.activemq.util.Wait.Condition;
4949
import org.junit.Rule;
5050
import org.junit.rules.TemporaryFolder;
5151

@@ -95,9 +95,16 @@ protected void stopRemoteBroker() throws Exception {
9595
}
9696

9797
protected void assertBridgeStarted() throws Exception {
98-
assertTrue(Wait.waitFor(
99-
() -> localBroker.getNetworkConnectors().get(0).activeBridges().size() == 1,
100-
10000, 500));
98+
assertTrue("Bridge should be fully started", Wait.waitFor(() -> {
99+
if (localBroker.getNetworkConnectors().get(0).activeBridges().size() != 1) {
100+
return false;
101+
}
102+
final NetworkBridge bridge = localBroker.getNetworkConnectors().get(0).activeBridges().iterator().next();
103+
if (bridge instanceof DemandForwardingBridgeSupport) {
104+
return ((DemandForwardingBridgeSupport) bridge).startedLatch.getCount() == 0;
105+
}
106+
return true;
107+
}, TimeUnit.SECONDS.toMillis(10), 500));
101108
}
102109

103110
protected RemoveSubscriptionInfo getRemoveSubscriptionInfo(final ConnectionContext context,
@@ -135,17 +142,19 @@ protected interface ConsumerCreator {
135142

136143
protected void assertNCDurableSubsCount(final BrokerService brokerService,
137144
final ActiveMQTopic dest, final int count) throws Exception {
138-
assertTrue(Wait.waitFor(() -> count == getNCDurableSubs(brokerService, dest).size(),
139-
10000, 500));
145+
assertTrue("Expected " + count + " NC durable subs on " + dest,
146+
Wait.waitFor(() -> count == getNCDurableSubs(brokerService, dest).size(),
147+
TimeUnit.SECONDS.toMillis(30), 500));
140148
}
141149

142150
protected void assertConsumersCount(final BrokerService brokerService,
143151
final ActiveMQDestination dest, final int count) throws Exception {
144152
assertTrue(Wait.waitFor(() -> count == getConsumers(brokerService, dest).size(),
145153
10000, 500));
146-
Thread.sleep(1000);
147-
// Check one more time after a short pause to make sure the count didn't increase past what we wanted
148-
assertEquals(count, getConsumers(brokerService, dest).size());
154+
// Wait a bit longer and verify the count is stable (didn't increase past what we wanted)
155+
assertTrue("Consumer count should remain stable at " + count,
156+
Wait.waitFor(() -> count == getConsumers(brokerService, dest).size(),
157+
TimeUnit.SECONDS.toMillis(5), 500));
149158
}
150159

151160
protected List<Subscription> getConsumers(final BrokerService brokerService,
@@ -208,12 +217,9 @@ protected void removeSubscription(final BrokerService brokerService,
208217

209218
protected void assertSubscriptionsCount(final BrokerService brokerService,
210219
final ActiveMQTopic dest, final int count) throws Exception {
211-
assertTrue(Wait.waitFor(new Condition() {
212-
@Override
213-
public boolean isSatisified() throws Exception {
214-
return count == getSubscriptions(brokerService, dest).size();
215-
}
216-
}, 10000, 500));
220+
assertTrue("Expected " + count + " subscriptions on " + dest,
221+
Wait.waitFor(() -> count == getSubscriptions(brokerService, dest).size(),
222+
TimeUnit.SECONDS.toMillis(30), 500));
217223
}
218224

219225
protected void assertSubscriptionMapCounts(NetworkBridge networkBridge, final int count) {

activemq-unit-tests/src/test/java/org/apache/activemq/network/DynamicallyIncludedDestinationsDuplexNetworkTest.java

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -80,19 +80,19 @@ public void testTempQueues() throws Exception {
8080
assertEquals("Destination not deleted", 0, remoteBroker.getAdminView().getTemporaryQueues().length);
8181
}
8282

83-
@Test
83+
@Test(timeout = 60 * 1000)
8484
public void testDynamicallyIncludedDestinationsForDuplex() throws Exception{
8585
// Once the bridge is set up, we should see the filter used for the duplex end of the bridge
8686
// only subscribe to the specific destinations included in the <dynamicallyIncludedDestinations> list
8787
// so let's test that the filter is correct, let's also test the subscription on the localbroker
8888
// is correct
8989

9090
// the bridge on the remote broker has the correct filter
91-
TransportConnection bridgeConnection = getDuplexBridgeConnectionFromRemote();
91+
final TransportConnection bridgeConnection = getDuplexBridgeConnectionFromRemote();
9292
assertNotNull(bridgeConnection);
93-
DemandForwardingBridge duplexBridge = getDuplexBridgeFromConnection(bridgeConnection);
93+
final DemandForwardingBridge duplexBridge = waitForDuplexBridge(bridgeConnection);
9494
assertNotNull(duplexBridge);
95-
NetworkBridgeConfiguration configuration = getConfigurationFromNetworkBridge(duplexBridge);
95+
final NetworkBridgeConfiguration configuration = getConfigurationFromNetworkBridge(duplexBridge);
9696
assertNotNull(configuration);
9797
assertFalse("This destinationFilter does not include ONLY the destinations specified in dynamicallyIncludedDestinations",
9898
configuration.getDestinationFilter().equals(AdvisorySupport.CONSUMER_ADVISORY_TOPIC_PREFIX + ">"));
@@ -115,17 +115,20 @@ private DemandForwardingBridge getDuplexBridgeFromConnection(TransportConnection
115115
return bridge;
116116
}
117117

118+
private DemandForwardingBridge waitForDuplexBridge(final TransportConnection bridgeConnection) throws Exception {
119+
assertTrue("Timed out waiting for duplex bridge to be fully started",
120+
Wait.waitFor(() -> {
121+
final DemandForwardingBridge bridge = getDuplexBridgeFromConnection(bridgeConnection);
122+
return bridge != null && bridge.getRemoteBrokerName() != null;
123+
}));
124+
return getDuplexBridgeFromConnection(bridgeConnection);
125+
}
126+
118127
public TransportConnection getDuplexBridgeConnectionFromRemote() throws Exception {
119128
final TransportConnector transportConnector = remoteBroker.getTransportConnectorByScheme("tcp");
120129
assertTrue("Timed out waiting for duplex bridge connection",
121-
Wait.waitFor(new Wait.Condition() {
122-
@Override
123-
public boolean isSatisified() {
124-
return !transportConnector.getConnections().isEmpty();
125-
}
126-
}));
127-
CopyOnWriteArrayList<TransportConnection> transportConnections = transportConnector.getConnections();
128-
return transportConnections.get(0);
130+
Wait.waitFor(() -> !transportConnector.getConnections().isEmpty()));
131+
return transportConnector.getConnections().get(0);
129132
}
130133

131134
@Override

0 commit comments

Comments
 (0)