@@ -125,6 +125,9 @@ public class TcpDiscoverySelfTest extends GridCommonAbstractTest {
125
125
/** */
126
126
private UUID nodeId ;
127
127
128
+ /** Flag to disable metrics for some tests. */
129
+ private boolean metricsEnabled = true ;
130
+
128
131
/** */
129
132
private static ThreadLocal <TcpDiscoverySpi > nodeSpi = new ThreadLocal <>();
130
133
@@ -185,7 +188,10 @@ public TcpDiscoverySelfTest() throws Exception {
185
188
186
189
cfg .setIncludeProperties ();
187
190
188
- cfg .setMetricsUpdateFrequency (1000 );
191
+ if (!metricsEnabled ) {
192
+ cfg .setMetricsUpdateFrequency (Long .MAX_VALUE );
193
+ cfg .setClientFailureDetectionTimeout (Long .MAX_VALUE );
194
+ }
189
195
190
196
if (!igniteInstanceName .contains ("LoopbackProblemTest" ))
191
197
cfg .setLocalHost ("127.0.0.1" );
@@ -1937,6 +1943,18 @@ public void testFailedCoordinatorNodeNoopSegmentationPolicy() throws Exception {
1937
1943
checkFailedCoordinatorNode (SegmentationPolicy .NOOP );
1938
1944
}
1939
1945
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
+
1940
1958
/**
1941
1959
* @param segPlc Segmentation policy.
1942
1960
* @throws Exception If failed.
@@ -2037,6 +2055,9 @@ public void testCustomEventAckNotSend() throws Exception {
2037
2055
@ Test
2038
2056
public void testDiscoveryEventsDiscard () throws Exception {
2039
2057
try {
2058
+ // disable metrics to avoid sending metrics messages as they may mess with pending messages counting.
2059
+ metricsEnabled = false ;
2060
+
2040
2061
TestEventDiscardSpi spi = new TestEventDiscardSpi ();
2041
2062
2042
2063
nodeSpi .set (spi );
@@ -2049,6 +2070,13 @@ public void testDiscoveryEventsDiscard() throws Exception {
2049
2070
2050
2071
ignite0 .destroyCache (DEFAULT_CACHE_NAME ); // Send custom message.
2051
2072
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
+
2052
2080
stopGrid (1 );
2053
2081
2054
2082
log .info ("Start new node." );
@@ -2063,6 +2091,8 @@ public void testDiscoveryEventsDiscard() throws Exception {
2063
2091
}
2064
2092
finally {
2065
2093
stopAllGrids ();
2094
+
2095
+ metricsEnabled = true ;
2066
2096
}
2067
2097
}
2068
2098
0 commit comments