(t *testing.T)
| 225 | } |
| 226 | |
| 227 | func 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") |
nothing calls this directly
no test coverage detected