Skip to content

Commit

Permalink
Adjust latency and jitter for Toxi proxy to stabilize SDK resiliency …
Browse files Browse the repository at this point in the history
…IT (#1070)
  • Loading branch information
artur-ciocanu authored Jul 10, 2024
1 parent 3dadc0b commit a4ec275
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
/**
* Test SDK resiliency.
*/
public class ActorSdkResiliencytIT extends BaseIT {
public class ActorSdkResiliencyIT extends BaseIT {

private static final ActorId ACTOR_ID = new ActorId(UUID.randomUUID().toString());

Expand Down Expand Up @@ -69,7 +69,7 @@ public class ActorSdkResiliencytIT extends BaseIT {
@BeforeAll
public static void init() throws Exception {
daprRun = startDaprApp(
ActorSdkResiliencytIT.class.getSimpleName(),
ActorSdkResiliencyIT.class.getSimpleName(),
DemoActorService.SUCCESS_MESSAGE,
DemoActorService.class,
true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,18 @@
/**
* Test SDK resiliency.
*/
public class SdkResiliencytIT extends BaseIT {
public class SdkResiliencyIT extends BaseIT {

private static final int NUM_ITERATIONS = 35;

private static final Duration TIMEOUT = Duration.ofMillis(100);

private static final Duration LATENCY = TIMEOUT.dividedBy(2);
private static final Duration LATENCY = TIMEOUT.dividedBy(3);

private static final Duration JITTER = TIMEOUT.multipliedBy(2);
private static final Duration JITTER = TIMEOUT.multipliedBy(3);

private static final int MAX_RETRIES = -1; // Infinity

private static DaprRun daprRun;

private static DaprClient daprClient;

private static ToxiProxyRun toxiProxyRun;
Expand All @@ -64,7 +62,7 @@ public class SdkResiliencytIT extends BaseIT {

@BeforeAll
public static void init() throws Exception {
daprRun = startDaprApp(SdkResiliencytIT.class.getSimpleName(), 5000);
DaprRun daprRun = startDaprApp(SdkResiliencyIT.class.getSimpleName(), 5000);
daprClient = new DaprClientBuilder().build();
daprClient.waitForSidecar(8000).block();

Expand Down Expand Up @@ -113,7 +111,7 @@ public static void tearDown() throws Exception {
@Test
public void retryAndTimeout() {
AtomicInteger toxiClientErrorCount = new AtomicInteger();
AtomicInteger retryOneClientErrorCount = new AtomicInteger();
AtomicInteger retryOnceClientErrorCount = new AtomicInteger();

while (true){
for (int i = 0; i < NUM_ITERATIONS; i++) {
Expand All @@ -129,7 +127,7 @@ public void retryAndTimeout() {
daprRetriesOnceClient.saveState(STATE_STORE_NAME, key, value).block();
} catch (Exception e) {
// This call should fail sometimes. So, we count.
retryOneClientErrorCount.incrementAndGet();
retryOnceClientErrorCount.incrementAndGet();
}

// We retry forever so that the call below should always work.
Expand All @@ -140,17 +138,29 @@ public void retryAndTimeout() {
}

// We should have at least one success per client, otherwise retry.
if(toxiClientErrorCount.get() < NUM_ITERATIONS && retryOneClientErrorCount.get() < NUM_ITERATIONS){
if(toxiClientErrorCount.get() < NUM_ITERATIONS && retryOnceClientErrorCount.get() < NUM_ITERATIONS){
// This assertion makes sure that toxicity is on
assertTrue(toxiClientErrorCount.get() > 0);
assertTrue(retryOneClientErrorCount.get() > 0);
assertTrue(toxiClientErrorCount.get() > 0, "Toxi client error count is 0");
assertTrue(retryOnceClientErrorCount.get() > 0, "Retry once client error count is 0");
// A client without retries should have more errors than a client with one retry.
assertTrue(toxiClientErrorCount.get() > retryOneClientErrorCount.get());

String failureMessage = formatFailureMessage(toxiClientErrorCount, retryOnceClientErrorCount);
assertTrue(toxiClientErrorCount.get() > retryOnceClientErrorCount.get(), failureMessage);
break;
}
toxiClientErrorCount.set(0);
retryOneClientErrorCount.set(0);
retryOnceClientErrorCount.set(0);
}
}

private static String formatFailureMessage(
AtomicInteger toxiClientErrorCount,
AtomicInteger retryOnceClientErrorCount
) {
return String.format(
"Toxi client error count: %d, Retry once client error count: %d",
toxiClientErrorCount.get(),
retryOnceClientErrorCount.get()
);
}
}

0 comments on commit a4ec275

Please sign in to comment.