Skip to content

Commit

Permalink
golangci-lint version upgrade + fixes (#93)
Browse files Browse the repository at this point in the history
  • Loading branch information
bgentry authored Dec 3, 2023
1 parent 4fd541f commit 78e436a
Show file tree
Hide file tree
Showing 19 changed files with 56 additions and 52 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ jobs:
# Optional: show only new issues if it's a pull request. The default value is `false`.
only-new-issues: true

version: v1.54.2
version: v1.55.2

producer_sample:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -201,7 +201,7 @@ jobs:
- name: Setup sqlc
uses: sqlc-dev/setup-sqlc@v4
with:
sqlc-version: '1.22.0'
sqlc-version: "1.22.0"

- name: Run sqlc diff
working-directory: ./internal/dbsqlc
Expand Down
4 changes: 2 additions & 2 deletions client_monitor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func Test_Monitor(t *testing.T) {

monitor.SetElectorStatus(componentstatus.ElectorLeader)
update := awaitSnapshot(t, snapshotCh)
require.Len(update.Producers, 0)
require.Empty(update.Producers)
require.Equal(componentstatus.ElectorLeader, update.Elector)
require.Equal(componentstatus.Uninitialized, update.Notifier)

Expand All @@ -79,7 +79,7 @@ func Test_Monitor(t *testing.T) {

monitor.SetNotifierStatus(componentstatus.Initializing)
update := awaitSnapshot(t, snapshotCh)
require.Len(update.Producers, 0)
require.Empty(update.Producers)
require.Equal(componentstatus.ElectorNonLeader, update.Elector)
require.Equal(componentstatus.Initializing, update.Notifier)

Expand Down
8 changes: 4 additions & 4 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1146,7 +1146,7 @@ func Test_Client_ErrorHandler(t *testing.T) {
HandleErrorFunc: func(ctx context.Context, job *rivertype.JobRow, err error) *ErrorHandlerResult {
var unknownJobKindErr *UnknownJobKindError
require.ErrorAs(t, err, &unknownJobKindErr)
require.Equal(t, *unknownJobKindErr, UnknownJobKindError{Kind: "RandomWorkerNameThatIsNeverRegistered"})
require.Equal(t, UnknownJobKindError{Kind: "RandomWorkerNameThatIsNeverRegistered"}, *unknownJobKindErr)
errorHandlerCalled = true
return &ErrorHandlerResult{}
},
Expand Down Expand Up @@ -1348,7 +1348,7 @@ func Test_Client_Maintenance(t *testing.T) {
// No jobs yet because the RunOnStart option was not specified.
jobs, err := queries.JobGetByKind(ctx, client.driver.GetDBPool(), (periodicJobArgs{}).Kind())
require.NoError(t, err)
require.Len(t, jobs, 0)
require.Empty(t, jobs)
})

t.Run("Reindexer", func(t *testing.T) {
Expand Down Expand Up @@ -2133,7 +2133,7 @@ func Test_Client_UnknownJobKindErrorsTheJob(t *testing.T) {

event := riverinternaltest.WaitOrTimeout(t, subscribeChan)
require.Equal(insertRes.Job.ID, event.Job.ID)
require.Equal(insertRes.Job.Kind, "RandomWorkerNameThatIsNeverRegistered")
require.Equal("RandomWorkerNameThatIsNeverRegistered", insertRes.Job.Kind)
require.Len(event.Job.Errors, 1)
require.Equal((&UnknownJobKindError{Kind: "RandomWorkerNameThatIsNeverRegistered"}).Error(), event.Job.Errors[0].Error)
require.Equal(JobStateRetryable, event.Job.State)
Expand Down Expand Up @@ -2552,7 +2552,7 @@ func Test_NewClient_Validations(t *testing.T) {

client, err := NewClient(riverpgxv5.New(dbPool), config)
if tt.wantErr != nil {
require.NotNil(err)
require.Error(err)
require.ErrorContains(err, tt.wantErr.Error())
return
}
Expand Down
2 changes: 1 addition & 1 deletion internal/dbadapter/db_adapter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ func Test_Adapter_JobInsertMany(t *testing.T) {

count, err := adapter.JobInsertMany(ctx, insertParams)
require.NoError(t, err)
require.Equal(t, len(insertParams), int(count))
require.Len(t, insertParams, int(count))

jobsAfter, err := adapter.JobGetAvailable(ctx, rivercommon.QueueDefault, int32(len(insertParams)))
require.NoError(t, err)
Expand Down
6 changes: 3 additions & 3 deletions internal/maintenance/job_cleaner.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ func (s *JobCleaner) Start(ctx context.Context) error { //nolint:dupl
// races.
defer close(stopped)

s.Logger.InfoContext(ctx, s.Name+": Run loop started")
defer s.Logger.InfoContext(ctx, s.Name+": Run loop stopped")
s.Logger.InfoContext(ctx, s.Name+logPrefixRunLoopStarted)
defer s.Logger.InfoContext(ctx, s.Name+logPrefixRunLoopStopped)

ticker := timeutil.NewTickerWithInitialTick(ctx, s.Config.Interval)
for {
Expand All @@ -130,7 +130,7 @@ func (s *JobCleaner) Start(ctx context.Context) error { //nolint:dupl
continue
}

s.Logger.InfoContext(ctx, s.Name+": Ran successfully",
s.Logger.InfoContext(ctx, s.Name+logPrefixRanSuccessfully,
slog.Int64("num_jobs_deleted", res.NumJobsDeleted),
)
}
Expand Down
8 changes: 4 additions & 4 deletions internal/maintenance/job_cleaner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ func TestJobCleaner(t *testing.T) {

cleaner := NewJobCleaner(riverinternaltest.BaseServiceArchetype(t), &JobCleanerConfig{}, nil)

require.Equal(t, cleaner.Config.CancelledJobRetentionPeriod, CancelledJobRetentionPeriodDefault)
require.Equal(t, cleaner.Config.CompletedJobRetentionPeriod, CompletedJobRetentionPeriodDefault)
require.Equal(t, cleaner.Config.DiscardedJobRetentionPeriod, DiscardedJobRetentionPeriodDefault)
require.Equal(t, cleaner.Config.Interval, JobCleanerIntervalDefault)
require.Equal(t, CancelledJobRetentionPeriodDefault, cleaner.Config.CancelledJobRetentionPeriod)
require.Equal(t, CompletedJobRetentionPeriodDefault, cleaner.Config.CompletedJobRetentionPeriod)
require.Equal(t, DiscardedJobRetentionPeriodDefault, cleaner.Config.DiscardedJobRetentionPeriod)
require.Equal(t, JobCleanerIntervalDefault, cleaner.Config.Interval)
})

t.Run("StartStopStress", func(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions internal/maintenance/periodic_job_enqueuer.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ func (s *PeriodicJobEnqueuer) Start(ctx context.Context) error {
// races.
defer close(stopped)

s.Logger.InfoContext(ctx, s.Name+": Run loop started")
defer s.Logger.InfoContext(ctx, s.Name+": Run loop stopped")
s.Logger.InfoContext(ctx, s.Name+logPrefixRunLoopStarted)
defer s.Logger.InfoContext(ctx, s.Name+logPrefixRunLoopStopped)

// An initial loop to assign next runs for every configured job and
// queues any jobs that should run immediately.
Expand Down
4 changes: 4 additions & 0 deletions internal/maintenance/queue_maintainer.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ const (

JitterMin = 0 * time.Second
JitterMax = 1 * time.Second

logPrefixRanSuccessfully = ": Ran successfully"
logPrefixRunLoopStarted = ": Run loop started"
logPrefixRunLoopStopped = ": Run loop stopped"
)

// QueueMaintainer runs regular maintenance operations against job queues, like
Expand Down
6 changes: 3 additions & 3 deletions internal/maintenance/reindexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ func (s *Reindexer) Start(ctx context.Context) error {
// races.
defer close(stopped)

s.Logger.InfoContext(ctx, s.Name+": Run loop started")
defer s.Logger.InfoContext(ctx, s.Name+": Run loop stopped")
s.Logger.InfoContext(ctx, s.Name+logPrefixRunLoopStarted)
defer s.Logger.InfoContext(ctx, s.Name+logPrefixRunLoopStopped)

// On each run, we calculate the new schedule based on the previous run's
// start time. This ensures that we don't accidentally skip a run as time
Expand Down Expand Up @@ -135,7 +135,7 @@ func (s *Reindexer) Start(ctx context.Context) error {
s.TestSignals.Reindexed.Signal(struct{}{})
}
// TODO: maybe we should log differently if some of these fail?
s.Logger.InfoContext(ctx, s.Name+": Ran successfully", slog.Int("num_reindexes_initiated", len(s.Config.IndexNames)))
s.Logger.InfoContext(ctx, s.Name+logPrefixRanSuccessfully, slog.Int("num_reindexes_initiated", len(s.Config.IndexNames)))
}
}()

Expand Down
6 changes: 3 additions & 3 deletions internal/maintenance/rescuer.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ func (s *Rescuer) Start(ctx context.Context) error {
s.CancellableSleepRandomBetween(ctx, JitterMin, JitterMax)

go func() {
s.Logger.InfoContext(ctx, s.Name+": Run loop started")
defer s.Logger.InfoContext(ctx, s.Name+": Run loop stopped")
s.Logger.InfoContext(ctx, s.Name+logPrefixRunLoopStarted)
defer s.Logger.InfoContext(ctx, s.Name+logPrefixRunLoopStopped)

defer close(stopped)

Expand All @@ -133,7 +133,7 @@ func (s *Rescuer) Start(ctx context.Context) error {
continue
}

s.Logger.InfoContext(ctx, s.Name+": Ran successfully",
s.Logger.InfoContext(ctx, s.Name+logPrefixRanSuccessfully,
slog.Int64("num_jobs_discarded", res.NumJobsDiscarded),
slog.Int64("num_jobs_retry_scheduled", res.NumJobsRetried),
)
Expand Down
4 changes: 2 additions & 2 deletions internal/maintenance/rescuer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ func TestRescuer(t *testing.T) {
nil,
)

require.Equal(t, cleaner.Config.RescueAfter, RescueAfterDefault)
require.Equal(t, cleaner.Config.Interval, RescuerIntervalDefault)
require.Equal(t, RescueAfterDefault, cleaner.Config.RescueAfter)
require.Equal(t, RescuerIntervalDefault, cleaner.Config.Interval)
})

t.Run("StartStopStress", func(t *testing.T) {
Expand Down
6 changes: 3 additions & 3 deletions internal/maintenance/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ func (s *Scheduler) Start(ctx context.Context) error { //nolint:dupl
// races.
defer close(stopped)

s.Logger.InfoContext(ctx, s.Name+": Run loop started")
defer s.Logger.InfoContext(ctx, s.Name+": Run loop stopped")
s.Logger.InfoContext(ctx, s.Name+logPrefixRunLoopStarted)
defer s.Logger.InfoContext(ctx, s.Name+logPrefixRunLoopStopped)

ticker := timeutil.NewTickerWithInitialTick(ctx, s.config.Interval)
for {
Expand All @@ -116,7 +116,7 @@ func (s *Scheduler) Start(ctx context.Context) error { //nolint:dupl
}
continue
}
s.Logger.InfoContext(ctx, s.Name+": Ran successfully",
s.Logger.InfoContext(ctx, s.Name+logPrefixRanSuccessfully,
slog.Int64("num_jobs_scheduled", res.NumCompletedJobsScheduled),
)
}
Expand Down
4 changes: 2 additions & 2 deletions internal/maintenance/scheduler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ func TestScheduler(t *testing.T) {

scheduler := NewScheduler(riverinternaltest.BaseServiceArchetype(t), &SchedulerConfig{}, nil)

require.Equal(t, scheduler.config.Interval, SchedulerIntervalDefault)
require.Equal(t, scheduler.config.Limit, SchedulerLimitDefault)
require.Equal(t, SchedulerIntervalDefault, scheduler.config.Interval)
require.Equal(t, SchedulerLimitDefault, scheduler.config.Limit)
})

t.Run("StartStopStress", func(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion internal/riverinternaltest/riverinternaltest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
// `riverinternaltest_test`, except that the test below uses internal variables
// like `dbPool`.
type Executor interface {
Exec(context.Context, string, ...interface{}) (pgconn.CommandTag, error)
Exec(ctx context.Context, query string, args ...interface{}) (pgconn.CommandTag, error)
}

func TestTestTx(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions internal/util/maputil/map_util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func TestKeys(t *testing.T) {
r1 := Keys(map[string]int{"foo": 1, "bar": 2})
sort.Strings(r1)

is.Equal(r1, []string{"bar", "foo"})
is.Equal([]string{"bar", "foo"}, r1)
}

func TestValues(t *testing.T) {
Expand All @@ -26,5 +26,5 @@ func TestValues(t *testing.T) {
r1 := Values(map[string]int{"foo": 1, "bar": 2})
sort.Ints(r1)

is.Equal(r1, []int{1, 2})
is.Equal([]int{1, 2}, r1)
}
14 changes: 7 additions & 7 deletions internal/util/sliceutil/slice_util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ func TestGroupBy(t *testing.T) {
return i % 3
})

require.Equal(t, len(result1), 3)
require.Equal(t, result1, map[int][]int{
require.Len(t, result1, 3)
require.Equal(t, map[int][]int{
0: {0, 3},
1: {1, 4},
2: {2, 5},
})
}, result1)
}

func TestKeyBy(t *testing.T) {
Expand Down Expand Up @@ -70,8 +70,8 @@ func TestMap(t *testing.T) {
return strconv.FormatInt(x, 10)
})

require.Equal(t, len(result1), 4)
require.Equal(t, len(result2), 4)
require.Equal(t, result1, []string{"Hello", "Hello", "Hello", "Hello"})
require.Equal(t, result2, []string{"1", "2", "3", "4"})
require.Len(t, result1, 4)
require.Len(t, result2, 4)
require.Equal(t, []string{"Hello", "Hello", "Hello", "Hello"}, result1)
require.Equal(t, []string{"1", "2", "3", "4"}, result2)
}
14 changes: 7 additions & 7 deletions job_executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ func TestJobExecutor_Execute(t *testing.T) {
require.Equal(t, baselineTime, job.Errors[0].At)
require.Equal(t, uint16(1), job.Errors[0].Attempt)
require.Equal(t, "job error", job.Errors[0].Error)
require.Equal(t, job.Errors[0].Trace, "")
require.Equal(t, "", job.Errors[0].Trace)
})

t.Run("ErrorAgainAfterRetry", func(t *testing.T) {
Expand Down Expand Up @@ -329,7 +329,7 @@ func TestJobExecutor_Execute(t *testing.T) {
require.Equal(t, dbsqlc.JobStateScheduled, job.State)
require.WithinDuration(t, time.Now().Add(30*time.Minute), job.ScheduledAt, 2*time.Second)
require.Equal(t, maxAttemptsBefore+1, int(job.MaxAttempts))
require.Len(t, job.Errors, 0)
require.Empty(t, job.Errors)
})

t.Run("ErrorWithCustomRetryPolicy", func(t *testing.T) {
Expand Down Expand Up @@ -579,7 +579,7 @@ func TestUnknownJobKindError_As(t *testing.T) {

err1 := &UnknownJobKindError{Kind: "MyJobArgs"}
var err2 *UnknownJobKindError
require.True(t, errors.As(err1, &err2))
require.ErrorAs(t, err1, &err2)
require.Equal(t, err1, err2)
require.Equal(t, err1.Kind, err2.Kind)
})
Expand All @@ -599,14 +599,14 @@ func TestUnknownJobKindError_Is(t *testing.T) {
t.Parallel()

err1 := &UnknownJobKindError{Kind: "MyJobArgs"}
require.True(t, errors.Is(err1, &UnknownJobKindError{}))
require.ErrorIs(t, err1, &UnknownJobKindError{})
})

t.Run("ReturnsFalseForADifferentError", func(t *testing.T) {
t.Parallel()

err1 := &UnknownJobKindError{Kind: "MyJobArgs"}
require.False(t, errors.Is(err1, fmt.Errorf("some other error")))
require.NotErrorIs(t, err1, fmt.Errorf("some other error"))
})
}

Expand All @@ -616,12 +616,12 @@ func TestJobCancel(t *testing.T) {
t.Run("ErrorsIsReturnsTrueForAnotherErrorOfSameType", func(t *testing.T) {
t.Parallel()
err1 := JobCancel(errors.New("some message"))
require.True(t, errors.Is(err1, JobCancel(errors.New("another message"))))
require.ErrorIs(t, err1, JobCancel(errors.New("another message")))
})

t.Run("ErrorsIsReturnsFalseForADifferentErrorType", func(t *testing.T) {
t.Parallel()
err1 := JobCancel(errors.New("some message"))
require.False(t, errors.Is(err1, &UnknownJobKindError{Kind: "MyJobArgs"}))
require.NotErrorIs(t, err1, &UnknownJobKindError{Kind: "MyJobArgs"})
})
}
2 changes: 1 addition & 1 deletion periodic.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
type PeriodicSchedule interface {
// Next returns the next time at which the job should be run given the
// current time.
Next(time.Time) time.Time
Next(current time.Time) time.Time
}

// PeriodicJobConstructor is a function that gets called each time the paired
Expand Down
6 changes: 3 additions & 3 deletions rivertest/rivertest.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ import (
// common implementation that takes one of these.
type dbtx interface {
CopyFrom(ctx context.Context, tableName pgx.Identifier, columnNames []string, rowSrc pgx.CopyFromSource) (int64, error)
Exec(context.Context, string, ...interface{}) (pgconn.CommandTag, error)
Query(context.Context, string, ...interface{}) (pgx.Rows, error)
QueryRow(context.Context, string, ...interface{}) pgx.Row
Exec(ctx context.Context, query string, args ...interface{}) (pgconn.CommandTag, error)
Query(ctx context.Context, query string, args ...interface{}) (pgx.Rows, error)
QueryRow(ctx context.Context, query string, args ...interface{}) pgx.Row
}

// testingT is an interface wrapper around *testing.T that's implemented by all
Expand Down

0 comments on commit 78e436a

Please sign in to comment.