Skip to content

Commit da91e49

Browse files
IGNITE-25599 Wait for pending messages to be sent before checks (#12126)
1 parent e457dcc commit da91e49

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

modules/core/src/test/java/org/apache/ignite/spi/discovery/tcp/TcpDiscoverySelfTest.java

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,9 @@ public class TcpDiscoverySelfTest extends GridCommonAbstractTest {
125125
/** */
126126
private UUID nodeId;
127127

128+
/** Flag to disable metrics for some tests. */
129+
private boolean metricsEnabled = true;
130+
128131
/** */
129132
private static ThreadLocal<TcpDiscoverySpi> nodeSpi = new ThreadLocal<>();
130133

@@ -185,7 +188,10 @@ public TcpDiscoverySelfTest() throws Exception {
185188

186189
cfg.setIncludeProperties();
187190

188-
cfg.setMetricsUpdateFrequency(1000);
191+
if (!metricsEnabled) {
192+
cfg.setMetricsUpdateFrequency(Long.MAX_VALUE);
193+
cfg.setClientFailureDetectionTimeout(Long.MAX_VALUE);
194+
}
189195

190196
if (!igniteInstanceName.contains("LoopbackProblemTest"))
191197
cfg.setLocalHost("127.0.0.1");
@@ -1937,6 +1943,18 @@ public void testFailedCoordinatorNodeNoopSegmentationPolicy() throws Exception {
19371943
checkFailedCoordinatorNode(SegmentationPolicy.NOOP);
19381944
}
19391945

1946+
/**
1947+
* Waits for pending messages collected by a given {@link TcpDiscoverySpi} to be discarded.
1948+
* @param spi {@link TcpDiscoverySpi} collecting pending messages.
1949+
* @return {@code true} If pending messages were discarded in a timeout period.
1950+
* @throws IgniteInterruptedCheckedException If wait was interrupted.
1951+
*/
1952+
private boolean waitPendingMessagesDiscarded(TcpDiscoverySpi spi) throws IgniteInterruptedCheckedException {
1953+
Iterable<?> pendingMsgsIterable = GridTestUtils.getFieldValue(spi.impl, "msgWorker", "pendingMsgs");
1954+
1955+
return GridTestUtils.waitForCondition(() -> !pendingMsgsIterable.iterator().hasNext(), 1000);
1956+
}
1957+
19401958
/**
19411959
* @param segPlc Segmentation policy.
19421960
* @throws Exception If failed.
@@ -2037,6 +2055,9 @@ public void testCustomEventAckNotSend() throws Exception {
20372055
@Test
20382056
public void testDiscoveryEventsDiscard() throws Exception {
20392057
try {
2058+
// disable metrics to avoid sending metrics messages as they may mess with pending messages counting.
2059+
metricsEnabled = false;
2060+
20402061
TestEventDiscardSpi spi = new TestEventDiscardSpi();
20412062

20422063
nodeSpi.set(spi);
@@ -2049,6 +2070,13 @@ public void testDiscoveryEventsDiscard() throws Exception {
20492070

20502071
ignite0.destroyCache(DEFAULT_CACHE_NAME); // Send custom message.
20512072

2073+
// We need to wait for discartion of pending messages from asynchronous processes like removing cache
2074+
// metrics from DMS. Initially the test was correct as createCache/destroyCache methods are synchronous
2075+
// and block test-runner thread for long enough for pending messages to be discarded.
2076+
// But at some point aforementioned operations were added and implicit assumption the test relies on was broken.
2077+
boolean pendingMsgsDiscarded = waitPendingMessagesDiscarded(spi);
2078+
assertTrue(pendingMsgsDiscarded);
2079+
20522080
stopGrid(1);
20532081

20542082
log.info("Start new node.");
@@ -2063,6 +2091,8 @@ public void testDiscoveryEventsDiscard() throws Exception {
20632091
}
20642092
finally {
20652093
stopAllGrids();
2094+
2095+
metricsEnabled = true;
20662096
}
20672097
}
20682098

0 commit comments

Comments
 (0)