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

feat: make async test timeout overrideable #4241

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 @@ -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);
}
Loading