Skip to content

Commit

Permalink
fix: fix flaky tests (#3592)
Browse files Browse the repository at this point in the history
  • Loading branch information
ndr-brt authored Nov 6, 2023
1 parent c6f53a5 commit 0831463
Showing 1 changed file with 3 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
import static java.lang.String.valueOf;
import static org.awaitility.Awaitility.await;
import static org.eclipse.edc.connector.dataplane.http.testfixtures.TestFunctions.createRequest;
import static org.eclipse.edc.connector.dataplane.spi.DataFlowStates.COMPLETED;
import static org.eclipse.edc.connector.dataplane.spi.DataFlowStates.NOTIFIED;
import static org.eclipse.edc.junit.testfixtures.TestUtils.getFreePort;
import static org.hamcrest.Matchers.containsString;
Expand Down Expand Up @@ -169,13 +168,9 @@ void transfer_toHttpSink_success(TypeManager typeManager) {
// HTTP Sink Request & Response
httpSinkMockServer.when(postRequest(body), once()).respond(successfulResponse());

// Act & Assert
// Initiate transfer
initiateTransfer(transferRequestPayload(processId, typeManager));

// Wait for transfer to be completed.
await().atMost(timeout).untilAsserted(() -> expectState(processId, COMPLETED));

await().atMost(timeout).untilAsserted(() -> expectState(processId, NOTIFIED));
// Verify HTTP Source server called exactly once.
httpSourceMockServer.verify(getRequest(HTTP_API_PATH), VerificationTimes.once());
// Verify HTTP Sink server called exactly once.
Expand All @@ -197,13 +192,9 @@ void transfer_toHttpSink_withSourceQueryParams_success(TypeManager typeManager)
// HTTP Sink Request & Response
httpSinkMockServer.when(postRequest(body), once()).respond(successfulResponse());

// Act & Assert
// Initiate transfer
initiateTransfer(transferRequestPayload(processId, queryParams, typeManager));

// Wait for transfer to be completed.
await().atMost(timeout).untilAsserted(() -> expectState(processId, COMPLETED));

await().atMost(timeout).untilAsserted(() -> expectState(processId, NOTIFIED));
// Verify HTTP Source server called exactly once.
httpSourceMockServer.verify(getRequest(queryParams, HTTP_API_PATH), VerificationTimes.once());
// Verify HTTP Sink server called exactly once.
Expand All @@ -219,8 +210,6 @@ void transfer_invalidInput_failure(TypeManager typeManager) {
var processId = UUID.randomUUID().toString();
var invalidRequest = transferRequestPayload(processId, typeManager).remove("processId");

// Act & Assert
// Initiate transfer
given()
.baseUri(CONTROL_API_HOST)
.contentType(ContentType.JSON)
Expand All @@ -237,10 +226,8 @@ void transfer_toHttpSink_sourceNotAvailable_noInteractionWithSink(TypeManager ty
// HTTP Source Request & Error Response
httpSourceMockServer.when(getRequest(HTTP_API_PATH)).error(withDropConnection());

// Initiate transfer
initiateTransfer(transferRequestPayload(processId, typeManager));

// Wait for transfer to be completed.
await().atMost(timeout).untilAsserted(() -> expectState(processId, NOTIFIED));
// Verify HTTP Source server called at lest once.
httpSourceMockServer.verify(getRequest(HTTP_API_PATH), VerificationTimes.atLeast(1));
Expand All @@ -264,12 +251,9 @@ void transfer_toHttpSink_sourceTemporaryDropConnection_success(TypeManager typeM
// HTTP Sink Request & Response
httpSinkMockServer.when(postRequest(body), once()).respond(successfulResponse());

// Act & Assert
// Initiate transfer
initiateTransfer(transferRequestPayload(processId, typeManager));

// Wait for transfer to be completed.
await().atMost(timeout).untilAsserted(() -> expectState(processId, COMPLETED));
await().atMost(timeout).untilAsserted(() -> expectState(processId, NOTIFIED));
// Verify HTTP Source server called exactly 3 times.
httpSourceMockServer.verify(getRequest(HTTP_API_PATH), VerificationTimes.exactly(3));
// Verify HTTP Sink server called exactly once.
Expand Down Expand Up @@ -345,12 +329,6 @@ private void initiateTransfer(Object payload) {
.assertThat().statusCode(HttpStatus.SC_OK);
}

/**
* Fetch transfer state and assert if transfer is completed.
*
* @param processId ProcessID of transfer. See {@link DataFlowRequest}
* @param expectedState the expected state
*/
private void expectState(String processId, DataFlowStates expectedState) {
given()
.baseUri(CONTROL_API_HOST)
Expand Down

0 comments on commit 0831463

Please sign in to comment.