Skip to content

Commit

Permalink
fix Latency in multi-experiment matches (#15)
Browse files Browse the repository at this point in the history
Co-authored-by: Jeff Nickoloff <[email protected]>
  • Loading branch information
allingeek and Jeff Nickoloff authored Dec 16, 2024
1 parent babf557 commit 9d63f37
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public void applyBehavior(Experiment[] experiments) {
try {
int latencyToInject = Integer.parseInt(e.getEffect().get("latency").toString());
timeout(latencyToInject);
return;
continue;
} catch (NumberFormatException nfe) {
throw new FailureFlagException("Invalid value for latency passed");
}
Expand Down
32 changes: 32 additions & 0 deletions src/test/java/com/gremlin/failureflags/FailureFlagsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@

import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
Expand Down Expand Up @@ -189,6 +191,36 @@ public void invoke_introducesLatency_whenExperimentReturnedAndLatencyInEffectAnd
assertTrue((end-start) < 700);
}

@Test
public void invoke_introducesTwoLatency_whenTwoExperimentsReturnedAndLatencyInEffectAndLatencyBehaviorPassed() {
Map<String, Object> effect = new HashMap<>();
effect.put("latency", 500);
Experiment exp1 = new Experiment();
exp1.setEffect(effect);
exp1.setRate(1.0f);
Experiment exp2 = new Experiment();
exp2.setEffect(effect);
exp2.setRate(1.0f);
List<Experiment> experiments = Arrays.asList(exp1, exp2);

try {
stubFor(post(urlEqualTo("/experiment"))
.willReturn(aResponse()
.withStatus(200)
.withHeader("Content-Type", "application/json")
.withBody(MAPPER.writeValueAsString(experiments))));
} catch (JsonProcessingException e) {

}
Map<String, String> labels = new HashMap<>();
labels.put("key", "value");
long start = LocalDateTime.now().toInstant(ZoneOffset.UTC).toEpochMilli();
GremlinFailureFlags failureFlags = new GremlinFailureFlags();
failureFlags.enabled = true;
failureFlags.invoke(new FailureFlag("test-1", labels, true), new Latency());
long end = LocalDateTime.now().toInstant(ZoneOffset.UTC).toEpochMilli();
assertTrue((end-start) > 900);
}

@Test
public void invoke_introducesLatency_whenExperimentReturnedAndLatencyInEffectInObject() {
Expand Down

0 comments on commit 9d63f37

Please sign in to comment.