Skip to content

Commit f8e1be3

Browse files
authored
Fix failing network partition test (#4118)
* fix network partition test for possible long duration of fault injection assert with multiple expected msg * wait for working connection
1 parent 6ce5d72 commit f8e1be3

File tree

1 file changed

+30
-14
lines changed

1 file changed

+30
-14
lines changed

src/test/java/redis/clients/jedis/authentication/RedisEntraIDIntegrationTests.java

+30-14
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package redis.clients.jedis.authentication;
22

33
import static org.awaitility.Awaitility.await;
4+
import static org.awaitility.Durations.TWO_SECONDS;
45
import static org.awaitility.Durations.FIVE_SECONDS;
56
import static org.awaitility.Durations.ONE_HUNDRED_MILLISECONDS;
67
import static org.junit.Assert.assertEquals;
@@ -15,6 +16,8 @@
1516
import static org.mockito.Mockito.spy;
1617
import static org.mockito.Mockito.verify;
1718
import static org.mockito.Mockito.when;
19+
import static org.hamcrest.Matchers.in;
20+
import static org.hamcrest.Matchers.is;
1821

1922
import java.io.IOException;
2023
import java.util.ArrayList;
@@ -32,6 +35,7 @@
3235

3336
import org.awaitility.Awaitility;
3437
import org.awaitility.Durations;
38+
import org.hamcrest.MatcherAssert;
3539
import org.junit.BeforeClass;
3640
import org.junit.FixMethodOrder;
3741
import org.junit.Test;
@@ -62,6 +66,7 @@
6266
import redis.clients.jedis.exceptions.JedisAccessControlException;
6367
import redis.clients.jedis.exceptions.JedisConnectionException;
6468
import redis.clients.jedis.scenario.FaultInjectionClient;
69+
import redis.clients.jedis.scenario.FaultInjectionClient.TriggerActionResponse;
6570

6671
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
6772
public class RedisEntraIDIntegrationTests {
@@ -345,34 +350,44 @@ public void networkPartitionEvictionTest() {
345350
jedis.del(key);
346351
}
347352

348-
triggerNetworkFailure();
353+
TriggerActionResponse actionResponse = triggerNetworkFailure();
349354

350355
JedisConnectionException aclException = assertThrows(JedisConnectionException.class, () -> {
351-
for (int i = 0; i < 50; i++) {
352-
String key = UUID.randomUUID().toString();
353-
jedis.set(key, "value");
354-
assertEquals("value", jedis.get(key));
355-
jedis.del(key);
356+
while (!actionResponse.isCompleted(ONE_HUNDRED_MILLISECONDS, TWO_SECONDS, FIVE_SECONDS)) {
357+
for (int i = 0; i < 50; i++) {
358+
String key = UUID.randomUUID().toString();
359+
jedis.set(key, "value");
360+
assertEquals("value", jedis.get(key));
361+
jedis.del(key);
362+
}
356363
}
357364
});
358365

359-
assertEquals("Unexpected end of stream.", aclException.getMessage());
366+
String[] expectedMessages = new String[] { "Unexpected end of stream.",
367+
"java.net.SocketException: Connection reset" };
368+
MatcherAssert.assertThat(aclException.getMessage(), is(in(expectedMessages)));
360369
Awaitility.await().pollDelay(Durations.ONE_HUNDRED_MILLISECONDS).atMost(Durations.TWO_SECONDS)
361370
.until(() -> {
362-
String key = UUID.randomUUID().toString();
363-
jedis.set(key, "value");
364-
assertEquals("value", jedis.get(key));
365-
jedis.del(key);
366-
return true;
371+
try {
372+
String key = UUID.randomUUID().toString();
373+
jedis.set(key, "value");
374+
assertEquals("value", jedis.get(key));
375+
jedis.del(key);
376+
return true;
377+
} catch (Exception e) {
378+
log.debug("attempt to reconnect after network failure, connection has not been re-established yet:"
379+
+ e.getMessage());
380+
return false;
381+
}
367382
});
368383
}
369384
}
370385

371-
private void triggerNetworkFailure() {
386+
private TriggerActionResponse triggerNetworkFailure() {
372387
HashMap<String, Object> params = new HashMap<>();
373388
params.put("bdb_id", endpointConfig.getBdbId());
374389

375-
FaultInjectionClient.TriggerActionResponse actionResponse = null;
390+
TriggerActionResponse actionResponse = null;
376391
String action = "network_failure";
377392
try {
378393
log.info("Triggering {}", action);
@@ -381,6 +396,7 @@ private void triggerNetworkFailure() {
381396
fail("Fault Injection Server error:" + e.getMessage());
382397
}
383398
log.info("Action id: {}", actionResponse.getActionId());
399+
return actionResponse;
384400
}
385401

386402
@Test

0 commit comments

Comments
 (0)