forked from deepnoodle-ai/workflow
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheckpointer_fenced_test.go
More file actions
76 lines (64 loc) · 2.29 KB
/
checkpointer_fenced_test.go
File metadata and controls
76 lines (64 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package workflow
import (
"context"
"errors"
"fmt"
"testing"
"github.com/deepnoodle-ai/workflow/internal/require"
)
func TestFencedCheckpointerPassesOnValidFence(t *testing.T) {
inner := NewNullCheckpointer()
fenced := WithFencing(inner, func(ctx context.Context) error {
return nil // fence is valid
})
err := fenced.SaveCheckpoint(context.Background(), &Checkpoint{
ExecutionID: "test-1",
})
require.NoError(t, err)
}
func TestFencedCheckpointerRejectsOnLostLease(t *testing.T) {
inner := NewNullCheckpointer()
fenced := WithFencing(inner, func(ctx context.Context) error {
return fmt.Errorf("lease expired for worker-7")
})
err := fenced.SaveCheckpoint(context.Background(), &Checkpoint{
ExecutionID: "test-1",
})
require.Error(t, err)
require.True(t, errors.Is(err, ErrFenceViolation))
require.Contains(t, err.Error(), "lease expired for worker-7")
}
func TestFencedCheckpointerDoesNotFenceOnLoad(t *testing.T) {
fenceCalled := false
inner := NewNullCheckpointer()
fenced := WithFencing(inner, func(ctx context.Context) error {
fenceCalled = true
return fmt.Errorf("should not be called")
})
_, err := fenced.LoadCheckpoint(context.Background(), "any-id")
require.NoError(t, err)
require.False(t, fenceCalled)
}
func TestFenceViolationBypassesRetryAndCatch(t *testing.T) {
// Wrap an error with ErrFenceViolation
fenceErr := fmt.Errorf("%w: lease lost for worker-3", ErrFenceViolation)
// MatchesErrorType should return false for ALL error types — fence errors
// are never retryable or catchable
require.False(t, MatchesErrorType(fenceErr, ErrorTypeAll))
require.False(t, MatchesErrorType(fenceErr, ErrorTypeActivityFailed))
require.False(t, MatchesErrorType(fenceErr, ErrorTypeTimeout))
require.False(t, MatchesErrorType(fenceErr, ErrorTypeFatal))
require.False(t, MatchesErrorType(fenceErr, "custom-error"))
}
func TestFencedCheckpointerDoesNotDoubleWrap(t *testing.T) {
inner := NewNullCheckpointer()
// Consumer returns an error that already wraps ErrFenceViolation
fenced := WithFencing(inner, func(ctx context.Context) error {
return fmt.Errorf("%w: detected externally", ErrFenceViolation)
})
err := fenced.SaveCheckpoint(context.Background(), &Checkpoint{
ExecutionID: "test-1",
})
require.Error(t, err)
require.True(t, errors.Is(err, ErrFenceViolation))
}