Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
evlekht committed Oct 15, 2024
1 parent 602975f commit c3c51c8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
11 changes: 10 additions & 1 deletion pkg/scheduler/scheduler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
reflect "reflect"
"slices"
"testing"
"time"

Expand Down Expand Up @@ -216,6 +217,11 @@ func requireJobsToBeExecuted(t *testing.T, execTime time.Time, jobs []*Job, exec

require.Len(t, jobs, len(executed))

notExecutedJobNames := make([]string, len(jobs))
for i, job := range jobs {
notExecutedJobNames[i] = job.Name
}

for i := 0; i < len(jobs); i++ {
cases := make([]reflect.SelectCase, len(executed)+1)
for i, ch := range executed {
Expand All @@ -224,10 +230,13 @@ func requireJobsToBeExecuted(t *testing.T, execTime time.Time, jobs []*Job, exec
cases[len(executed)] = reflect.SelectCase{Dir: reflect.SelectRecv, Chan: reflect.ValueOf(time.After(timeout))}

if i, _, _ := reflect.Select(cases); i == len(executed) {
require.FailNow(t, "some jobs wasn't executed within timeout")
require.FailNowf(t, "some jobs wasn't executed within timeout", "some of %v", notExecutedJobNames)
}
require.Equal(t, execTime, jobs[i].ExecuteAt, "expected %s (%d) to be executed at %d, but got at %d",
jobs[i].Name, jobs[i].Period, jobs[i].ExecuteAt.UnixNano(), execTime.UnixNano())
notExecutedJobNames = slices.DeleteFunc(notExecutedJobNames, func(jobName string) bool {
return jobs[i].Name == jobName
})
}
}

Expand Down
1 change: 0 additions & 1 deletion pkg/scheduler/timer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ func TestTimer_Start(t *testing.T) {
select {
case <-callCh:
case <-time.After(timeout):
// TODO@ sometimes fails. Why?
require.FailNow("function was not called within the expected duration")
}

Expand Down

0 comments on commit c3c51c8

Please sign in to comment.