Skip to content

Commit

Permalink
Improve racy test
Browse files Browse the repository at this point in the history
  • Loading branch information
vietj committed Jan 31, 2025
1 parent a92e76f commit dacd689
Showing 1 changed file with 11 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

import io.vertx.core.*;
import io.vertx.core.impl.VertxThread;
import io.vertx.test.core.Repeat;
import io.vertx.test.core.TestUtils;
import io.vertx.test.core.VertxTestBase;
import org.junit.Test;
Expand Down Expand Up @@ -128,7 +127,6 @@ public void testUnordered() throws Exception {
await();
}

@Repeat(times = 1000)
@Test
public void testUseDifferentExecutorWithSameTaskQueue() {
int count = 10;
Expand Down Expand Up @@ -280,29 +278,30 @@ public void start() throws Exception {
}

@Test
public void testDeployUsingNamedPool() {
AtomicReference<Thread> thread = new AtomicReference<>();
public void testDeployUsingNamedPool() throws Exception {
String poolName = "vert.x-" + TestUtils.randomAlphaString(10);
Promise<Void> undeployed = Promise.promise();
Promise<Thread> promise = Promise.promise();
vertx.deployVerticle(new AbstractVerticle() {
@Override
public void start() {
vertx.runOnContext(v1 -> {
vertx.executeBlocking(() -> {
thread.set(Thread.currentThread());
Thread current = Thread.currentThread();
assertTrue(Context.isOnVertxThread());
assertTrue(Context.isOnWorkerThread());
assertFalse(Context.isOnEventLoopThread());
assertTrue(Thread.currentThread().getName().startsWith(poolName + "-"));
return null;
}).onComplete(onSuccess(v2 -> {
vertx.undeploy(context.deploymentID()).onComplete(undeployed);
assertTrue(current.getName().startsWith(poolName + "-"));
return current;
}).onComplete(onSuccess(current -> {
vertx.undeploy(context.deploymentID()).onComplete(onSuccess(v2 -> {
promise.complete(current);
}));
}));
});
}
}, new DeploymentOptions().setWorkerPoolName(poolName));
assertWaitUntil(() -> thread.get() != null);
assertWaitUntil(() -> thread.get().getState() == Thread.State.TERMINATED, 10000, "Unexpected thread state " + thread.get().getState());
Thread thread = promise.future().await(20, SECONDS);
assertWaitUntil(() -> thread.getState() == Thread.State.TERMINATED, 20_000, "Unexpected thread state " + thread.getState());
}

@Test
Expand Down

0 comments on commit dacd689

Please sign in to comment.