Skip to content

Commit

Permalink
Change < to <= in instance polling condition 'next_activation <= curr…
Browse files Browse the repository at this point in the history
…ent_timestamp'
  • Loading branch information
eputtone committed Mar 5, 2016
1 parent cdc8ad7 commit a94becd
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ String updateInstanceForExecutionQuery() {

String whereConditionForInstanceUpdate() {
return "where executor_id is null and status in (" + sqlVariants.workflowStatus(created) + ", "
+ sqlVariants.workflowStatus(inProgress) + ") and next_activation < current_timestamp and "
+ sqlVariants.workflowStatus(inProgress) + ") and next_activation <= current_timestamp and "
+ executorInfo.getExecutorGroupCondition() + " order by next_activation asc";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ public void updateWorkflowInstance() throws InterruptedException {
WorkflowInstance i1 = constructWorkflowInstanceBuilder().setStatus(created).build();
int id = dao.insertWorkflowInstance(i1);
List<Integer> ids = dao.pollNextWorkflowInstanceIds(1);
// FIXME this assert fails randomly. due to race condition?
assertThat(ids, contains(id));
final WorkflowInstance i2 = new WorkflowInstance.Builder(dao.getWorkflowInstance(id)).setStatus(inProgress)
.setState("updateState").setStateText("update text").build();
Expand Down Expand Up @@ -478,7 +477,7 @@ public void fakePostgreSQLpollNextWorkflowInstances() {
when(j.queryForList(sql.capture(), eq(Integer.class))).thenReturn(asList(1, 2, 3));
assertThat(d.pollNextWorkflowInstanceIds(5), is(asList(1, 2, 3)));
assertEquals(
"update nflow_workflow set executor_id = 42, status = 'executing'::workflow_status, external_next_activation = null where id in (select id from nflow_workflow where executor_id is null and status in ('created'::workflow_status, 'inProgress'::workflow_status) and next_activation < current_timestamp and group matches order by next_activation asc limit 5) and executor_id is null returning id",
"update nflow_workflow set executor_id = 42, status = 'executing'::workflow_status, external_next_activation = null where id in (select id from nflow_workflow where executor_id is null and status in ('created'::workflow_status, 'inProgress'::workflow_status) and next_activation <= current_timestamp and group matches order by next_activation asc limit 5) and executor_id is null returning id",
sql.getValue());
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.nitorcreations.nflow.tests;

import static java.lang.Thread.sleep;
import static java.util.concurrent.TimeUnit.SECONDS;
import static org.apache.cxf.jaxrs.client.WebClient.fromClient;
import static org.hamcrest.Matchers.notNullValue;
import static org.junit.Assert.assertEquals;
Expand Down Expand Up @@ -51,15 +53,19 @@ public void t00_cleanupExistingArchivableStuff() {
}

@Test(timeout = CREATE_TIMEOUT)
public void t01_createWorkflows() {
public void t01_createWorkflows() throws InterruptedException {
waitUntilWorkflowsFinished(createWorkflows(STEP_1_WORKFLOWS));
archiveLimit1 = DateTime.now();
// Make sure first batch of workflows is created before the second batch.
// (some databases have 1 second precision in timestamps (e.g. mysql 5.5))
sleep(SECONDS.toMillis(1));
}

@Test(timeout = CREATE_TIMEOUT)
public void t02_createMoreWorkflows() {
public void t02_createMoreWorkflows() throws InterruptedException {
waitUntilWorkflowsFinished(createWorkflows(STEP_2_WORKFLOWS));
archiveLimit2 = DateTime.now();
sleep(SECONDS.toMillis(1));
}

@Test(timeout = ARCHIVE_TIMEOUT)
Expand Down

0 comments on commit a94becd

Please sign in to comment.