Skip to content

Commit 6128414

Browse files
authored
[Fix #2192] OutputBuffer.writeInstant writes seconds rather than millis (#1293)
Signed-off-by: fjtirado <ftirados@redhat.com>
1 parent 062e4c1 commit 6128414

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

impl/core/src/main/java/io/serverlessworkflow/impl/marshaller/AbstractOutputBuffer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ protected AbstractOutputBuffer(Collection<CustomObjectMarshaller> customMarshall
3131

3232
@Override
3333
public WorkflowOutputBuffer writeInstant(Instant instant) {
34-
writeLong(instant.getEpochSecond());
34+
writeLong(instant.toEpochMilli());
3535
return this;
3636
}
3737

impl/persistence/tests/src/main/java/io/serverlessworkflow/impl/persistence/test/AbstractHandlerPersistenceTest.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import io.serverlessworkflow.impl.persistence.PersistenceInstanceHandlers;
3737
import io.serverlessworkflow.impl.persistence.WorkflowPersistenceInstance;
3838
import java.io.IOException;
39+
import java.time.Duration;
3940
import java.time.Instant;
4041
import java.util.Map;
4142
import java.util.Optional;
@@ -55,6 +56,7 @@ public abstract class AbstractHandlerPersistenceTest {
5556
protected WorkflowModel context;
5657
protected WorkflowInstanceData workflowInstance;
5758
protected WorkflowContextData workflowContext;
59+
private Instant beforeStart;
5860

5961
@BeforeAll()
6062
static void init() throws IOException {
@@ -64,14 +66,15 @@ static void init() throws IOException {
6466

6567
@BeforeEach
6668
void setup() {
69+
beforeStart = Instant.now();
6770
handlers = getPersistenceHandlers();
6871
context = app.modelFactory().fromNull();
6972
workflowContext = mock(WorkflowContext.class);
7073
workflowInstance = mock(WorkflowInstance.class);
7174
when(workflowContext.context()).thenReturn(context);
7275
when(workflowContext.definition()).thenReturn(definition);
7376
when(workflowContext.instanceData()).thenReturn(workflowInstance);
74-
when(workflowInstance.startedAt()).thenReturn(Instant.now());
77+
when(workflowInstance.startedAt()).thenReturn(beforeStart.plus(Duration.ofMillis(1)));
7578
when(workflowInstance.context()).thenReturn(context);
7679
when(workflowInstance.id()).thenReturn(app.idFactory().get());
7780
when(workflowInstance.input()).thenReturn(app.modelFactory().from(Map.of("name", "Javierito")));
@@ -127,7 +130,10 @@ void testWorkflowInstance() throws InterruptedException {
127130
assertThat(optional).isPresent();
128131
WorkflowPersistenceInstance instance = (WorkflowPersistenceInstance) optional.orElseThrow();
129132
assertThat(instance.input().asMap().orElseThrow()).isEqualTo(Map.of("name", "Javierito"));
130-
assertThat(instance.startedAt()).isNotNull().isBefore(Instant.now());
133+
assertThat(instance.startedAt())
134+
.isNotNull()
135+
.isBefore(Instant.now())
136+
.isAfterOrEqualTo(beforeStart);
131137

132138
// task retry
133139
WorkflowContext updateWContext = mock(WorkflowContext.class);

0 commit comments

Comments
 (0)