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

test: increment time continuously #8508

Merged
1 commit merged into from
Jan 4, 2022
Merged
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 @@ -15,12 +15,15 @@
import io.camunda.zeebe.broker.exporter.util.ControlledTestExporter;
import io.camunda.zeebe.protocol.impl.record.value.deployment.DeploymentRecord;
import io.camunda.zeebe.protocol.record.intent.DeploymentIntent;
import io.camunda.zeebe.util.sched.clock.ControlledActorClock;
import java.time.Duration;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import org.awaitility.Awaitility;
import org.awaitility.core.ConditionEvaluationListener;
import org.awaitility.core.EvaluatedCondition;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
Expand Down Expand Up @@ -106,6 +109,7 @@ public void shouldDistributeExporterPositions() {

// then
Awaitility.await("Active Director has distributed positions and passive has received it")
.conditionEvaluationListener(new ClockShifter(activeExporters.getClock()))
.untilAsserted(
() -> {
assertThat(passiveExporterState.getPosition(EXPORTER_ID_1)).isEqualTo(position);
Expand Down Expand Up @@ -133,6 +137,7 @@ public void shouldNotResetExporterPositionWhenOldPositionReceived() {

final var passiveExporterState = passiveExporters.getExportersState();
Awaitility.await("Active Director has distributed positions and passive has received it")
.conditionEvaluationListener(new ClockShifter(activeExporters.getClock()))
.untilAsserted(
() -> {
assertThat(passiveExporterState.getPosition(EXPORTER_ID_1)).isEqualTo(position);
Expand All @@ -153,4 +158,25 @@ public void shouldNotResetExporterPositionWhenOldPositionReceived() {
// then - the exported position should not go back
assertThat(passiveExporterState.getPosition(EXPORTER_ID_1)).isEqualTo(position);
}

/**
* Shifts the actor clock by the {@link this#DISTRIBUTION_INTERVAL} after an awaitility condition
* was evaluated.
*
* <p>This makes sure that even if we miss one export position event, we distribute the event
* later again, which makes tests less flaky.
*/
private static final class ClockShifter implements ConditionEvaluationListener<Void> {

private final ControlledActorClock clock;

public ClockShifter(final ControlledActorClock clock) {
this.clock = clock;
}

@Override
public void conditionEvaluated(final EvaluatedCondition<Void> condition) {
clock.addTime(DISTRIBUTION_INTERVAL);
}
}
}