Skip to content

Commit

Permalink
Fix random test failures caused by dev server timeouts (#93)
Browse files Browse the repository at this point in the history
There were two instances of the dev server being created at the same
time by different tests tasks, causing one of the them to `pkill` both
instances.

This PR fixes that along with tracking the dev server process and
destroying it when tests are finish running.
  • Loading branch information
KiKoS0 authored Nov 6, 2024
1 parent 3b207b9 commit bdb3a11
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ public class DevServerComponent {
static String baseUrl = "http://127.0.0.1:8288";
OkHttpClient httpClient = new OkHttpClient();

Process devServerProcess;

DevServerComponent(CommHandler commHandler) throws Exception {
Runtime rt = Runtime.getRuntime();
rt.exec("pkill inngest-cli");
rt.exec("npx -y inngest-cli dev -u http://127.0.0.1:8080/api/inngest");
devServerProcess = rt.exec("npx -y inngest-cli@latest dev -u http://localhost:8080/api/inngest --port 8288 --no-discovery --no-poll --retry-interval 1");

waitForStartup(commHandler);
}
Expand All @@ -32,7 +33,7 @@ private void waitForStartup(CommHandler commHandler) throws Exception {

try (Response response = httpClient.newCall(request).execute()) {
if (response.code() == 200) {
Thread.sleep(3000);
Thread.sleep(6000);
commHandler.register("http://localhost:8080", null);
return;
}
Expand Down Expand Up @@ -102,8 +103,9 @@ private <T> T makeRequest(Request request, TypeReference<T> typeReference) throw


@PreDestroy
public void stop() throws Exception {
Runtime rt = Runtime.getRuntime();
rt.exec("pkill inngest-cli");
public void stop() {
if (devServerProcess != null && devServerProcess.isAlive()) {
devServerProcess.destroy();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import com.inngest.Version;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledIfSystemProperty;
import org.junit.jupiter.api.parallel.Execution;
import org.junit.jupiter.api.parallel.ExecutionMode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.context.annotation.Import;
Expand All @@ -12,15 +14,13 @@
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;

@Import(DemoTestConfiguration.class)
@WebMvcTest(DemoController.class)
@IntegrationTest
@Execution(ExecutionMode.CONCURRENT)
public class DevModeIntrospectionTest {

@Autowired
private MockMvc mockMvc;

@Test
@EnabledIfSystemProperty(named = "test-group", matches = "unit-test")
public void shouldReturnInsecureIntrospectPayload() throws Exception {
mockMvc.perform(get("/api/inngest").header("Host", "localhost:8080"))
.andExpect(status().isOk())
Expand Down

0 comments on commit bdb3a11

Please sign in to comment.