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

Function TestWalkerIndependence

aibridge/keypool/keypool_test.go:612–647  ·  view source on GitHub ↗

TestWalkerIndependence simulates two requests using the same pool. The first request marks key-0 temporary and key-1 permanent, then gets key-2. The second request sees the updated pool state and also gets key-2.

(t *testing.T)

Source from the content-addressed store, hash-verified

610// permanent, then gets key-2. The second request sees the
611// updated pool state and also gets key-2.
612func TestWalkerIndependence(t *testing.T) {
613 t.Parallel()
614
615 clk := quartz.NewMock(t)
616 pool, err := keypool.New([]string{"key-0", "key-1", "key-2"}, clk)
617 require.NoError(t, err)
618
619 walker := pool.Walker()
620
621 // First attempt: get key-0.
622 key, keyPoolErr := walker.Next()
623 require.Nil(t, keyPoolErr)
624 assert.Equal(t, "key-0", key.Value())
625
626 // Simulate 429: mark key-0 temporary.
627 key.MarkTemporary(60 * time.Second)
628
629 // Second attempt: walker advances to key-1.
630 key, keyPoolErr = walker.Next()
631 require.Nil(t, keyPoolErr)
632 assert.Equal(t, "key-1", key.Value())
633
634 // Simulate 401: mark key-1 permanent.
635 key.MarkPermanent()
636
637 // Third attempt: walker advances to key-2.
638 key, keyPoolErr = walker.Next()
639 require.Nil(t, keyPoolErr)
640 assert.Equal(t, "key-2", key.Value())
641
642 // A new walker should skip key-0 (temporary) and key-1
643 // (permanent), and return key-2.
644 key2, keyPoolErr := pool.Walker().Next()
645 require.Nil(t, keyPoolErr)
646 assert.Equal(t, "key-2", key2.Value())
647}

Callers

nothing calls this directly

Calls 7

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

Tested by

no test coverage detected