Skip to content

Commit

Permalink
adaptertest: Standardise allowed time deviations (#67)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewwormald authored Jan 7, 2025
1 parent b2c0390 commit 40c8758
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 11 deletions.
58 changes: 50 additions & 8 deletions adapters/adaptertest/recordstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,14 @@ func testList(t *testing.T, factory func() workflow.RecordStore) {
}

for status, count := range config {
ls, err := store.List(ctx, workflowName, 0, 100, workflow.OrderTypeAscending, workflow.FilterByStatus(int64(status)))
ls, err := store.List(
ctx,
workflowName,
0,
100,
workflow.OrderTypeAscending,
workflow.FilterByStatus(int64(status)),
)
require.Nil(t, err)
require.Equal(t, count, len(ls))

Expand All @@ -255,15 +262,36 @@ func testList(t *testing.T, factory func() workflow.RecordStore) {
}
}

ls, err := store.List(ctx, workflowName, 0, 100, workflow.OrderTypeAscending, workflow.FilterByForeignID(foreignIDs[0]))
ls, err := store.List(
ctx,
workflowName,
0,
100,
workflow.OrderTypeAscending,
workflow.FilterByForeignID(foreignIDs[0]),
)
require.Nil(t, err)
require.Equal(t, 20, len(ls))

ls2, err := store.List(ctx, workflowName, 0, 100, workflow.OrderTypeAscending, workflow.FilterByForeignID(foreignIDs[1]))
ls2, err := store.List(
ctx,
workflowName,
0,
100,
workflow.OrderTypeAscending,
workflow.FilterByForeignID(foreignIDs[1]),
)
require.Nil(t, err)
require.Equal(t, 20, len(ls2))

ls3, err := store.List(ctx, workflowName, 0, 100, workflow.OrderTypeAscending, workflow.FilterByForeignID("random"))
ls3, err := store.List(
ctx,
workflowName,
0,
100,
workflow.OrderTypeAscending,
workflow.FilterByForeignID("random"),
)
require.Nil(t, err)
require.Equal(t, 0, len(ls3))
})
Expand All @@ -290,7 +318,14 @@ func testList(t *testing.T, factory func() workflow.RecordStore) {
}

for runState, count := range config {
ls, err := store.List(ctx, workflowName, 0, 100, workflow.OrderTypeAscending, workflow.FilterByRunState(runState))
ls, err := store.List(
ctx,
workflowName,
0,
100,
workflow.OrderTypeAscending,
workflow.FilterByRunState(runState),
)
require.Nil(t, err)
require.Equal(t, count, len(ls), fmt.Sprintf("Expected to have %v entries of %v", count, runState.String()))

Expand Down Expand Up @@ -319,7 +354,14 @@ func testList(t *testing.T, factory func() workflow.RecordStore) {
}

for status, count := range config {
ls, err := store.List(ctx, workflowName, 0, 100, workflow.OrderTypeAscending, workflow.FilterByStatus(int64(status)))
ls, err := store.List(
ctx,
workflowName,
0,
100,
workflow.OrderTypeAscending,
workflow.FilterByStatus(int64(status)),
)
require.Nil(t, err)
require.Equal(t, count, len(ls))

Expand Down Expand Up @@ -364,6 +406,6 @@ func recordIsEqual(t *testing.T, a, b workflow.Record) {
require.Equal(t, a.Status, b.Status)
require.Equal(t, a.Object, b.Object)
require.Equal(t, a.RunState, b.RunState)
require.WithinDuration(t, a.CreatedAt, b.CreatedAt, time.Second*10)
require.WithinDuration(t, a.UpdatedAt, b.UpdatedAt, time.Second*10)
require.WithinDuration(t, a.CreatedAt, b.CreatedAt, allowedTimeDeviation)
require.WithinDuration(t, a.UpdatedAt, b.UpdatedAt, allowedTimeDeviation)
}
13 changes: 10 additions & 3 deletions adapters/adaptertest/timeoutstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,14 @@ func testCompleteAndCancelTimeout(t *testing.T, factory func() workflow.TimeoutS
func seed(t *testing.T, store workflow.TimeoutStore, count int) {
ctx := context.Background()
for i := range count {
err := store.Create(ctx, "example", "andrew", fmt.Sprintf("%v", i+1), int(statusStarted), time.Now().Add(-time.Hour))
err := store.Create(
ctx,
"example",
"andrew",
fmt.Sprintf("%v", i+1),
int(statusStarted),
time.Now().Add(-time.Hour),
)
require.Nil(t, err)
}
}
Expand All @@ -60,8 +67,8 @@ func expect(t *testing.T, count int, actual []workflow.TimeoutRecord) {
require.Equal(t, "andrew", timeout.ForeignID)
require.Equal(t, fmt.Sprintf("%v", i+1), timeout.RunID)
require.False(t, timeout.Completed)
require.WithinDuration(t, time.Now().Add(-time.Hour), timeout.ExpireAt, time.Second)
require.WithinDuration(t, time.Now(), timeout.CreatedAt, time.Second)
require.WithinDuration(t, time.Now().Add(-time.Hour), timeout.ExpireAt, allowedTimeDeviation)
require.WithinDuration(t, time.Now(), timeout.CreatedAt, allowedTimeDeviation)
}
}

Expand Down
4 changes: 4 additions & 0 deletions adapters/adaptertest/util.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package adaptertest

import "time"

const allowedTimeDeviation = time.Second * 10

type status int

const (
Expand Down

0 comments on commit 40c8758

Please sign in to comment.