Skip to content

Commit

Permalink
#30545 Improving tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jgambarios committed Dec 10, 2024
1 parent fd919aa commit 1b34000
Showing 1 changed file with 26 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import javax.inject.Inject;
import org.awaitility.Awaitility;
import org.jboss.weld.junit5.EnableWeld;
import org.junit.Ignore;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
Expand Down Expand Up @@ -398,10 +397,13 @@ void test_CombinedScenarios() throws Exception {
String successJob1Id = jobQueueManagerAPI.createJob("successQueue", new HashMap<>());
String successJob2Id = jobQueueManagerAPI.createJob("successQueue", new HashMap<>());
String failJobId = jobQueueManagerAPI.createJob("failQueue", new HashMap<>());
String cancelJobId = jobQueueManagerAPI.createJob("cancelQueue", new HashMap<>());
String cancelJob1Id = jobQueueManagerAPI.createJob("cancelQueue", new HashMap<>());
String cancelJob2Id = jobQueueManagerAPI.createJob("cancelQueue",
Map.of("wontCancel", true)
);

// Set up latches to track job completions
CountDownLatch successLatch = new CountDownLatch(2);
CountDownLatch successLatch = new CountDownLatch(3);
CountDownLatch failLatch = new CountDownLatch(1);
CountDownLatch cancelLatch = new CountDownLatch(1);

Expand All @@ -421,15 +423,20 @@ void test_CombinedScenarios() throws Exception {
failLatch.countDown();
}
});
jobQueueManagerAPI.watchJob(cancelJobId, job -> {
jobQueueManagerAPI.watchJob(cancelJob1Id, job -> {
if (job.state() == JobState.CANCELED) {
cancelLatch.countDown();
}
});
jobQueueManagerAPI.watchJob(cancelJob2Id, job -> {
if (job.state() == JobState.SUCCESS) {
successLatch.countDown();
}
});

// Wait a bit before cancelling the job
// Wait a bit before cancelling the job, just cancelJob1Id
Awaitility.await().pollDelay(500, TimeUnit.MILLISECONDS).until(() -> true);
jobQueueManagerAPI.cancelJob(cancelJobId);
jobQueueManagerAPI.cancelJob(cancelJob1Id);

// Wait for all jobs to complete (or timeout after 30 seconds)
boolean allCompleted = successLatch.await(30, TimeUnit.SECONDS)
Expand All @@ -445,8 +452,10 @@ void test_CombinedScenarios() throws Exception {
"Second success job should be successful");
assertEquals(JobState.FAILED_PERMANENTLY, jobQueueManagerAPI.getJob(failJobId).state(),
"Fail job should be in failed state");
assertEquals(JobState.CANCELED, jobQueueManagerAPI.getJob(cancelJobId).state(),
"Cancel job should be canceled");
assertEquals(JobState.CANCELED, jobQueueManagerAPI.getJob(cancelJob1Id).state(),
"Cancel job 1 should be canceled");
assertEquals(JobState.SUCCESS, jobQueueManagerAPI.getJob(cancelJob2Id).state(),
"Cancel job 2 should be successful");

// Wait for job processing to complete as we have retries running
Awaitility.await().atMost(30, TimeUnit.SECONDS)
Expand Down Expand Up @@ -768,11 +777,16 @@ static class CancellableJobProcessor implements JobProcessor, Cancellable {
@Override
public void process(Job job) {

Awaitility.await().atMost(10, TimeUnit.SECONDS)
.until(canceled::get);
if (job.parameters().containsKey("wontCancel")) {
// Simulate some work
Awaitility.await().pollDelay(5, TimeUnit.SECONDS).until(() -> true);
} else {
Awaitility.await().atMost(10, TimeUnit.SECONDS)
.until(canceled::get);

// Simulate some additional work after cancellation
Awaitility.await().pollDelay(1, TimeUnit.SECONDS).until(() -> true);
// Simulate some additional work after cancellation
Awaitility.await().pollDelay(1, TimeUnit.SECONDS).until(() -> true);
}
}

@Override
Expand Down

0 comments on commit 1b34000

Please sign in to comment.