Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attempt to fix intermittent failure in SimpleContextPropagationTest caused by possible race condition #27284

Merged
merged 1 commit into from Aug 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -1,12 +1,15 @@
package io.quarkus.context.test;

import java.util.concurrent.CountDownLatch;

import javax.annotation.PreDestroy;
import javax.enterprise.context.RequestScoped;

@RequestScoped
public class RequestBean {

public static volatile int DESTROY_INVOKED = 0;
public static volatile CountDownLatch LATCH;

public String callMe() {
return "Hello " + System.identityHashCode(this);
Expand All @@ -15,5 +18,14 @@ public String callMe() {
@PreDestroy
public void destroy() {
DESTROY_INVOKED++;
// bean is also used in tests where there is no latch
if (LATCH != null) {
LATCH.countDown();
}
}

public static void initState() {
LATCH = new CountDownLatch(2);
DESTROY_INVOKED = 0;
}
}
Expand Up @@ -75,20 +75,22 @@ public void testArcTCContextPropagation() {
}

@Test()
public void testArcMEContextPropagationDisabled() {
public void testArcMEContextPropagationDisabled() throws InterruptedException {
// reset state
RequestBean.DESTROY_INVOKED = 0;
RequestBean.initState();
RestAssured.when().get("/context/noarc").then()
.statusCode(Response.Status.OK.getStatusCode());
Assertions.assertTrue(RequestBean.LATCH.await(3, TimeUnit.SECONDS));
Assertions.assertEquals(2, RequestBean.DESTROY_INVOKED);
}

@Test()
public void testArcTCContextPropagationDisabled() {
public void testArcTCContextPropagationDisabled() throws InterruptedException {
// reset state
RequestBean.DESTROY_INVOKED = 0;
RequestBean.initState();
RestAssured.when().get("/context/noarc-tc").then()
.statusCode(Response.Status.OK.getStatusCode());
Assertions.assertTrue(RequestBean.LATCH.await(3, TimeUnit.SECONDS));
Assertions.assertEquals(2, RequestBean.DESTROY_INVOKED);
}

Expand Down