Skip to content

Commit

Permalink
Optimize & clean up e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Sean-DNAstack committed Oct 24, 2023
1 parent 92869fc commit 15038c1
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 52 deletions.
83 changes: 45 additions & 38 deletions e2e-tests/src/main/java/com/dnastack/wes/service/WesE2ETest.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,20 @@
import io.restassured.builder.MultiPartSpecBuilder;
import io.restassured.http.ContentType;
import io.restassured.specification.MultiPartSpecification;
import org.awaitility.Awaitility;
import org.awaitility.core.ConditionFactory;
import org.junit.jupiter.api.*;
import org.junit.jupiter.api.TestInstance.Lifecycle;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.time.Duration;
import java.util.*;
import java.util.stream.Stream;

import static io.restassured.RestAssured.given;
import static org.awaitility.Awaitility.with;
Expand Down Expand Up @@ -431,7 +436,6 @@ public void uploadWorkflowAttachmentWithRunSubmission() throws Exception {
public class RunMethodsWithExistingJobs {

String workflowJobId;
String workflowJobIdWithAllOutputTypes;

@BeforeAll
public void setup() throws InterruptedException {
Expand All @@ -451,22 +455,6 @@ public void setup() throws InterruptedException {
.multiPart(getJsonMultipart("tags", tags))
.multiPart(getJsonMultipart("workflow_params", inputs))
.post(path)
.then()
.assertThat()
.statusCode(200)
.body("run_id",is(notNullValue()))
.extract()
.jsonPath()
.getString("run_id");

workflowJobIdWithAllOutputTypes = given()
.log().uri()
.log().method()
.header(getHeader(getResource(path)))
.multiPart(getWorkflowUrlMultipart("echo.wdl"))
.multiPart(getMultipartAttachment("echo.wdl",supplier.getFileContent(WdlSupplier.WORKFLOW_WITH_ALL_OUTPUT_TYPES).getBytes()))
.multiPart(getJsonMultipart("workflow_params", inputs))
.post(path)
.then()
.assertThat()
.statusCode(200)
Expand Down Expand Up @@ -585,17 +573,17 @@ public void listRunsReturnsReturnsNonEmptyCollection() {
}


@Test
@ParameterizedTest
@MethodSource("completeWorkflowWithFilesProvider")
@DisplayName("Get Run Files for existing run returns all files")
public void getRunFilesReturnsNonEmptyCollection() throws Exception {
String path = getRootPath() + "/runs/" + workflowJobIdWithAllOutputTypes + "/files";
pollUntilJobCompletes(workflowJobIdWithAllOutputTypes);
public void getRunFilesReturnsNonEmptyCollection(String runId) {
String path = getRootPath() + "/runs/" + runId + "/files";

//@formatter:off
given()
.log().uri()
.log().method()
.header(getHeader(getResource(getRootPath() + "/runs/" + workflowJobIdWithAllOutputTypes)))
.header(getHeader(getResource(getRootPath() + "/runs/" + runId)))
.accept(ContentType.JSON)
.get(path)
.then()
Expand Down Expand Up @@ -627,18 +615,17 @@ public void getRunFilesForNonExistentRunShouldFail() {
}


@Test
@ParameterizedTest
@MethodSource("completeWorkflowWithFilesProvider")
@DisplayName("Delete Run Files for existing run returns all deleted files")
public void deleteRunFilesReturnsNonEmptyCollection() throws Exception {
reRunWorkflowWithAllOutputTypes();
String path = getRootPath() + "/runs/" + workflowJobIdWithAllOutputTypes + "/files";
pollUntilJobCompletes(workflowJobIdWithAllOutputTypes);
public void deleteRunFilesReturnsNonEmptyCollection(String runId) {
String path = getRootPath() + "/runs/" + runId + "/files";

//@formatter:off
given()
.log().uri()
.log().method()
.header(getHeader(getResource(getRootPath() + "/runs/" + workflowJobIdWithAllOutputTypes)))
.header(getHeader(getResource(getRootPath() + "/runs/" + runId)))
.accept(ContentType.JSON)
.delete(path)
.then()
Expand All @@ -650,18 +637,17 @@ public void deleteRunFilesReturnsNonEmptyCollection() throws Exception {
}


@Test
@ParameterizedTest
@MethodSource("completeWorkflowWithFilesProvider")
@DisplayName("Delete Run Files for existing run asynchronously returns all deleted files")
public void deleteRunFilesAsyncReturnsNonEmptyCollection() throws Exception {
reRunWorkflowWithAllOutputTypes();
String path = getRootPath() + "/runs/" + workflowJobIdWithAllOutputTypes + "/files";
pollUntilJobCompletes(workflowJobIdWithAllOutputTypes);
public void deleteRunFilesAsyncReturnsNonEmptyCollection(String runId) {
String path = getRootPath() + "/runs/" + runId + "/files";

//@formatter:off
given()
.log().uri()
.log().method()
.header(getHeader(getResource(getRootPath() + "/runs/" + workflowJobIdWithAllOutputTypes)))
.header(getHeader(getResource(getRootPath() + "/runs/" + runId)))
.accept(ContentType.JSON)
.queryParam("async", true)
.delete(path)
Expand All @@ -671,6 +657,24 @@ public void deleteRunFilesAsyncReturnsNonEmptyCollection() throws Exception {
.body("deletions.size()", greaterThan(0))
.body("deletions.every { it.path != null && it.file_type == 'SECONDARY' && it.state == 'ASYNC' }", equalTo(true));
//@formatter:on

Awaitility.await()
.atMost(Duration.ofSeconds(30))
.pollInterval(Duration.ofSeconds(5))
.untilAsserted(() ->
//@formatter:off
given()
.log().uri()
.log().method()
.header(getHeader(getResource(getRootPath() + "/runs/" + runId)))
.accept(ContentType.JSON)
.get(path)
.then()
.assertThat()
.statusCode(200)
.body("runFiles.size()", greaterThan(0))
.body("runFiles.every { it.path != null && it.file_type in ['FINAL', 'LOG'] }", equalTo(true)));
//@formatter:on
}


Expand All @@ -694,27 +698,30 @@ public void deleteRunFilesForNonExistentRunShouldFail() {
}


private void reRunWorkflowWithAllOutputTypes() {
private Stream<Arguments> completeWorkflowWithFilesProvider() throws Exception {
String path = getRootPath() + "/runs";
Map<String, String> inputs = Collections.singletonMap("hello_world.name", "Some sort of String");

//@formatter:off
workflowJobIdWithAllOutputTypes = given()
String workflowJobIdWithAllOutputTypes = given()
.log().uri()
.log().method()
.header(getHeader(getResource(path)))
.multiPart(getWorkflowUrlMultipart("echo.wdl"))
.multiPart(getMultipartAttachment("echo.wdl",supplier.getFileContent(WdlSupplier.WORKFLOW_WITH_ALL_OUTPUT_TYPES).getBytes()))
.multiPart(getMultipartAttachment("echo.wdl", supplier.getFileContent(WdlSupplier.WORKFLOW_WITH_ALL_OUTPUT_TYPES).getBytes()))
.multiPart(getJsonMultipart("workflow_params", inputs))
.post(path)
.then()
.assertThat()
.statusCode(200)
.body("run_id",is(notNullValue()))
.body("run_id", is(notNullValue()))
.extract()
.jsonPath()
.getString("run_id");
//@formatter:on

pollUntilJobCompletes(workflowJobIdWithAllOutputTypes);
return Stream.of(Arguments.of(workflowJobIdWithAllOutputTypes));
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,7 @@ public void testWritingBytesToFile_existingFileThrowsError() throws IOException
@Test
public void testReadingFile() throws IOException {
LocalBlobStorageClient storageClient = new LocalBlobStorageClient();
Path targetPath = Path.of(storageClient.getStagingPath() + "/" + directory + "/" + fileName);
Files.createDirectory(targetPath.getParent());
Files.write(targetPath, toWrite.getBytes(), StandardOpenOption.CREATE_NEW);
Path targetPath = createFile();

ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
storageClient.readBytes(outputStream, targetPath.toString(), HttpRange.createByteRange(0L,toWrite.length()));
Expand All @@ -76,9 +74,7 @@ public void testReadingFile() throws IOException {
@Test
public void testReadingFile_withTruncation() throws IOException {
LocalBlobStorageClient storageClient = new LocalBlobStorageClient();
Path targetPath = Path.of(storageClient.getStagingPath() + "/" + directory + "/" + fileName);
Files.createDirectory(targetPath.getParent());
Files.write(targetPath, toWrite.getBytes(), StandardOpenOption.CREATE_NEW);
Path targetPath = createFile();

ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

Expand All @@ -90,27 +86,23 @@ public void testReadingFile_withTruncation() throws IOException {
@Test
public void testIsFile() throws IOException {
LocalBlobStorageClient storageClient = new LocalBlobStorageClient();
Path targetPath = Path.of(storageClient.getStagingPath() + "/" + directory + "/" + fileName);
Files.createDirectory(targetPath.getParent());
Files.write(targetPath, toWrite.getBytes(), StandardOpenOption.CREATE_NEW);
Path targetPath = createFile();

Assertions.assertTrue(storageClient.isFile(targetPath.toString()));
}

@Test
public void testIsFile_noFileExists() throws IOException {
LocalBlobStorageClient storageClient = new LocalBlobStorageClient();
Path targetPath = Path.of(storageClient.getStagingPath() + "/" + directory + "/" + fileName);
Path targetPath = Path.of(directory + "/" + fileName);

Assertions.assertFalse(storageClient.isFile(targetPath.toString()));
}

@Test
public void testDeletingFile() throws IOException {
LocalBlobStorageClient storageClient = new LocalBlobStorageClient();
Path targetPath = Path.of(storageClient.getStagingPath() + "/" + directory + "/" + fileName);
Files.createDirectory(targetPath.getParent());
Files.write(targetPath, toWrite.getBytes(), StandardOpenOption.CREATE_NEW);
Path targetPath = createFile();

Assertions.assertTrue(Files.exists(targetPath));
storageClient.deleteFile(targetPath.toString());
Expand All @@ -120,10 +112,17 @@ public void testDeletingFile() throws IOException {
@Test
public void testDeletingFile_throwsError() throws IOException {
LocalBlobStorageClient storageClient = new LocalBlobStorageClient();
Path targetPath = Path.of(storageClient.getStagingPath() + "/" + directory + "/" + fileName);
Path targetPath = Path.of(directory + "/" + fileName);

Assertions.assertFalse(Files.exists(targetPath));
Assertions.assertThrows(IOException.class, () -> storageClient.deleteFile(targetPath.toString()));
}

private Path createFile() throws IOException {
Path tempDir = Files.createTempDirectory(directory);
Path targetPath = tempDir.resolve(fileName);
Files.write(targetPath, toWrite.getBytes(), StandardOpenOption.CREATE_NEW);
return targetPath;
}

}

0 comments on commit 15038c1

Please sign in to comment.