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

Function TestFallbackCooldownState

pkg/runtime/fallback_test.go:333–370  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

331}
332
333func TestFallbackCooldownState(t *testing.T) {
334 t.Parallel()
335
336 synctest.Test(t, func(t *testing.T) {
337 mockModel := &mockProvider{id: "test/model", stream: newStreamBuilder().AddContent("ok").AddStopWithUsage(1, 1).Build()}
338 tm := team.New(team.WithAgents(
339 agent.New("test-agent", "test instruction", agent.WithModel(mockModel)),
340 ))
341 rt, err := NewLocalRuntime(t.Context(), tm, WithSessionCompaction(false), WithModelStore(mockModelStore{}))
342 require.NoError(t, err)
343
344 agentName := "test-agent"
345
346 // Initially no cooldown
347 assert.Nil(t, rt.fallback.cooldowns.Get(agentName), "should have no cooldown initially")
348
349 // Fake clock so cooldown expiry needs no sleeping.
350 current := time.Now()
351 rt.fallback.cooldowns.now = func() time.Time { return current }
352
353 // Set cooldown with short duration for testing
354 rt.fallback.cooldowns.Set(agentName, 0, 100*time.Millisecond)
355 state := rt.fallback.cooldowns.Get(agentName)
356 require.NotNil(t, state, "should have cooldown state")
357 assert.Equal(t, 0, state.fallbackIndex)
358
359 // Advance fake time past the cooldown
360 current = current.Add(101 * time.Millisecond)
361 assert.Nil(t, rt.fallback.cooldowns.Get(agentName), "cooldown should have expired")
362
363 // Set cooldown again and then clear it
364 rt.fallback.cooldowns.Set(agentName, 1, 1*time.Hour)
365 require.NotNil(t, rt.fallback.cooldowns.Get(agentName))
366
367 rt.fallback.cooldowns.Clear(agentName)
368 assert.Nil(t, rt.fallback.cooldowns.Get(agentName), "cooldown should be cleared")
369 })
370}
371
372func TestGetEffectiveCooldown(t *testing.T) {
373 t.Parallel()

Callers

nothing calls this directly

Calls 15

NewFunction · 0.92
WithAgentsFunction · 0.92
NewFunction · 0.92
WithModelFunction · 0.92
newStreamBuilderFunction · 0.85
NewLocalRuntimeFunction · 0.85
WithSessionCompactionFunction · 0.85
WithModelStoreFunction · 0.85
AddStopWithUsageMethod · 0.80
ContextMethod · 0.80
NowMethod · 0.80
GetMethod · 0.65

Tested by

no test coverage detected