Skip to content

Commit

Permalink
Avoid using test groups for test ordering (#649)
Browse files Browse the repository at this point in the history
Test groups are global, not just for single test. This means that multiple
test classes may be "in progress" at the same time, which leads to issues
in at least one implementation which has global state.

Instead of test groups and `dependsOnGroups`, this commit uses simple
`dependsOnMethods`, which is local to the test class.
  • Loading branch information
Ladicek authored Oct 3, 2024
1 parent 9d5b14a commit 62b7b55
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ private CompletableFuture<Void> newWaitingFuture() {
return result;
}

@Test(groups = "main")
@Test
public void bulkheadMetricTest() throws InterruptedException, ExecutionException, TimeoutException {
TelemetryMetricGetter m = new TelemetryMetricGetter(BulkheadMetricBean.class, "waitFor");
m.baselineMetrics();
Expand Down Expand Up @@ -145,7 +145,7 @@ public void bulkheadMetricTest() throws InterruptedException, ExecutionException
is(0L));
}

@Test(groups = "main")
@Test
public void bulkheadMetricRejectionTest() throws InterruptedException, ExecutionException, TimeoutException {
TelemetryMetricGetter m = new TelemetryMetricGetter(BulkheadMetricBean.class, "waitFor");
m.baselineMetrics();
Expand Down Expand Up @@ -178,7 +178,7 @@ public void bulkheadMetricRejectionTest() throws InterruptedException, Execution

}

@Test(groups = "main")
@Test
public void bulkheadMetricHistogramTest() throws InterruptedException, ExecutionException, TimeoutException {
TelemetryMetricGetter m = new TelemetryMetricGetter(BulkheadMetricBean.class, "waitForHistogram");
m.baselineMetrics();
Expand Down Expand Up @@ -217,7 +217,7 @@ public void bulkheadMetricHistogramTest() throws InterruptedException, Execution
m.getBulkheadRunningDuration().assertBoundaries();
}

@Test(groups = "main")
@Test
public void bulkheadMetricAsyncTest() throws InterruptedException, ExecutionException, TimeoutException {
TelemetryMetricGetter m = new TelemetryMetricGetter(BulkheadMetricBean.class, "waitForAsync");
m.baselineMetrics();
Expand Down Expand Up @@ -265,7 +265,8 @@ public void bulkheadMetricAsyncTest() throws InterruptedException, ExecutionExce
is(1L));
}

@Test(dependsOnGroups = "main")
@Test(dependsOnMethods = {"bulkheadMetricTest", "bulkheadMetricRejectionTest", "bulkheadMetricHistogramTest",
"bulkheadMetricAsyncTest"})
public void testMetricUnits() throws InterruptedException, ExecutionException {
InMemoryMetricReader reader = InMemoryMetricReader.current();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public void closeTheCircuit() throws Exception {
}
}

@Test(groups = "main")
@Test
public void testCircuitBreakerMetric() throws Exception {
TelemetryMetricGetter m = new TelemetryMetricGetter(CircuitBreakerMetricBean.class, "doWork");

Expand Down Expand Up @@ -181,7 +181,7 @@ public void testCircuitBreakerMetric() throws Exception {
is(5L));
}

