Skip to content

Commit 30ca74c

Browse files
committed
fix: tests + cleanup
1 parent 26bf7cf commit 30ca74c

2 files changed

Lines changed: 26 additions & 25 deletions

File tree

‎pkg/repository/durable_events.go‎

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -683,19 +683,16 @@ func nonDeterminismDetail(opts IngestDurableTaskEventOpts, expectedKind sqlcv1.V
683683
}
684684

685685
type GetOrCreateLogEntryOpt struct {
686-
Kind sqlcv1.V1DurableEventLogKind
687-
IdempotencyKey []byte
688-
InputPayload []byte
689-
ResultPayload []byte
690-
NodeId int64
691-
BranchId int64
692-
IsSatisfied bool
693-
UserMessage *string
694-
WaitData string // JSON-encoded WaitData, empty string means no wait data
695-
// IsDagStepTrigger skips the idempotency check against an existing entry: the engine orchestrates the DAG
696-
// itself from a pinned workflow version, so its replays are deterministic by construction, whereas the key
697-
// hashes the run's input bytes, which change with the engine version that serialised them.
698-
IsDagStepTrigger bool
686+
Kind sqlcv1.V1DurableEventLogKind
687+
IdempotencyKey []byte
688+
InputPayload []byte
689+
ResultPayload []byte
690+
NodeId int64
691+
BranchId int64
692+
IsSatisfied bool
693+
UserMessage *string
694+
WaitData string // JSON-encoded WaitData, empty string means no wait data
695+
IsDAGStepTrigger bool
699696
ChildTaskExternalId uuid.UUID
700697
ShouldSkip bool
701698
// IsTriggered creates the entry with triggered_at already set: the child's task rows exist
@@ -704,7 +701,7 @@ type GetOrCreateLogEntryOpt struct {
704701
}
705702

706703
func (o GetOrCreateLogEntryOpt) matchesExistingEntry(existing *sqlcv1.BulkGetDurableEventLogEntriesRow) bool {
707-
return o.IsDagStepTrigger || bytes.Equal(o.IdempotencyKey, existing.IdempotencyKey)
704+
return o.IsDAGStepTrigger || bytes.Equal(o.IdempotencyKey, existing.IdempotencyKey)
708705
}
709706

710707
type GetOrCreateLogEntryOpts struct {

‎pkg/repository/durable_events_dag_replay_test.go‎

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func ingestDagStepTrigger(
2525
) *IngestTriggerRunsEntry {
2626
t.Helper()
2727

28-
result, err := ingestDagStepTriggerResult(ctx, repo, tenantID, task, invocationCount, actionId, childIndex, false)
28+
result, err := ingestDagStepTriggerResult(ctx, repo, tenantID, task, invocationCount, actionId, childIndex, []byte(`{"x":1}`), false)
2929
require.NoError(t, err)
3030
require.NotNil(t, result.TriggerRunsResult)
3131
require.Len(t, result.TriggerRunsResult.Entries, 1)
@@ -41,6 +41,7 @@ func ingestDagStepTriggerResult(
4141
invocationCount int32,
4242
actionId string,
4343
childIndex int64,
44+
input []byte,
4445
isSkipped bool,
4546
) (*IngestDurableTaskEventResult, error) {
4647
parentExternalId := task.ExternalID
@@ -61,7 +62,7 @@ func ingestDagStepTriggerResult(
6162
TriggerTaskData: &TriggerTaskData{
6263
IsSkipped: isSkipped,
6364
WorkflowName: "my-dag",
64-
Data: []byte(`{"x":1}`),
65+
Data: input,
6566
TargetActionId: &actionId,
6667
ParentExternalId: &parentExternalId,
6768
ParentTaskId: &parentTaskId,
@@ -84,7 +85,7 @@ func reinvokeDurableTask(t *testing.T, ctx context.Context, repos userEventScope
8485
require.NoError(t, err)
8586
}
8687

87-
func TestDagStepReplayAtAnotherStepsNodeIsNondeterministic(t *testing.T) {
88+
func TestDagStepReplayReusesTheEntryEvenWhenTheInputBytesDiffer(t *testing.T) {
8889
pool, cleanup := setupPostgresWithMigration(t)
8990
defer cleanup()
9091

@@ -93,17 +94,20 @@ func TestDagStepReplayAtAnotherStepsNodeIsNondeterministic(t *testing.T) {
9394
repos := newUserEventScopeTestRepositories(t, pool)
9495
task := createUserEventScopeTestTask(t, ctx, repos, tenantID, 201)
9596

96-
dedupe := ingestDagStepTrigger(t, ctx, repos.durable, tenantID, task, 1, "my-dag:dedupe-action-items", 13)
97-
require.False(t, dedupe.AlreadyExisted)
98-
require.EqualValues(t, 1, dedupe.NodeId)
97+
first := ingestDagStepTrigger(t, ctx, repos.durable, tenantID, task, 1, "my-dag:step-a", 1)
98+
require.False(t, first.AlreadyExisted)
99+
require.EqualValues(t, 1, first.NodeId)
99100

100101
reinvokeDurableTask(t, ctx, repos, tenantID, task)
101102

102-
_, err := ingestDagStepTriggerResult(ctx, repos.durable, tenantID, task, 2, "my-dag:bold-dates-and-quantities", 9, false)
103+
result, err := ingestDagStepTriggerResult(ctx, repos.durable, tenantID, task, 2, "my-dag:step-a", 1, []byte(`{"x": 1}`), false)
104+
require.NoError(t, err)
105+
require.Len(t, result.TriggerRunsResult.Entries, 1)
103106

104-
var nonDeterminismErr *NonDeterminismError
105-
require.ErrorAs(t, err, &nonDeterminismErr)
106-
require.EqualValues(t, 1, nonDeterminismErr.NodeId)
107+
replayed := result.TriggerRunsResult.Entries[0]
108+
require.True(t, replayed.AlreadyExisted)
109+
require.EqualValues(t, 1, replayed.NodeId)
110+
require.Equal(t, first.WorkflowRunExternalId, replayed.WorkflowRunExternalId)
107111
}
108112

109113
func TestDagStepEntriesOfSameWorkflowHaveDistinctIdempotencyKeys(t *testing.T) {
@@ -141,7 +145,7 @@ func TestDagStepCreatedSkippedTakesNextSatisfiedOrder(t *testing.T) {
141145
require.False(t, running.IsSatisfied)
142146
require.Nil(t, running.SatisfiedOrder)
143147

144-
result, err := ingestDagStepTriggerResult(ctx, repos.durable, tenantID, task, 1, "my-dag:step-b", 2, true)
148+
result, err := ingestDagStepTriggerResult(ctx, repos.durable, tenantID, task, 1, "my-dag:step-b", 2, []byte(`{"x":1}`), true)
145149
require.NoError(t, err)
146150

147151
skipped := result.TriggerRunsResult.Entries[0]

0 commit comments

Comments
 (0)