MCPcopy Index your code
hub / github.com/coder/coder / TestWalkerNext

Function TestWalkerNext

aibridge/keypool/keypool_test.go:282–527  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

280}
281
282func TestWalkerNext(t *testing.T) {
283 t.Parallel()
284
285 tests := []struct {
286 name string
287 keys []string
288 setup func(t *testing.T, pool *keypool.Pool)
289 advance time.Duration
290 expectedValid []string
291 expectedErr *keypool.Error
292 }{
293 {
294 // Given: key-0: valid, key-1: valid, key-2: valid.
295 // Then: key-0: valid, key-1: valid, key-2: valid.
296 name: "all_keys_valid",
297 keys: []string{"key-0", "key-1", "key-2"},
298 setup: func(_ *testing.T, _ *keypool.Pool) {},
299 expectedValid: []string{"key-0", "key-1", "key-2"},
300 expectedErr: &keypool.Error{Kind: keypool.ErrorKindRateLimited},
301 },
302 {
303 // Given: key-0: temporary, key-1: valid, key-2: valid.
304 // Then: key-0: temporary, key-1: valid, key-2: valid.
305 name: "skips_temporary_keys",
306 keys: []string{"key-0", "key-1", "key-2"},
307 setup: func(t *testing.T, pool *keypool.Pool) {
308 key, keyPoolErr := pool.Walker().Next()
309 require.Nil(t, keyPoolErr)
310 key.MarkTemporary(60 * time.Second)
311 },
312 expectedValid: []string{"key-1", "key-2"},
313 expectedErr: &keypool.Error{Kind: keypool.ErrorKindRateLimited},
314 },
315 {
316 // Given: key-0: permanent, key-1: permanent, key-2: valid.
317 // Then: key-0: permanent, key-1: permanent, key-2: valid.
318 name: "skips_permanent_keys",
319 keys: []string{"key-0", "key-1", "key-2"},
320 setup: func(t *testing.T, pool *keypool.Pool) {
321 walker := pool.Walker()
322 key0, keyPoolErr := walker.Next()
323 require.Nil(t, keyPoolErr)
324 key0.MarkPermanent()
325 key1, keyPoolErr := walker.Next()
326 require.Nil(t, keyPoolErr)
327 key1.MarkPermanent()
328 },
329 expectedValid: []string{"key-2"},
330 expectedErr: &keypool.Error{Kind: keypool.ErrorKindRateLimited},
331 },
332 {
333 // Given: key-0: temporary (30s), key-1: valid.
334 // When: 35s pass.
335 // Then: key-0: valid, key-1: valid.
336 name: "expired_temporary_is_available",
337 keys: []string{"key-0", "key-1"},
338 setup: func(t *testing.T, pool *keypool.Pool) {
339 key, keyPoolErr := pool.Walker().Next()

Callers

nothing calls this directly

Calls 8

NewFunction · 0.92
WalkerMethod · 0.80
MarkTemporaryMethod · 0.80
MarkPermanentMethod · 0.80
NextMethod · 0.65
RunMethod · 0.65
EqualMethod · 0.45
ValueMethod · 0.45

Tested by

no test coverage detected