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

Function TestListJobs

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

Source from the content-addressed store, hash-verified

158}
159
160func TestListJobs(t *testing.T) {
161 work := New(Config{})
162
163 // Add jobs with different creation times
164 jobs := []*Job{
165 createTestJob("job-1", tempopb.JobType_JOB_TYPE_COMPACTION),
166 createTestJob("job-2", tempopb.JobType_JOB_TYPE_COMPACTION),
167 createTestJob("job-3", tempopb.JobType_JOB_TYPE_COMPACTION),
168 }
169
170 var err error
171
172 for i, job := range jobs {
173 err = work.AddJob(job)
174 require.NoError(t, err)
175 // Manually set creation time for testing sorting
176 retrievedJob := work.GetJob(job.ID)
177 retrievedJob.CreatedTime = time.Now().Add(time.Duration(i) * time.Second)
178 }
179
180 listedJobs := work.ListJobs()
181 require.Equal(t, len(jobs), len(listedJobs))
182
183 // Verify jobs are sorted by creation time
184 for i := 1; i < len(listedJobs); i++ {
185 require.True(t, listedJobs[i-1].CreatedTime.Before(listedJobs[i].CreatedTime) ||
186 listedJobs[i-1].CreatedTime.Equal(listedJobs[i].CreatedTime))
187 }
188}
189
190func TestGetJobForWorker(t *testing.T) {
191 var (

Callers

nothing calls this directly

Calls 9

createTestJobFunction · 0.85
DurationMethod · 0.80
NewFunction · 0.70
AddJobMethod · 0.65
GetJobMethod · 0.65
AddMethod · 0.65
NowMethod · 0.65
ListJobsMethod · 0.65
EqualMethod · 0.45

Tested by

no test coverage detected