From 868a4c99d29cfc307d6520d3a7f7593235db23b9 Mon Sep 17 00:00:00 2001 From: Stuart Douglas Date: Tue, 15 Nov 2022 09:59:16 +1100 Subject: [PATCH] Compile application classes before test classes Fixes #28376 --- .../dev/RuntimeUpdatesProcessor.java | 2 +- .../ChangeSourceAndTestAtOnceTestCase.java | 64 +++++++++++++++++++ .../vertx/http/testrunner/CoupledET.java | 13 ++++ .../vertx/http/testrunner/CoupledService.java | 9 +++ .../io/quarkus/test/QuarkusDevModeTest.java | 12 ++++ 5 files changed, 99 insertions(+), 1 deletion(-) create mode 100644 extensions/vertx-http/deployment/src/test/java/io/quarkus/vertx/http/testrunner/ChangeSourceAndTestAtOnceTestCase.java create mode 100644 extensions/vertx-http/deployment/src/test/java/io/quarkus/vertx/http/testrunner/CoupledET.java create mode 100644 extensions/vertx-http/deployment/src/test/java/io/quarkus/vertx/http/testrunner/CoupledService.java diff --git a/core/deployment/src/main/java/io/quarkus/deployment/dev/RuntimeUpdatesProcessor.java b/core/deployment/src/main/java/io/quarkus/deployment/dev/RuntimeUpdatesProcessor.java index 3b869b5fadf93..1da4db6de658e 100644 --- a/core/deployment/src/main/java/io/quarkus/deployment/dev/RuntimeUpdatesProcessor.java +++ b/core/deployment/src/main/java/io/quarkus/deployment/dev/RuntimeUpdatesProcessor.java @@ -316,9 +316,9 @@ private void periodicTestCompile() { scanLock.lock(); TestScanningLock.lockForTests(); try { - ClassScanResult changedTestClassResult = compileTestClasses(); ClassScanResult changedApp = checkForChangedClasses(compiler, DevModeContext.ModuleInfo::getMain, false, test, true); + ClassScanResult changedTestClassResult = compileTestClasses(); if (changedApp.compilationHappened) { if (testCompileProblem != null) { testSupport.testCompileFailed(testCompileProblem); diff --git a/extensions/vertx-http/deployment/src/test/java/io/quarkus/vertx/http/testrunner/ChangeSourceAndTestAtOnceTestCase.java b/extensions/vertx-http/deployment/src/test/java/io/quarkus/vertx/http/testrunner/ChangeSourceAndTestAtOnceTestCase.java new file mode 100644 index 0000000000000..4612d7713c86f --- /dev/null +++ b/extensions/vertx-http/deployment/src/test/java/io/quarkus/vertx/http/testrunner/ChangeSourceAndTestAtOnceTestCase.java @@ -0,0 +1,64 @@ +package io.quarkus.vertx.http.testrunner; + +import java.util.function.Function; +import java.util.function.Supplier; + +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.asset.StringAsset; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.quarkus.dev.testing.TestScanningLock; +import io.quarkus.test.ContinuousTestingTestUtils; +import io.quarkus.test.ContinuousTestingTestUtils.TestStatus; +import io.quarkus.test.QuarkusDevModeTest; + +public class ChangeSourceAndTestAtOnceTestCase { + + @RegisterExtension + static QuarkusDevModeTest test = new QuarkusDevModeTest() + .setArchiveProducer(new Supplier<>() { + @Override + public JavaArchive get() { + return ShrinkWrap.create(JavaArchive.class).addClasses(CoupledService.class) + .add(new StringAsset(ContinuousTestingTestUtils.appProperties("quarkus.test.type=unit")), + "application.properties"); + } + }) + .setTestArchiveProducer(new Supplier<>() { + @Override + public JavaArchive get() { + return ShrinkWrap.create(JavaArchive.class).addClasses(CoupledET.class); + } + }); + + @Test + public void testChangeSourceAndTestAtOnce() throws InterruptedException { + ContinuousTestingTestUtils utils = new ContinuousTestingTestUtils(); + TestStatus ts = utils.waitForNextCompletion(); + Assertions.assertEquals(1L, ts.getTestsPassed()); + TestScanningLock.lockForTests(); + try { + test.modifySourceFile(CoupledService.class, new Function() { + @Override + public String apply(String s) { + return s.replace("service", "newService"); + } + }); + test.modifyTestSourceFile(CoupledET.class, new Function() { + @Override + public String apply(String s) { + return s.replace("service", "newService"); + } + }); + + } finally { + TestScanningLock.unlockForTests(); + } + ts = utils.waitForNextCompletion(); + Assertions.assertEquals(1L, ts.getTestsPassed()); + + } +} diff --git a/extensions/vertx-http/deployment/src/test/java/io/quarkus/vertx/http/testrunner/CoupledET.java b/extensions/vertx-http/deployment/src/test/java/io/quarkus/vertx/http/testrunner/CoupledET.java new file mode 100644 index 0000000000000..c723a5b3759f0 --- /dev/null +++ b/extensions/vertx-http/deployment/src/test/java/io/quarkus/vertx/http/testrunner/CoupledET.java @@ -0,0 +1,13 @@ +package io.quarkus.vertx.http.testrunner; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +public class CoupledET { + + @Test + public void unitStyleTest2() { + Assertions.assertEquals("unit", CoupledService.service()); + } + +} diff --git a/extensions/vertx-http/deployment/src/test/java/io/quarkus/vertx/http/testrunner/CoupledService.java b/extensions/vertx-http/deployment/src/test/java/io/quarkus/vertx/http/testrunner/CoupledService.java new file mode 100644 index 0000000000000..3dae85b2f39b6 --- /dev/null +++ b/extensions/vertx-http/deployment/src/test/java/io/quarkus/vertx/http/testrunner/CoupledService.java @@ -0,0 +1,9 @@ +package io.quarkus.vertx.http.testrunner; + +public class CoupledService { + + public static String service() { + return "unit"; + } + +} diff --git a/test-framework/junit5-internal/src/main/java/io/quarkus/test/QuarkusDevModeTest.java b/test-framework/junit5-internal/src/main/java/io/quarkus/test/QuarkusDevModeTest.java index f335aab4f106a..9a449d60c72f8 100644 --- a/test-framework/junit5-internal/src/main/java/io/quarkus/test/QuarkusDevModeTest.java +++ b/test-framework/junit5-internal/src/main/java/io/quarkus/test/QuarkusDevModeTest.java @@ -774,4 +774,16 @@ public QuarkusDevModeTest setAllowFailedStart(boolean allowFailedStart) { this.allowFailedStart = allowFailedStart; return this; } + + static class ChangeSet { + final String name; + final Function mutator; + final Path path; + + ChangeSet(String name, Function mutator, Path path) { + this.name = name; + this.mutator = mutator; + this.path = path; + } + } }