MCPcopy
hub / github.com/redis/go-redis / TestLazyReloadQueueBehavior

Function TestLazyReloadQueueBehavior

osscluster_lazy_reload_test.go:11–201  ·  view source on GitHub ↗

TestLazyReloadQueueBehavior tests that LazyReload properly queues reload requests

(t *testing.T)

Source from the content-addressed store, hash-verified

9
10// TestLazyReloadQueueBehavior tests that LazyReload properly queues reload requests
11func TestLazyReloadQueueBehavior(t *testing.T) {
12 t.Run("SingleReload", func(t *testing.T) {
13 var reloadCount atomic.Int32
14
15 holder := newClusterStateHolder(func(ctx context.Context) (*clusterState, error) {
16 reloadCount.Add(1)
17 time.Sleep(50 * time.Millisecond) // Simulate reload work
18 return &clusterState{}, nil
19 }, 10*time.Second)
20
21 // Trigger one reload
22 holder.LazyReload()
23
24 // Wait for reload to complete
25 time.Sleep(300 * time.Millisecond)
26
27 if count := reloadCount.Load(); count != 1 {
28 t.Errorf("Expected 1 reload, got %d", count)
29 }
30 })
31
32 t.Run("ConcurrentReloadsDeduplication", func(t *testing.T) {
33 var reloadCount atomic.Int32
34
35 holder := newClusterStateHolder(func(ctx context.Context) (*clusterState, error) {
36 reloadCount.Add(1)
37 time.Sleep(50 * time.Millisecond) // Simulate reload work
38 return &clusterState{}, nil
39 }, 10*time.Second)
40
41 // Trigger multiple reloads concurrently
42 for i := 0; i < 10; i++ {
43 go holder.LazyReload()
44 }
45
46 // Wait for all to complete
47 time.Sleep(100 * time.Millisecond)
48
49 // Should only reload once (all concurrent calls deduplicated)
50 if count := reloadCount.Load(); count != 1 {
51 t.Errorf("Expected 1 reload (deduplication), got %d", count)
52 }
53 })
54
55 t.Run("PendingReloadDuringCooldown", func(t *testing.T) {
56 var reloadCount atomic.Int32
57
58 holder := newClusterStateHolder(func(ctx context.Context) (*clusterState, error) {
59 reloadCount.Add(1)
60 time.Sleep(10 * time.Millisecond) // Simulate reload work
61 return &clusterState{}, nil
62 }, 10*time.Second)
63
64 // Trigger first reload
65 holder.LazyReload()
66
67 // Wait for reload to complete but still in cooldown
68 time.Sleep(50 * time.Millisecond)

Callers

nothing calls this directly

Calls 5

newClusterStateHolderFunction · 0.85
LazyReloadMethod · 0.80
AddMethod · 0.65
RunMethod · 0.45
LoadMethod · 0.45

Tested by

no test coverage detected