MCPcopy Create free account
hub / github.com/astercloud/aster / TestToolCache_Expiration

Function TestToolCache_Expiration

pkg/tools/cache_test.go:98–134  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

96}
97
98func TestToolCache_Expiration(t *testing.T) {
99 config := &CacheConfig{
100 Enabled: true,
101 Strategy: CacheStrategyMemory,
102 TTL: 100 * time.Millisecond,
103 }
104
105 cache := NewToolCache(config)
106 ctx := context.Background()
107 key := "test_key"
108 value := "test_value"
109
110 // 设置缓存
111 err := cache.Set(ctx, key, value, config.TTL)
112 if err != nil {
113 t.Fatalf("Failed to set cache: %v", err)
114 }
115
116 // 立即获取应该成功
117 if _, ok := cache.Get(ctx, key); !ok {
118 t.Fatal("Expected cache hit")
119 }
120
121 // 等待过期
122 time.Sleep(150 * time.Millisecond)
123
124 // 获取应该失败
125 if _, ok := cache.Get(ctx, key); ok {
126 t.Fatal("Expected cache miss after expiration")
127 }
128
129 // 检查统计
130 stats := cache.GetStats()
131 if stats.Misses != 1 {
132 t.Errorf("Expected 1 miss, got: %d", stats.Misses)
133 }
134}
135
136func TestToolCache_FileCache(t *testing.T) {
137 // 创建临时目录

Callers

nothing calls this directly

Calls 4

SetMethod · 0.95
GetMethod · 0.95
GetStatsMethod · 0.95
NewToolCacheFunction · 0.85

Tested by

no test coverage detected