mirror of https://github.com/dapr/java-sdk.git
fix flaky integration test SdkResiliencytIT (#960)
* fix flaky integration test SdkResiliencytIT Signed-off-by: MregXN <mregxn@gmail.com> * Update sdk-tests/src/test/java/io/dapr/it/resiliency/SdkResiliencytIT.java Co-authored-by: Mukundan Sundararajan <65565396+mukundansundar@users.noreply.github.com> Signed-off-by: MregXN <46479059+MregXN@users.noreply.github.com> * Update sdk-tests/src/test/java/io/dapr/it/resiliency/SdkResiliencytIT.java Co-authored-by: Mukundan Sundararajan <65565396+mukundansundar@users.noreply.github.com> Signed-off-by: MregXN <46479059+MregXN@users.noreply.github.com> * Update sdk-tests/src/test/java/io/dapr/it/resiliency/SdkResiliencytIT.java Co-authored-by: Mukundan Sundararajan <65565396+mukundansundar@users.noreply.github.com> Signed-off-by: MregXN <46479059+MregXN@users.noreply.github.com> --------- Signed-off-by: MregXN <mregxn@gmail.com> Signed-off-by: MregXN <46479059+MregXN@users.noreply.github.com> Co-authored-by: Mukundan Sundararajan <65565396+mukundansundar@users.noreply.github.com> Co-authored-by: Artur Souza <artursouza.ms@outlook.com>
This commit is contained in:
parent
da395f8dac
commit
4ef96e19f4
|
@ -38,7 +38,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
*/
|
*/
|
||||||
public class SdkResiliencytIT extends BaseIT {
|
public class SdkResiliencytIT extends BaseIT {
|
||||||
|
|
||||||
private static final int NUM_ITERATIONS = 30;
|
private static final int NUM_ITERATIONS = 35;
|
||||||
|
|
||||||
private static final Duration TIMEOUT = Duration.ofMillis(100);
|
private static final Duration TIMEOUT = Duration.ofMillis(100);
|
||||||
|
|
||||||
|
@ -116,36 +116,43 @@ public class SdkResiliencytIT extends BaseIT {
|
||||||
public void retryAndTimeout() {
|
public void retryAndTimeout() {
|
||||||
AtomicInteger toxiClientErrorCount = new AtomicInteger();
|
AtomicInteger toxiClientErrorCount = new AtomicInteger();
|
||||||
AtomicInteger retryOneClientErrorCount = new AtomicInteger();
|
AtomicInteger retryOneClientErrorCount = new AtomicInteger();
|
||||||
for (int i = 0; i < NUM_ITERATIONS; i++) {
|
|
||||||
String key = randomStateKeyPrefix + "_" + i;
|
while (true){
|
||||||
String value = Base64.getEncoder().encodeToString(key.getBytes(StandardCharsets.UTF_8));
|
for (int i = 0; i < NUM_ITERATIONS; i++) {
|
||||||
try {
|
String key = randomStateKeyPrefix + "_" + i;
|
||||||
daprToxiClient.saveState(STATE_STORE_NAME, key, value).block();
|
String value = Base64.getEncoder().encodeToString(key.getBytes(StandardCharsets.UTF_8));
|
||||||
} catch (Exception e) {
|
try {
|
||||||
// This call should fail sometimes. So, we count.
|
daprToxiClient.saveState(STATE_STORE_NAME, key, value).block();
|
||||||
toxiClientErrorCount.incrementAndGet();
|
} catch (Exception e) {
|
||||||
}
|
// This call should fail sometimes. So, we count.
|
||||||
try {
|
toxiClientErrorCount.incrementAndGet();
|
||||||
daprRetriesOnceClient.saveState(STATE_STORE_NAME, key, value).block();
|
}
|
||||||
} catch (Exception e) {
|
try {
|
||||||
// This call should fail sometimes. So, we count.
|
daprRetriesOnceClient.saveState(STATE_STORE_NAME, key, value).block();
|
||||||
retryOneClientErrorCount.incrementAndGet();
|
} catch (Exception e) {
|
||||||
|
// This call should fail sometimes. So, we count.
|
||||||
|
retryOneClientErrorCount.incrementAndGet();
|
||||||
|
}
|
||||||
|
|
||||||
|
// We retry forever so that the call below should always work.
|
||||||
|
daprResilientClient.saveState(STATE_STORE_NAME, key, value).block();
|
||||||
|
// Makes sure the value was actually saved.
|
||||||
|
String savedValue = daprClient.getState(STATE_STORE_NAME, key, String.class).block().getValue();
|
||||||
|
assertEquals(value, savedValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
// We retry forever so that the call below should always work.
|
// We should have at least one success per client, otherwise retry.
|
||||||
daprResilientClient.saveState(STATE_STORE_NAME, key, value).block();
|
if(toxiClientErrorCount.get() < NUM_ITERATIONS && retryOneClientErrorCount.get() < NUM_ITERATIONS){
|
||||||
// Makes sure the value was actually saved.
|
// This assertion makes sure that toxicity is on
|
||||||
String savedValue = daprClient.getState(STATE_STORE_NAME, key, String.class).block().getValue();
|
assertTrue(toxiClientErrorCount.get() > 0);
|
||||||
assertEquals(value, savedValue);
|
assertTrue(retryOneClientErrorCount.get() > 0);
|
||||||
|
// A client without retries should have more errors than a client with one retry.
|
||||||
|
assertTrue(toxiClientErrorCount.get() > retryOneClientErrorCount.get());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
toxiClientErrorCount.set(0);
|
||||||
|
retryOneClientErrorCount.set(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Asserts that we had at least one success per client.
|
|
||||||
assertTrue(toxiClientErrorCount.get() < NUM_ITERATIONS);
|
|
||||||
assertTrue(retryOneClientErrorCount.get() < NUM_ITERATIONS);
|
|
||||||
// This assertion makes sure that toxicity is on
|
|
||||||
assertTrue(toxiClientErrorCount.get() > 0);
|
|
||||||
assertTrue(retryOneClientErrorCount.get() > 0);
|
|
||||||
// A client without retries should have more errors than a client with one retry.
|
|
||||||
assertTrue(toxiClientErrorCount.get() > retryOneClientErrorCount.get());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue