Skip to content

Commit

Permalink
chore(standalone-canary-analysis): tweak control offset field name to…
Browse files Browse the repository at this point in the history
… make units clear, add unit test
  • Loading branch information
fieldju committed Dec 21, 2020
1 parent e7fc9cb commit b559be3
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 5 deletions.
64 changes: 64 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 30 additions & 1 deletion .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ public class CanaryAnalysisExecutionRequestScope {

@ApiModelProperty(
value =
"The time offset (in minutes) to apply to the control scope. If none is provided, the control is "
"The time offset in minutes to be subtracted from the control start and end time. If none is provided, the control is "
+ "evaluated at the same time as the experiment.",
example = "10")
@Builder.Default
Long controlOffset = 0L;
Long controlOffsetInMinutes = 0L;

@ApiModelProperty(
value =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,10 @@ protected Map<String, CanaryScopePair> buildRequestScopes(
new CanaryScope(
scope.getControlScope(),
scope.getControlLocation(),
scopeTimeConfig.start.minus(Duration.ofMinutes(scope.getControlOffset())),
scopeTimeConfig.end.minus(Duration.ofMinutes(scope.getControlOffset())),
scopeTimeConfig.start.minus(
Duration.ofMinutes(scope.getControlOffsetInMinutes())),
scopeTimeConfig.end.minus(
Duration.ofMinutes(scope.getControlOffsetInMinutes())),
config.getStep().getSeconds(),
scope.getExtendedScopeParams());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,4 +206,27 @@ public void test_that_calculateLifetime_uses_supplied_start_and_end_time_if_prov
assertEquals(Instant.parse(startIso), actual.getStart());
assertEquals(Instant.parse(startIso).plus(3L, ChronoUnit.MINUTES), actual.getEnd());
}

@Test
public void
test_that_buildRequestScopes_has_expected_start_and_end_when_control_offset_is_supplied() {
int interval = 1;
String startIso = "2018-12-17T20:56:39.689Z";
Duration lifetimeDuration = Duration.ofMinutes(3L);
CanaryAnalysisExecutionRequest request =
CanaryAnalysisExecutionRequest.builder()
.scopes(
ImmutableList.of(
CanaryAnalysisExecutionRequestScope.builder()
.controlOffsetInMinutes(5L)
.startTimeIso(startIso)
.build()))
.build();

var requestScopes = stage.buildRequestScopes(request, interval, lifetimeDuration);
var defaultScope = requestScopes.get("default");
var expectedControlStartIso = "2018-12-17T20:51:39.689Z";
assertEquals(Instant.parse(startIso), defaultScope.getExperimentScope().getStart());
assertEquals(Instant.parse(expectedControlStartIso), defaultScope.getControlScope().getStart());
}
}

0 comments on commit b559be3

Please sign in to comment.