-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathincremental_test.go
More file actions
59 lines (51 loc) · 1.42 KB
/
incremental_test.go
File metadata and controls
59 lines (51 loc) · 1.42 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
package sight
import (
"sync"
"testing"
)
func TestIncrementalState_Basic(t *testing.T) {
state := NewIncrementalState("")
if got := state.LastReviewedSHA(); got != "" {
t.Errorf("expected empty SHA, got %q", got)
}
state.SetLastReviewedSHA("abc123")
if got := state.LastReviewedSHA(); got != "abc123" {
t.Errorf("expected 'abc123', got %q", got)
}
}
func TestIncrementalState_Seeded(t *testing.T) {
state := NewIncrementalState("initial-sha")
if got := state.LastReviewedSHA(); got != "initial-sha" {
t.Errorf("expected 'initial-sha', got %q", got)
}
}
func TestIncrementalState_Update(t *testing.T) {
state := NewIncrementalState("sha1")
state.SetLastReviewedSHA("sha2")
if got := state.LastReviewedSHA(); got != "sha2" {
t.Errorf("expected 'sha2', got %q", got)
}
state.SetLastReviewedSHA("sha3")
if got := state.LastReviewedSHA(); got != "sha3" {
t.Errorf("expected 'sha3', got %q", got)
}
}
func TestIncrementalState_Concurrent(t *testing.T) {
state := NewIncrementalState("")
var wg sync.WaitGroup
// Write from multiple goroutines to test thread safety
for i := 0; i < 100; i++ {
wg.Add(1)
go func(sha string) {
defer wg.Done()
state.SetLastReviewedSHA(sha)
_ = state.LastReviewedSHA()
}("sha-" + string(rune('a'+i%26)))
}
wg.Wait()
// Should not panic or race; any value is fine
got := state.LastReviewedSHA()
if got == "" {
t.Error("expected non-empty SHA after concurrent writes")
}
}