diff --git a/example_test.go b/example_test.go index ec1f2ec..bd0965d 100644 --- a/example_test.go +++ b/example_test.go @@ -798,7 +798,7 @@ func newExampleMonitorer() *exampleMonitorer { } } -func (t *exampleMonitorer) Inc(id uuid.UUID, name string, status JobStatus) { +func (t *exampleMonitorer) Inc(_ uuid.UUID, name string, _ JobStatus) { t.mu.Lock() defer t.mu.Unlock() _, ok := t.counter[name] @@ -808,7 +808,7 @@ func (t *exampleMonitorer) Inc(id uuid.UUID, name string, status JobStatus) { t.counter[name]++ } -func (t *exampleMonitorer) WriteTiming(startTime, endTime time.Time, id uuid.UUID, name string) { +func (t *exampleMonitorer) WriteTiming(startTime, endTime time.Time, _ uuid.UUID, name string) { t.mu.Lock() defer t.mu.Unlock() _, ok := t.time[name] diff --git a/metrics.go b/metrics.go index c1a4c53..d1edda0 100644 --- a/metrics.go +++ b/metrics.go @@ -6,8 +6,11 @@ import ( "github.com/google/uuid" ) +// JobStatus is the status of job run that should be collect +// with metric. type JobStatus string +// The different statuses of job that can be used. const ( Fail JobStatus = "fail" Success JobStatus = "success" diff --git a/scheduler_test.go b/scheduler_test.go index 114a57e..a9901d5 100644 --- a/scheduler_test.go +++ b/scheduler_test.go @@ -1683,7 +1683,7 @@ func newTestMonitorer() *testMonitorer { } } -func (t *testMonitorer) Inc(id uuid.UUID, name string, status JobStatus) { +func (t *testMonitorer) Inc(_ uuid.UUID, name string, status JobStatus) { t.mu.Lock() defer t.mu.Unlock() _, ok := t.counter[name] @@ -1693,7 +1693,7 @@ func (t *testMonitorer) Inc(id uuid.UUID, name string, status JobStatus) { t.counter[name]++ } -func (t *testMonitorer) WriteTiming(startTime, endTime time.Time, id uuid.UUID, name string) { +func (t *testMonitorer) WriteTiming(startTime, endTime time.Time, _ uuid.UUID, name string) { t.mu.Lock() defer t.mu.Unlock() _, ok := t.time[name] @@ -1705,27 +1705,21 @@ func (t *testMonitorer) WriteTiming(startTime, endTime time.Time, id uuid.UUID, func TestScheduler_WithMonitorer(t *testing.T) { goleak.VerifyNone(t) - jobCh := make(chan struct{}) tests := []struct { name string jd JobDefinition - tsk Task jobName string - ch chan struct{} }{ { "scheduler with monitorer", DurationJob(time.Millisecond * 50), - NewTask(func() { - jobCh <- struct{}{} - }), "job", - jobCh, }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { + ch := make(chan struct{}, 20) testMonitorer := newTestMonitorer() s, err := NewScheduler(WithMonitorer(testMonitorer)) require.NoError(t, err) @@ -1738,22 +1732,20 @@ func TestScheduler_WithMonitorer(t *testing.T) { } _, err = s.NewJob( tt.jd, - tt.tsk, + NewTask(func() { + ch <- struct{}{} + }), opt..., ) require.NoError(t, err) - s.Start() - - expectedCount := 0 - go func() { - for range tt.ch { - expectedCount++ - } - }() - time.Sleep(150 * time.Millisecond) require.NoError(t, s.Shutdown()) + close(ch) + expectedCount := 0 + for range ch { + expectedCount++ + } got := testMonitorer.counter[tt.jobName] if got != expectedCount {