MCPcopy Create free account
hub / github.com/cortexproject/cortex / TestCachedScanner_ConcurrentAccess

Function TestCachedScanner_ConcurrentAccess

pkg/util/users/cache_test.go:113–151  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

111}
112
113func TestCachedScanner_ConcurrentAccess(t *testing.T) {
114 t.Parallel()
115
116 ctx := context.Background()
117 reg := prometheus.NewRegistry()
118 scanner := &mockScanner{
119 active: []string{"user-1"},
120 deleting: []string{"user-2"},
121 deleted: []string{"user-3"},
122 }
123
124 cachedScanner := newCachedScanner(scanner, UsersScannerConfig{
125 CacheTTL: 1 * time.Hour,
126 }, reg)
127
128 // Run multiple concurrent scans
129 const goroutines = 10
130 done := make(chan struct{})
131
132 for range goroutines {
133 go func() {
134 defer func() { done <- struct{}{} }()
135
136 active, deleting, deleted, err := cachedScanner.ScanUsers(ctx)
137 require.NoError(t, err)
138 assert.Equal(t, scanner.active, active)
139 assert.Equal(t, scanner.deleting, deleting)
140 assert.Equal(t, scanner.deleted, deleted)
141 }()
142 }
143
144 // Wait for all goroutines to complete
145 for range goroutines {
146 <-done
147 }
148
149 // Verify that the underlying scanner was called only once
150 assert.Equal(t, 1, scanner.calls)
151}

Callers

nothing calls this directly

Calls 3

newCachedScannerFunction · 0.85
ScanUsersMethod · 0.65
EqualMethod · 0.65

Tested by

no test coverage detected