@Test(dependsOnGroups = "main")
@Test(dependsOnMethods = "testCircuitBreakerMetric")
public void testMetricUnits() throws InterruptedException, ExecutionException {
InMemoryMetricReader reader = InMemoryMetricReader.current();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public static WebArchive deploy() {
@Inject
private FallbackMetricBean fallbackBean;

@Test(groups = "main")
@Test
public void fallbackMetricMethodTest() {
TelemetryMetricGetter m = new TelemetryMetricGetter(FallbackMetricBean.class, "doWork");
m.baselineMetrics();
Expand Down Expand Up @@ -124,7 +124,7 @@ public void fallbackMetricMethodTest() {
is(1L));
}

@Test(groups = "main")
@Test
public void fallbackMetricHandlerTest() {
TelemetryMetricGetter m = new TelemetryMetricGetter(FallbackMetricBean.class, "doWorkWithHandler");
m.baselineMetrics();
Expand Down Expand Up @@ -177,7 +177,7 @@ public void fallbackMetricHandlerTest() {
is(1L));
}

@Test(dependsOnGroups = "main")
@Test(dependsOnMethods = {"fallbackMetricMethodTest", "fallbackMetricHandlerTest"})
public void testMetricUnits() throws InterruptedException, ExecutionException {
InMemoryMetricReader reader = InMemoryMetricReader.current();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public static WebArchive deploy() {
@Inject
private RetryMetricBean retryBean;

@Test(groups = "main")
@Test
public void testRetryMetricSuccessfulImmediately() {
TelemetryMetricGetter m = new TelemetryMetricGetter(RetryMetricBean.class, "failSeveralTimes");
m.baselineMetrics();
Expand All @@ -103,7 +103,7 @@ public void testRetryMetricSuccessfulImmediately() {
m.getInvocations(EXCEPTION_THROWN, InvocationFallback.NOT_DEFINED).delta(), is(0L));
}

@Test(groups = "main")
@Test
public void testRetryMetricSuccessfulAfterRetry() {
TelemetryMetricGetter m = new TelemetryMetricGetter(RetryMetricBean.class, "failSeveralTimes");
m.baselineMetrics();
Expand All @@ -119,7 +119,7 @@ public void testRetryMetricSuccessfulAfterRetry() {
m.getInvocations(EXCEPTION_THROWN, InvocationFallback.NOT_DEFINED).delta(), is(0L));
}

@Test(groups = "main")
@Test
public void testRetryMetricNonRetryableImmediately() {
TelemetryMetricGetter m = new TelemetryMetricGetter(RetryMetricBean.class, "failSeveralTimesThenNonRetryable");
m.baselineMetrics();
Expand All @@ -137,7 +137,7 @@ public void testRetryMetricNonRetryableImmediately() {
m.getInvocations(EXCEPTION_THROWN, InvocationFallback.NOT_DEFINED).delta(), is(1L));
}

@Test(groups = "main")
@Test
public void testRetryMetricNonRetryableAfterRetries() {
TelemetryMetricGetter m = new TelemetryMetricGetter(RetryMetricBean.class, "failSeveralTimesThenNonRetryable");
m.baselineMetrics();
Expand All @@ -155,7 +155,7 @@ public void testRetryMetricNonRetryableAfterRetries() {
m.getInvocations(EXCEPTION_THROWN, InvocationFallback.NOT_DEFINED).delta(), is(1L));
}

@Test(groups = "main")
@Test
public void testRetryMetricMaxRetries() {
TelemetryMetricGetter m = new TelemetryMetricGetter(RetryMetricBean.class, "failSeveralTimes");
m.baselineMetrics();
Expand All @@ -172,7 +172,7 @@ public void testRetryMetricMaxRetries() {
m.getInvocations(EXCEPTION_THROWN, InvocationFallback.NOT_DEFINED).delta(), is(2L));
}

@Test(groups = "main")
@Test
public void testRetryMetricMaxRetriesHitButNoRetry() {
// This is an edge case which can only occur when maxRetries = 0
TelemetryMetricGetter m = new TelemetryMetricGetter(RetryMetricBean.class, "maxRetriesZero");
Expand All @@ -189,7 +189,7 @@ public void testRetryMetricMaxRetriesHitButNoRetry() {
m.getInvocations(EXCEPTION_THROWN, InvocationFallback.NOT_DEFINED).delta(), is(1L));
}

@Test(groups = "main")
@Test
public void testRetryMetricMaxDuration() {
TelemetryMetricGetter m = new TelemetryMetricGetter(RetryMetricBean.class, "failAfterDelay");
m.baselineMetrics();
Expand All @@ -206,7 +206,7 @@ public void testRetryMetricMaxDuration() {
m.getInvocations(EXCEPTION_THROWN, InvocationFallback.NOT_DEFINED).delta(), is(1L));
}

@Test(groups = "main")
@Test
public void testRetryMetricMaxDurationNoRetries() {
TelemetryMetricGetter m = new TelemetryMetricGetter(RetryMetricBean.class, "failAfterDelay");
m.baselineMetrics();
Expand All @@ -224,7 +224,10 @@ public void testRetryMetricMaxDurationNoRetries() {
m.getInvocations(EXCEPTION_THROWN, InvocationFallback.NOT_DEFINED).delta(), is(1L));
}

@Test(dependsOnGroups = "main")
@Test(dependsOnMethods = {"testRetryMetricSuccessfulImmediately", "testRetryMetricSuccessfulAfterRetry",
"testRetryMetricNonRetryableImmediately", "testRetryMetricNonRetryableAfterRetries",
"testRetryMetricMaxRetries", "testRetryMetricMaxRetriesHitButNoRetry", "testRetryMetricMaxDuration",
"testRetryMetricMaxDurationNoRetries"})
public void testMetricUnits() throws InterruptedException, ExecutionException {
InMemoryMetricReader reader = InMemoryMetricReader.current();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public static WebArchive deploy() {
@Inject
private TimeoutMetricBean timeoutBean;

@Test(groups = "main")
@Test
public void testTimeoutMetric() {
TelemetryMetricGetter m = new TelemetryMetricGetter(TimeoutMetricBean.class, "counterTestWorkForMillis");
m.baselineMetrics();
Expand All @@ -104,7 +104,7 @@ public void testTimeoutMetric() {
is(2L));
}

@Test(groups = "main")
@Test
public void testTimeoutHistogram() {
TelemetryMetricGetter m = new TelemetryMetricGetter(TimeoutMetricBean.class, "histogramTestWorkForMillis");

Expand All @@ -117,7 +117,7 @@ public void testTimeoutHistogram() {
m.getTimeoutExecutionDuration().assertBoundaries();
}

@Test(dependsOnGroups = "main")
@Test(dependsOnMethods = {"testTimeoutMetric", "testTimeoutHistogram"})
public void testMetricUnits() throws InterruptedException, ExecutionException {
InMemoryMetricReader reader = InMemoryMetricReader.current();

Expand Down

0 comments on commit 62b7b55

Please sign in to comment.