MCPcopy
hub / github.com/grafana/tempo / TestDrain_Train_CacheEvictionIntegration

Function TestDrain_Train_CacheEvictionIntegration

pkg/drain/drain_test.go:162–194  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

160}
161
162func TestDrain_Train_CacheEvictionIntegration(t *testing.T) {
163 t.Parallel()
164
165 config := DefaultConfig()
166 config.MaxClusters = 3 // Small cache size to trigger evictions
167 config.StaleClusterAge = 1 * time.Hour
168 drain := New("test-tenant", config)
169
170 // Fill cache beyond max size
171 spanNames := []string{
172 "GET /api/users/1",
173 "GET /api/users/2",
174 "GET /api/posts/3",
175 "GET /api/posts/4",
176 "GET /api/comments/5",
177 }
178
179 for _, spanName := range spanNames {
180 cluster := drain.Train(spanName)
181 require.NotNil(t, cluster)
182 }
183
184 // After filling cache, some clusters may have been evicted
185 allClusters := drain.Clusters()
186 require.LessOrEqual(t, len(allClusters), config.MaxClusters, "cache should respect max size")
187
188 // Prune should clean up references to evicted clusters
189 drain.Prune()
190
191 // After pruning, clusters count should still be <= max
192 allClustersAfterPrune := drain.Clusters()
193 require.LessOrEqual(t, len(allClustersAfterPrune), config.MaxClusters)
194}
195
196func TestDrain_Train_PatternEmergence(t *testing.T) {
197 t.Parallel()

Callers

nothing calls this directly

Calls 5

DefaultConfigFunction · 0.85
TrainMethod · 0.80
ClustersMethod · 0.80
NewFunction · 0.70
PruneMethod · 0.65

Tested by

no test coverage detected