Skip to content

Commit

Permalink
Fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
gorodet-sky committed Jan 10, 2024
1 parent 336d947 commit 275849a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 21 deletions.
4 changes: 2 additions & 2 deletions example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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]
Expand Down
3 changes: 3 additions & 0 deletions metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
30 changes: 11 additions & 19 deletions scheduler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

Check warning on line 1686 in scheduler_test.go

View workflow job for this annotation

GitHub Actions / lint and test (1.20)

unused-parameter: parameter 'status' seems to be unused, consider removing or renaming it as _ (revive)

Check warning on line 1686 in scheduler_test.go

View workflow job for this annotation

GitHub Actions / lint and test (1.21)

unused-parameter: parameter 'status' seems to be unused, consider removing or renaming it as _ (revive)
t.mu.Lock()
defer t.mu.Unlock()
_, ok := t.counter[name]
Expand All @@ -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]
Expand All @@ -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)
Expand All @@ -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 {
Expand Down

0 comments on commit 275849a

Please sign in to comment.