Skip to content

Commit

Permalink
Merge pull request #17573 from stuartwdouglas/17557
Browse files Browse the repository at this point in the history
Continuous tests may not run for unit tests
  • Loading branch information
stuartwdouglas authored Jun 1, 2021
2 parents 535f4db + b26a5a0 commit e4760ee
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ public String apply(Class<?> aClass) {
ClassWriter writer = new QuarkusClassWriter(cr,
ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
cr.accept(new TestTracingProcessor.TracingClassVisitor(writer, i), 0);
transformedClasses.put(i, writer.toByteArray());
transformedClasses.put(i.replace(".", "/") + ".class", writer.toByteArray());
} catch (IOException e) {
throw new RuntimeException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ public class BasicConsole extends QuarkusConsole {
private static final Logger log = Logger.getLogger(BasicConsole.class.getName());
private static final Logger statusLogger = Logger.getLogger("quarkus");

private static final ThreadLocal<Boolean> DISABLE_FILTER = new ThreadLocal<>() {
@Override
protected Boolean initialValue() {
return false;
}
};
final PrintStream printStream;
final boolean inputSupport;
final boolean noColor;
Expand Down Expand Up @@ -57,15 +63,25 @@ protected void setPromptMessage(String prompt) {
if (prompt == null) {
return;
}
statusLogger.info(prompt);
DISABLE_FILTER.set(true);
try {
statusLogger.info(prompt);
} finally {
DISABLE_FILTER.set(false);
}
}

@Override
protected void setStatusMessage(String status) {
if (status == null) {
return;
}
statusLogger.info(status);
DISABLE_FILTER.set(true);
try {
statusLogger.info(status);
} finally {
DISABLE_FILTER.set(false);
}
}
};
}
Expand All @@ -74,7 +90,10 @@ protected void setStatusMessage(String status) {
public void write(String s) {
if (outputFilter != null) {
if (!outputFilter.test(s)) {
return;
//we still test, the output filter may be recording output
if (!DISABLE_FILTER.get()) {
return;
}
}
}
if (noColor || !hasColorSupport()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class QuarkusTestTypeTestCase {
.setArchiveProducer(new Supplier<JavaArchive>() {
@Override
public JavaArchive get() {
return ShrinkWrap.create(JavaArchive.class).addClass(HelloResource.class)
return ShrinkWrap.create(JavaArchive.class).addClasses(HelloResource.class, UnitService.class)
.add(new StringAsset(ContinuousTestingTestUtils.appProperties("quarkus.test.type=quarkus-test")),
"application.properties");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class TestRunnerSmokeTestCase {
.setArchiveProducer(new Supplier<JavaArchive>() {
@Override
public JavaArchive get() {
return ShrinkWrap.create(JavaArchive.class).addClass(HelloResource.class)
return ShrinkWrap.create(JavaArchive.class).addClasses(HelloResource.class, UnitService.class)
.add(new StringAsset(ContinuousTestingTestUtils.appProperties()),
"application.properties");
}
Expand All @@ -39,10 +39,10 @@ public JavaArchive get() {
public void checkTestsAreRun() throws InterruptedException {
TestStatus ts = ContinuousTestingTestUtils.waitForFirstRunToComplete();
Assertions.assertEquals(1L, ts.getLastRun());
Assertions.assertEquals(2L, ts.getTestsFailed());
Assertions.assertEquals(3L, ts.getTestsFailed());
Assertions.assertEquals(1L, ts.getTestsPassed());
Assertions.assertEquals(0L, ts.getTestsSkipped());
Assertions.assertEquals(2L, ts.getTotalTestsFailed());
Assertions.assertEquals(3L, ts.getTotalTestsFailed());
Assertions.assertEquals(1L, ts.getTotalTestsPassed());
Assertions.assertEquals(0L, ts.getTotalTestsSkipped());
Assertions.assertEquals(-1L, ts.getRunning());
Expand All @@ -55,7 +55,7 @@ public void checkTestsAreRun() throws InterruptedException {
Assertions.assertEquals(1, cr.getFailing().size());
Assertions.assertEquals(1, cr.getPassing().size());
} else if (cr.getClassName().equals(UnitET.class.getName())) {
Assertions.assertEquals(1, cr.getFailing().size());
Assertions.assertEquals(2, cr.getFailing().size());
Assertions.assertEquals(0, cr.getPassing().size());
} else {
Assertions.fail("Unexpected test " + cr.getClassName());
Expand All @@ -71,58 +71,74 @@ public String apply(String s) {
});
ts = ContinuousTestingTestUtils.waitForRun(2);
Assertions.assertEquals(2L, ts.getLastRun());
Assertions.assertEquals(1L, ts.getTestsFailed());
Assertions.assertEquals(2L, ts.getTestsFailed());
Assertions.assertEquals(2L, ts.getTestsPassed());
Assertions.assertEquals(0L, ts.getTestsSkipped());
Assertions.assertEquals(1L, ts.getTotalTestsFailed());
Assertions.assertEquals(2L, ts.getTotalTestsFailed());
Assertions.assertEquals(2L, ts.getTotalTestsPassed());
Assertions.assertEquals(0L, ts.getTotalTestsSkipped());
Assertions.assertEquals(-1L, ts.getRunning());

//fix the unit test

test.modifyTestSourceFile(UnitET.class, new Function<String, String>() {
test.modifySourceFile(UnitService.class, new Function<String, String>() {
@Override
public String apply(String s) {
return s.replace("Hi", "hello");
return s.replace("unit", "UNIT");
}
});
ts = ContinuousTestingTestUtils.waitForRun(3);
Assertions.assertEquals(3L, ts.getLastRun());
Assertions.assertEquals(0L, ts.getTestsFailed());
Assertions.assertEquals(1L, ts.getTestsFailed());
Assertions.assertEquals(1L, ts.getTestsPassed());
Assertions.assertEquals(0L, ts.getTestsSkipped());
Assertions.assertEquals(0L, ts.getTotalTestsFailed());
Assertions.assertEquals(1L, ts.getTotalTestsFailed());
Assertions.assertEquals(3L, ts.getTotalTestsPassed());
Assertions.assertEquals(0L, ts.getTotalTestsSkipped());
Assertions.assertEquals(-1L, ts.getRunning());

//disable the unit test
test.modifyTestSourceFile(UnitET.class, new Function<String, String>() {
@Override
public String apply(String s) {
return s.replace("@Test", "@Test @org.junit.jupiter.api.Disabled");
return s.replace("Hi", "hello");
}
});
ts = ContinuousTestingTestUtils.waitForRun(4);
Assertions.assertEquals(4L, ts.getLastRun());
Assertions.assertEquals(0L, ts.getTestsFailed());
Assertions.assertEquals(2L, ts.getTestsPassed());
Assertions.assertEquals(0L, ts.getTestsSkipped());
Assertions.assertEquals(0L, ts.getTotalTestsFailed());
Assertions.assertEquals(4L, ts.getTotalTestsPassed());
Assertions.assertEquals(0L, ts.getTotalTestsSkipped());
Assertions.assertEquals(-1L, ts.getRunning());

//disable the unit test
test.modifyTestSourceFile(UnitET.class, new Function<String, String>() {
@Override
public String apply(String s) {
return s.replaceAll("@Test", "@Test @org.junit.jupiter.api.Disabled");
}
});
ts = ContinuousTestingTestUtils.waitForRun(5);
Assertions.assertEquals(5L, ts.getLastRun());
Assertions.assertEquals(0L, ts.getTestsFailed());
Assertions.assertEquals(0L, ts.getTestsPassed());
Assertions.assertEquals(1L, ts.getTestsSkipped());
Assertions.assertEquals(2L, ts.getTestsSkipped());
Assertions.assertEquals(0L, ts.getTotalTestsFailed());
Assertions.assertEquals(2L, ts.getTotalTestsPassed());
Assertions.assertEquals(1L, ts.getTotalTestsSkipped());
Assertions.assertEquals(2L, ts.getTotalTestsSkipped());
Assertions.assertEquals(-1L, ts.getRunning());

//delete the unit test
test.modifyTestSourceFile(UnitET.class, new Function<String, String>() {
@Override
public String apply(String s) {
return s.replace("@Test", "//@Test");
return s.replaceAll("@Test", "//@Test");
}
});
ts = ContinuousTestingTestUtils.waitForRun(5);
Assertions.assertEquals(5L, ts.getLastRun());
ts = ContinuousTestingTestUtils.waitForRun(6);
Assertions.assertEquals(6L, ts.getLastRun());
Assertions.assertEquals(0L, ts.getTestsFailed());
Assertions.assertEquals(0L, ts.getTestsPassed());
Assertions.assertEquals(0L, ts.getTestsSkipped());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@

public class UnitET {

@Test
public void unitStyleTest2() {
Assertions.assertEquals("UNIT", UnitService.service());
}

@Test
public void unitStyleTest() {
HelloResource res = new HelloResource();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package io.quarkus.vertx.http.testrunner;

public class UnitService {

public static String service() {
return "unit";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class UnitTestTypeTestCase {
.setArchiveProducer(new Supplier<JavaArchive>() {
@Override
public JavaArchive get() {
return ShrinkWrap.create(JavaArchive.class).addClass(HelloResource.class)
return ShrinkWrap.create(JavaArchive.class).addClasses(HelloResource.class, UnitService.class)
.add(new StringAsset(ContinuousTestingTestUtils.appProperties("quarkus.test.type=unit")),
"application.properties");
}
Expand All @@ -35,7 +35,7 @@ public JavaArchive get() {
public void testUnitMode() throws InterruptedException {
TestStatus ts = ContinuousTestingTestUtils.waitForFirstRunToComplete();
Assertions.assertEquals(1L, ts.getLastRun());
Assertions.assertEquals(1L, ts.getTestsFailed());
Assertions.assertEquals(2L, ts.getTestsFailed());
Assertions.assertEquals(0L, ts.getTestsPassed());
Assertions.assertEquals(0L, ts.getTestsSkipped());
Assertions.assertEquals(-1L, ts.getRunning());
Expand Down

0 comments on commit e4760ee

Please sign in to comment.