(t *testing.T)
| 96 | } |
| 97 | |
| 98 | func 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 | |
| 136 | func TestToolCache_FileCache(t *testing.T) { |
| 137 | // 创建临时目录 |
nothing calls this directly
no test coverage detected