MCPcopy Index your code
hub / github.com/docker/docker-agent / TestFallbackCooldown_UsesInjectedClock

Function TestFallbackCooldown_UsesInjectedClock

pkg/runtime/clock_test.go:63–88  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

61}
62
63func TestFallbackCooldown_UsesInjectedClock(t *testing.T) {
64 t.Parallel()
65
66 prov := &mockProvider{id: "test/mock-model"}
67 root := agent.New("root", "test", agent.WithModel(prov))
68 tm := team.New(team.WithAgents(root))
69
70 clock := newFakeClock(time.Date(2024, 1, 1, 0, 0, 0, 0, time.UTC))
71 rt, err := NewLocalRuntime(t.Context(), tm,
72 WithClock(clock.Now),
73 WithModelStore(mockModelStore{}),
74 )
75 require.NoError(t, err)
76
77 // Activate cooldown for 1 minute against a fallback at index 0.
78 rt.fallback.cooldowns.Set("root", 0, time.Minute)
79 require.NotNil(t, rt.fallback.cooldowns.Get("root"), "cooldown should be active")
80
81 // Advance just under the window: still active.
82 clock.Advance(59 * time.Second)
83 assert.NotNil(t, rt.fallback.cooldowns.Get("root"), "cooldown expired prematurely")
84
85 // Advance past expiry: cooldowns.Get evicts and returns nil.
86 clock.Advance(2 * time.Second)
87 assert.Nil(t, rt.fallback.cooldowns.Get("root"), "expired cooldown not evicted")
88}

Callers

nothing calls this directly

Calls 12

NewFunction · 0.92
WithModelFunction · 0.92
NewFunction · 0.92
WithAgentsFunction · 0.92
newFakeClockFunction · 0.85
NewLocalRuntimeFunction · 0.85
WithModelStoreFunction · 0.85
ContextMethod · 0.80
WithClockFunction · 0.70
GetMethod · 0.65
SetMethod · 0.45
AdvanceMethod · 0.45

Tested by

no test coverage detected