Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjust latency and jitter for Toxi proxy to stabilize SDK resiliency IT #1070

Merged
merged 3 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
);
}
}
Loading