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

Function TestPrune

modules/backendscheduler/work/work_sharded_test.go:227–285  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

225}
226
227func TestPrune(t *testing.T) {
228 cfg := Config{
229 PruneAge: time.Hour,
230 DeadJobTimeout: 30 * time.Minute,
231 }
232 work := New(cfg)
233 ctx := context.Background()
234
235 now := time.Now()
236
237 var err error
238
239 // Add old completed job (should be pruned)
240 oldCompleted := createTestJob("old-completed", tempopb.JobType_JOB_TYPE_COMPACTION)
241 err = work.AddJob(oldCompleted)
242 require.NoError(t, err)
243 work.CompleteJob(oldCompleted.ID) // Sets status to SUCCEEDED
244 retrievedOldCompleted := work.GetJob(oldCompleted.ID)
245 retrievedOldCompleted.EndTime = now.Add(-2 * time.Hour)
246
247 // Add recent completed job (should not be pruned)
248 recentCompleted := createTestJob("recent-completed", tempopb.JobType_JOB_TYPE_COMPACTION)
249 err = work.AddJob(recentCompleted)
250 require.NoError(t, err)
251 work.CompleteJob(recentCompleted.ID) // Sets status to SUCCEEDED
252 retrievedRecentCompleted := work.GetJob(recentCompleted.ID)
253 retrievedRecentCompleted.EndTime = now.Add(-10 * time.Minute)
254
255 // Add old running job (should be failed)
256 oldRunning := createTestJob("old-running", tempopb.JobType_JOB_TYPE_COMPACTION)
257 err = work.AddJob(oldRunning)
258 require.NoError(t, err)
259 work.StartJob(oldRunning.ID) // Sets status to RUNNING
260 retrievedOldRunning := work.GetJob(oldRunning.ID)
261 retrievedOldRunning.StartTime = now.Add(-time.Hour)
262
263 // Add recent running job (should remain running)
264 recentRunning := createTestJob("recent-running", tempopb.JobType_JOB_TYPE_COMPACTION)
265 err = work.AddJob(recentRunning)
266 require.NoError(t, err)
267 work.StartJob(recentRunning.ID) // Sets status to RUNNING
268 retrievedRecentRunning := work.GetJob(recentRunning.ID)
269 retrievedRecentRunning.StartTime = now.Add(-10 * time.Minute)
270
271 // Run prune
272 work.Prune(ctx)
273
274 // Verify results
275 require.Nil(t, work.GetJob("old-completed"), "old completed job should be pruned")
276 require.NotNil(t, work.GetJob("recent-completed"), "recent completed job should remain")
277
278 oldRunningJob := work.GetJob("old-running")
279 require.NotNil(t, oldRunningJob, "old running job should still exist")
280 require.Equal(t, tempopb.JobStatus_JOB_STATUS_FAILED, oldRunningJob.Status, "old running job should be failed")
281
282 recentRunningJob := work.GetJob("recent-running")
283 require.NotNil(t, recentRunningJob, "recent running job should remain")
284 require.Equal(t, tempopb.JobStatus_JOB_STATUS_RUNNING, recentRunningJob.Status, "recent running job should stay running")

Callers

nothing calls this directly

Calls 10

createTestJobFunction · 0.85
NewFunction · 0.70
NowMethod · 0.65
AddJobMethod · 0.65
CompleteJobMethod · 0.65
GetJobMethod · 0.65
AddMethod · 0.65
StartJobMethod · 0.65
PruneMethod · 0.65
EqualMethod · 0.45

Tested by

no test coverage detected