Skip to content

Commit

Permalink
feat: make async test timeout overrideable (#4241)
Browse files Browse the repository at this point in the history
feat(test): make async test timeout overridable
  • Loading branch information
paullatzelsperger authored Jun 6, 2024
1 parent c582647 commit 6e7bb67
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,24 @@ public abstract class TransferProcessStoreTestBase {
protected static final String CONNECTOR_NAME = "test-connector";
protected final Clock clock = Clock.systemUTC();

/**
* determines the amount of time (default = 500ms) before an async test using Awaitility fails. This may be useful if using remote
* or non-self-contained databases.
*/
protected Duration getTestTimeout() {
return Duration.ofMillis(500);
}

protected abstract TransferProcessStore getTransferProcessStore();

protected abstract void leaseEntity(String negotiationId, String owner, Duration duration);

protected void leaseEntity(String negotiationId, String owner) {
leaseEntity(negotiationId, owner, Duration.ofSeconds(60));
}

protected abstract boolean isLeasedBy(String negotiationId, String owner);

@Nested
class Create {
@Test
Expand Down Expand Up @@ -242,7 +260,7 @@ void expiredLease() {
leaseEntity(t.getId(), CONNECTOR_NAME, Duration.ofMillis(100));

Awaitility.await().atLeast(Duration.ofMillis(100))
.atMost(Duration.ofMillis(500))
.atMost(getTestTimeout())
.until(() -> getTransferProcessStore().nextNotLeased(10, hasState(INITIAL.code())), hasSize(1));
}

Expand Down Expand Up @@ -977,14 +995,4 @@ void shouldReturnAlreadyLeased_whenEntityIsAlreadyLeased() {
}
}

protected abstract TransferProcessStore getTransferProcessStore();

protected abstract void leaseEntity(String negotiationId, String owner, Duration duration);

protected void leaseEntity(String negotiationId, String owner) {
leaseEntity(negotiationId, owner, Duration.ofSeconds(60));
}

protected abstract boolean isLeasedBy(String negotiationId, String owner);

}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,36 @@ public abstract class DataPlaneInstanceStoreTestBase {

protected static final String CONNECTOR_NAME = "test-connector";

protected abstract DataPlaneInstanceStore getStore();

protected abstract void leaseEntity(String entityId, String owner, Duration duration);

protected void leaseEntity(String entityId, String owner) {
leaseEntity(entityId, owner, Duration.ofSeconds(60));
}

protected abstract boolean isLeasedBy(String entityId, String owner);

/**
* determines the amount of time (default = 500ms) before an async test using Awaitility fails. This may be useful if using remote
* or non-self-contained databases.
*/
protected Duration getTestTimeout() {
return Duration.ofMillis(500);
}

private DataPlaneInstance createInstanceWithProperty(String id, String name) {
return createInstanceBuilder(id)
.property("name", name)
.build();
}

private DataPlaneInstance.Builder createInstanceBuilder(String id) {
return DataPlaneInstance.Builder.newInstance()
.id(id)
.url("http://somewhere.com:1234/api/v1");
}

@Nested
class FindById {
@Test
Expand Down Expand Up @@ -163,10 +193,11 @@ void shouldLeaseAgainAfterTimePassed() {

leaseEntity(entry.getId(), CONNECTOR_NAME, Duration.ofMillis(100));

await().atMost(Duration.ofMillis(500))
await().atMost(getTestTimeout())
.until(() -> getStore().nextNotLeased(1, hasState(REGISTERED.code())), hasSize(1));
}


@Test
void shouldReturnReleasedEntityByUpdate() {
var entry = createInstanceBuilder(UUID.randomUUID().toString()).state(REGISTERED.code()).build();
Expand Down Expand Up @@ -251,26 +282,4 @@ void shouldFail_whenInstanceDoesNotExist() {

}

protected abstract DataPlaneInstanceStore getStore();

protected abstract void leaseEntity(String entityId, String owner, Duration duration);

protected void leaseEntity(String entityId, String owner) {
leaseEntity(entityId, owner, Duration.ofSeconds(60));
}

protected abstract boolean isLeasedBy(String entityId, String owner);

private DataPlaneInstance createInstanceWithProperty(String id, String name) {
return createInstanceBuilder(id)
.property("name", name)
.build();
}

private DataPlaneInstance.Builder createInstanceBuilder(String id) {
return DataPlaneInstance.Builder.newInstance()
.id(id)
.url("http://somewhere.com:1234/api/v1");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ protected void leaseEntity(String entityId, String owner) {

protected abstract boolean isLeasedBy(String entityId, String owner);

/**
* determines the amount of time (default = 500ms) before an async test using Awaitility fails. This may be useful if using remote
* or non-self-contained databases.
*/
protected Duration getTestTimeout() {
return Duration.ofMillis(500);
}

private DataFlow createDataFlow(String id, DataFlowStates state) {
return DataFlow.Builder.newInstance()
.id(id)
Expand Down Expand Up @@ -149,7 +157,7 @@ void shouldLeaseAgainAfterTimePassed() {

leaseEntity(dataFlow.getId(), CONNECTOR_NAME, Duration.ofMillis(100));

await().atMost(Duration.ofMillis(500))
await().atMost(getTestTimeout())
.until(() -> getStore().nextNotLeased(1, hasState(RECEIVED.code())), hasSize(1));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,32 @@ public abstract class PolicyMonitorStoreTestBase {

protected static final String CONNECTOR_NAME = "test-connector";

/**
* determines the amount of time (default = 500ms) before an async test using Awaitility fails. This may be useful if using remote
* or non-self-contained databases.
*/
protected Duration getTestTimeout() {
return Duration.ofMillis(500);
}

protected abstract PolicyMonitorStore getStore();

protected abstract void leaseEntity(String entityId, String owner, Duration duration);

protected void leaseEntity(String entityId, String owner) {
leaseEntity(entityId, owner, Duration.ofSeconds(60));
}

protected abstract boolean isLeasedBy(String entityId, String owner);

private PolicyMonitorEntry createPolicyMonitorEntry(String id, PolicyMonitorEntryStates state) {
return PolicyMonitorEntry.Builder.newInstance()
.id(id)
.contractId(UUID.randomUUID().toString())
.state(state.code())
.build();
}

@Nested
class Create {

Expand Down Expand Up @@ -125,7 +151,7 @@ void shouldLeaseAgainAfterTimePassed() {

leaseEntity(entry.getId(), CONNECTOR_NAME, Duration.ofMillis(100));

await().atMost(Duration.ofMillis(500))
await().atMost(getTestTimeout())
.until(() -> getStore().nextNotLeased(1, hasState(STARTED.code())), hasSize(1));
}

Expand Down Expand Up @@ -187,22 +213,4 @@ void shouldReturnAlreadyLeased_whenEntityIsAlreadyLeased() {
assertThat(result).isFailed().extracting(StoreFailure::getReason).isEqualTo(ALREADY_LEASED);
}
}

private PolicyMonitorEntry createPolicyMonitorEntry(String id, PolicyMonitorEntryStates state) {
return PolicyMonitorEntry.Builder.newInstance()
.id(id)
.contractId(UUID.randomUUID().toString())
.state(state.code())
.build();
}

protected abstract PolicyMonitorStore getStore();

protected abstract void leaseEntity(String entityId, String owner, Duration duration);

protected void leaseEntity(String entityId, String owner) {
leaseEntity(entityId, owner, Duration.ofSeconds(60));
}

protected abstract boolean isLeasedBy(String entityId, String owner);
}

0 comments on commit 6e7bb67

Please sign in to comment.