improve SchedulerJobsTest.testDateFormat() by introducing Awaitility
This recently introduced new test (FINERACT-926) would locally pass, but then fail on the next run, because another test in the same class would modify job state to be inactive. It now sets the first jobs state as it requires it to be, and properly awaits the expected outcome.
This commit is contained in:
committed by
Michael Vorburger ⛑️
parent
f3b3ebc58c
commit
55af726cf9
@@ -114,7 +114,7 @@ dependencyManagement {
|
||||
dependency 'io.github.classgraph:classgraph:4.8.43'
|
||||
dependency 'org.dom4j:dom4j:2.1.0'
|
||||
dependency 'nekohtml:nekohtml:1.9.6.2'
|
||||
|
||||
dependency 'org.awaitility:awaitility:4.0.2'
|
||||
|
||||
dependencySet(group: 'com.sun.jersey', version: jerseyVersion) {
|
||||
entry 'jersey-core'
|
||||
|
||||
@@ -78,7 +78,7 @@ dependencies {
|
||||
exclude group: 'javax.validation'
|
||||
}
|
||||
implementation ('org.apache.activemq:activemq-broker') {
|
||||
exclude group: 'org.apache.geronimo.specs'
|
||||
exclude group: 'org.apache.geronimo.specs'
|
||||
}
|
||||
implementation ('org.springframework.boot:spring-boot-starter-data-jpa') {
|
||||
exclude group: 'org.hibernate'
|
||||
@@ -111,9 +111,10 @@ dependencies {
|
||||
// Do NOT repeat dependencies which are ALREADY in implementation or runtimeOnly!
|
||||
//
|
||||
testImplementation( 'junit:junit',
|
||||
'org.junit.platform:junit-platform-runner', // FINERACT-943
|
||||
'org.junit.platform:junit-platform-runner', // FINERACT-943
|
||||
'org.mockito:mockito-core',
|
||||
'io.github.classgraph:classgraph',
|
||||
'org.awaitility:awaitility'
|
||||
)
|
||||
testImplementation ('io.rest-assured:rest-assured') {
|
||||
exclude group: 'commons-logging'
|
||||
|
||||
+8
-7
@@ -18,6 +18,7 @@
|
||||
*/
|
||||
package org.apache.fineract.integrationtests;
|
||||
|
||||
import static org.awaitility.Awaitility.await;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
@@ -34,7 +35,6 @@ import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unchecked", "static-access" })
|
||||
public class SchedulerJobsTest {
|
||||
|
||||
private RequestSpecification requestSpec;
|
||||
@@ -51,9 +51,10 @@ public class SchedulerJobsTest {
|
||||
|
||||
@Test // FINERACT-926
|
||||
public void testDateFormat() {
|
||||
Map<String, Object> schedulerJob1 = schedulerJobHelper.getSchedulerJobById(1);
|
||||
String nextRunTimeText = (String)schedulerJob1.get("nextRunTime");
|
||||
assertNotNull("nextRunTime == null: " + schedulerJob1, nextRunTimeText);
|
||||
// must start scheduler and make job active to have nextRunTime (which is a java.util.Date)
|
||||
schedulerJobHelper.updateSchedulerStatus(true);
|
||||
schedulerJobHelper.updateSchedulerJob(1, "true");
|
||||
String nextRunTimeText = await().until(() -> (String)schedulerJobHelper.getSchedulerJobById(1).get("nextRunTime"), nextRunTime -> nextRunTime != null);
|
||||
DateTimeFormatter.ISO_INSTANT.parse(nextRunTimeText);
|
||||
}
|
||||
|
||||
@@ -62,12 +63,12 @@ public class SchedulerJobsTest {
|
||||
// Retrieving Status of Scheduler
|
||||
Boolean schedulerStatus = schedulerJobHelper.getSchedulerStatus();
|
||||
if (schedulerStatus == true) {
|
||||
schedulerJobHelper.updateSchedulerStatus("stop");
|
||||
schedulerJobHelper.updateSchedulerStatus(false);
|
||||
schedulerStatus = schedulerJobHelper.getSchedulerStatus();
|
||||
// Verifying Status of the Scheduler after stopping
|
||||
assertEquals("Verifying Scheduler Job Status", false, schedulerStatus);
|
||||
} else {
|
||||
schedulerJobHelper.updateSchedulerStatus("start");
|
||||
schedulerJobHelper.updateSchedulerStatus(true);
|
||||
schedulerStatus = schedulerJobHelper.getSchedulerStatus();
|
||||
// Verifying Status of the Scheduler after starting
|
||||
assertEquals("Verifying Scheduler Job Status", true, schedulerStatus);
|
||||
@@ -77,7 +78,7 @@ public class SchedulerJobsTest {
|
||||
@Test
|
||||
public void testFlippingJobsActiveStatus() throws InterruptedException {
|
||||
// Stop the Scheduler while we test flapping jobs' active on/off, to avoid side effects
|
||||
schedulerJobHelper.updateSchedulerStatus("stop");
|
||||
schedulerJobHelper.updateSchedulerStatus(false);
|
||||
|
||||
// For each retrieved scheduled job (by ID)...
|
||||
for (Integer jobId : schedulerJobHelper.getAllSchedulerJobIds()) {
|
||||
|
||||
+3
-1
@@ -67,6 +67,7 @@ public class SchedulerJobHelper {
|
||||
final String GET_SCHEDULER_JOB_BY_ID_URL = "/fineract-provider/api/v1/jobs/" + jobId + "?" + Utils.TENANT_IDENTIFIER;
|
||||
System.out.println("------------------------ RETRIEVING SCHEDULER JOB BY ID -------------------------");
|
||||
final Map<String, Object> response = Utils.performServerGet(requestSpec, response200Spec, GET_SCHEDULER_JOB_BY_ID_URL, "");
|
||||
System.out.println(response);
|
||||
assertNotNull(response);
|
||||
return response;
|
||||
}
|
||||
@@ -78,7 +79,8 @@ public class SchedulerJobHelper {
|
||||
return (Boolean) response.get("active");
|
||||
}
|
||||
|
||||
public void updateSchedulerStatus(final String command) {
|
||||
public void updateSchedulerStatus(final boolean on) {
|
||||
String command = on ? "start" : "stop";
|
||||
final String UPDATE_SCHEDULER_STATUS_URL = "/fineract-provider/api/v1/scheduler?command=" + command + "&" + Utils.TENANT_IDENTIFIER;
|
||||
System.out.println("------------------------ UPDATING SCHEDULER STATUS -------------------------");
|
||||
Utils.performServerPost(requestSpec, response202Spec, UPDATE_SCHEDULER_STATUS_URL, runSchedulerJobAsJSON(), null);
|
||||
|
||||
Reference in New Issue
Block a user