Skip to content

Commit

Permalink
remove system test clone
Browse files Browse the repository at this point in the history
  • Loading branch information
karottenreibe committed Mar 28, 2024
1 parent 3342917 commit 9c98428
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 49 deletions.
Expand Up @@ -3,6 +3,7 @@
import com.teamscale.report.testwise.model.TestInfo;
import org.apache.commons.lang3.SystemUtils;
import org.conqat.lib.commons.io.ProcessUtils;
import org.jetbrains.annotations.NotNull;
import retrofit2.Call;
import retrofit2.Retrofit;
import retrofit2.http.POST;
Expand All @@ -13,6 +14,7 @@
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -52,25 +54,20 @@ public static String getCoverageString(TestInfo info) {
* @throws IOException if running Maven fails.
*/
public static void runMavenTests(String mavenProjectPath) throws IOException {
File workingDirectory = new File(mavenProjectPath);
runMaven(mavenProjectPath, "clean", "verify");
}

/**
* Runs Maven in the given Maven project path with the given arguments.
*
* @throws IOException if running Maven fails.
*/
public static void runMaven(String mavenProjectPath, String... mavenArguments) throws IOException {
ProcessUtils.ExecutionResult result;
try {
List<String> arguments = new ArrayList<>();
if (SystemUtils.IS_OS_WINDOWS) {
Collections.addAll(arguments, "cmd", "/c", "mvnw.cmd");
} else {
arguments.add("./mvnw");
}

arguments.add("clean");
arguments.add("verify");

result = ProcessUtils.execute(new ProcessBuilder(arguments).directory(workingDirectory));
result = ProcessUtils.execute(buildMavenProcess(mavenProjectPath, mavenArguments));
} catch (IOException e) {
throw new IOException(
"Failed to run ./mvnw clean verify in directory " + workingDirectory.getAbsolutePath(),
e);
throw new IOException("Failed to run ./mvnw clean verify in directory " + mavenProjectPath, e);
}

// in case the process succeeded, we still log stdout and stderr in case later assertions fail. This helps
Expand All @@ -83,6 +80,25 @@ public static void runMavenTests(String mavenProjectPath) throws IOException {
}
}

/**
* Creates the command-line arguments that can be passed to {@link ProcessBuilder} to invoke Maven with the given
* arguments.
*/
@NotNull
public static ProcessBuilder buildMavenProcess(String mavenProjectDirectory, String... mavenArguments) {
List<String> arguments = new ArrayList<>();
if (SystemUtils.IS_OS_WINDOWS) {
Collections.addAll(arguments, "cmd", "/c", "mvnw.cmd");
} else {
arguments.add("./mvnw");
}

arguments.addAll(Arrays.asList(mavenArguments));


return new ProcessBuilder(arguments).directory(new File(mavenProjectDirectory));
}

/** Retrieve all files in the `tia/reports` folder sorted by name. */
public static List<Path> getReportFileNames(String mavenProjectPath) throws IOException {
try (Stream<Path> stream = Files.walk(Paths.get(mavenProjectPath, "target", "tia", "reports"))) {
Expand Down
@@ -1,15 +1,11 @@
package com.teamscale.tia;

import org.apache.commons.lang3.SystemUtils;
import com.teamscale.test.commons.SystemTestUtils;
import org.conqat.lib.commons.filesystem.FileSystemUtils;
import org.conqat.lib.commons.io.ProcessUtils;
import org.junit.jupiter.api.Test;

import java.io.File;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;

Expand All @@ -18,43 +14,28 @@
*/
public class TiaMavenMultipleJobsTest {

private List<String> createMavenArguments(String... mavenCommands) {
List<String> arguments = new ArrayList<>();
if (SystemUtils.IS_OS_WINDOWS) {
Collections.addAll(arguments, "cmd", "/c",
Paths.get("maven-dump-local-project", "mvnw.cmd").toUri().getPath());
} else {
arguments.add("./mvnw");
}

Collections.addAll(arguments, mavenCommands);
return arguments;
}

/**
* Starts multiple maven processes and checks that the ports are dynamically set and the servers are correctly
* Starts multiple Maven processes and checks that the ports are dynamically set and the servers are correctly
* started.
*/
@Test
public void testMavenTia() throws Exception {
File workingDirectory = new File("maven-dump-local-project");
String workingDirectory = "maven-dump-local-project";

// Clean once before testing parallel execution and make sure that the cleaning
// process is finished before testing.
ProcessUtils.ExecutionResult result = ProcessUtils.execute(
new ProcessBuilder(createMavenArguments("clean")).directory(workingDirectory));
assertThat(result.terminatedByTimeoutOrInterruption()).isFalse();
SystemTestUtils.runMaven(workingDirectory, "clean");

// run three verify processes in parallel without waiting
for (int i = 0; i < 3; i++) {
new ProcessBuilder(createMavenArguments("verify")).directory(workingDirectory).start();
SystemTestUtils.buildMavenProcess(workingDirectory, "verify").start();
}
result = ProcessUtils
.execute(new ProcessBuilder(createMavenArguments("verify")).directory(workingDirectory));
// Get additional output for error debugging.
System.out.println(result.getStdout());
File configFile = new File(Paths.get(workingDirectory.getAbsolutePath(), "target", "tia", "agent.log").toUri());
String configContent = FileSystemUtils.readFile(configFile);
assertThat(configContent).isNotEmpty();
assertThat(result.terminatedByTimeoutOrInterruption()).isFalse();
assertThat(configContent).doesNotContain("Could not start http server on port");

// and one more that we wait for to terminate
SystemTestUtils.runMaven(workingDirectory, "verify");

Path configFile = Paths.get(workingDirectory, "target", "tia", "agent.log");
String configContent = FileSystemUtils.readFile(configFile.toFile());
assertThat(configContent).isNotEmpty().doesNotContain("Could not start http server on port");
}
}

0 comments on commit 9c98428

Please sign in to comment.