From 148600269af04b194f6b41184b1b200e1dbafd1e Mon Sep 17 00:00:00 2001 From: Stefan Negrea <3912943+stefannegrea@users.noreply.github.com> Date: Fri, 3 May 2024 08:46:36 -0500 Subject: [PATCH] Fix general warnings golang warnings. --- api_retries_test.go | 8 +++----- heartbeat_test.go | 4 +++- options.go | 4 ++-- producer_test.go | 1 + worker_test.go | 28 ++++++++++++++-------------- 5 files changed, 23 insertions(+), 22 deletions(-) diff --git a/api_retries_test.go b/api_retries_test.go index ce93efb..93ccc0c 100644 --- a/api_retries_test.go +++ b/api_retries_test.go @@ -4,11 +4,12 @@ import ( "context" "encoding/json" "errors" - "github.com/stretchr/testify/assert" "log" "net/http/httptest" "os" "testing" + + "github.com/stretchr/testify/assert" ) func TestRetries_Empty(t *testing.T) { @@ -33,8 +34,6 @@ func TestRetries_NotEmpty(t *testing.T) { assert.Equal(t, "[]\n", recorder.Body.String()) - ctx := context.Background() - // test API replies with registered workers opts, err := SetupDefaultTestOptionsWithNamespace("prod") assert.NoError(t, err) @@ -71,14 +70,13 @@ func TestRetries_NotEmpty(t *testing.T) { }, } - ctx = context.Background() var messages []string for index, test := range tests { // Test panic wares.build("myqueue", mgr, test.f)(message) // retries order is not guaranteed - retries, err := opts.client.ZRange(ctx, retryQueue(opts.Namespace), 0, -1).Result() + retries, err := opts.client.ZRange(context.Background(), retryQueue(opts.Namespace), 0, -1).Result() assert.NoError(t, err) assert.Len(t, retries, index+1) messages = append(messages, message.ToJson()) diff --git a/heartbeat_test.go b/heartbeat_test.go index aa4f032..cdff181 100644 --- a/heartbeat_test.go +++ b/heartbeat_test.go @@ -2,11 +2,12 @@ package workers import ( "encoding/json" - "github.com/stretchr/testify/assert" "log" "os" "testing" "time" + + "github.com/stretchr/testify/assert" ) func TestBuildHeartbeat(t *testing.T) { @@ -52,6 +53,7 @@ func TestBuildHeartbeatWorkerMessage(t *testing.T) { return nil }) msg, err := NewMsg("{\"class\":\"MyWorker\",\"jid\":\"jid-123\"}") + assert.NoError(t, err) testLogger := log.New(os.Stdout, "test-go-workers2: ", log.Ldate|log.Lmicroseconds) diff --git a/options.go b/options.go index df33415..7bb63ab 100644 --- a/options.go +++ b/options.go @@ -131,7 +131,7 @@ func processOptionsWithRedisClient(options Options, client *redis.Client) (Optio } if client == nil { - return Options{}, errors.New("Redis client is nil; Redis client is not configured") + return Options{}, errors.New("redis client is nil; Redis client is not configured") } options.client = client @@ -148,7 +148,7 @@ func processOptionsWithRedisClient(options Options, client *redis.Client) (Optio func validateGeneralOptions(options Options) (Options, error) { if options.ProcessID == "" { - return Options{}, errors.New("Options requires a ProcessID, which uniquely identifies this instance") + return Options{}, errors.New("options requires a ProcessID, which uniquely identifies this instance") } if options.Namespace != "" { diff --git a/producer_test.go b/producer_test.go index e54b8d4..506ecb6 100644 --- a/producer_test.go +++ b/producer_test.go @@ -118,6 +118,7 @@ func TestProducer_EnqueueIn(t *testing.T) { var data EnqueueData elem, err := rc.ZRange(ctx, scheduleQueue, 0, -1).Result() + assert.NoError(t, err) bytes := elem[0] err = json.Unmarshal([]byte(bytes), &data) assert.NoError(t, err) diff --git a/worker_test.go b/worker_test.go index 154e794..a6a503d 100644 --- a/worker_test.go +++ b/worker_test.go @@ -23,21 +23,21 @@ type dummyFetcher struct { closed func() bool } -func (d dummyFetcher) Queue() string { return d.queue() } -func (d dummyFetcher) InProgressQueue() string { return d.inProgressQueue() } -func (d dummyFetcher) Fetch() { d.fetch() } -func (d dummyFetcher) Acknowledge(m *Msg) { d.acknowledge(m) } -func (d dummyFetcher) Ready() chan bool { return d.ready() } -func (d dummyFetcher) Messages() chan *Msg { return d.messages() } -func (d dummyFetcher) Close() { d.close() } -func (d dummyFetcher) Closed() bool { return d.closed() } - -func (d dummyFetcher) SetActive(active bool) { +func (d *dummyFetcher) Queue() string { return d.queue() } +func (d *dummyFetcher) InProgressQueue() string { return d.inProgressQueue() } +func (d *dummyFetcher) Fetch() { d.fetch() } +func (d *dummyFetcher) Acknowledge(m *Msg) { d.acknowledge(m) } +func (d *dummyFetcher) Ready() chan bool { return d.ready() } +func (d *dummyFetcher) Messages() chan *Msg { return d.messages() } +func (d *dummyFetcher) Close() { d.close() } +func (d *dummyFetcher) Closed() bool { return d.closed() } + +func (d *dummyFetcher) SetActive(active bool) { d.lock.Lock() defer d.lock.Unlock() d.isActive = active } -func (d dummyFetcher) IsActive() bool { +func (d *dummyFetcher) IsActive() bool { d.lock.Lock() defer d.lock.Unlock() return d.isActive @@ -99,7 +99,7 @@ func TestWorker(t *testing.T) { var wg sync.WaitGroup go func() { wg.Add(1) - w.start(df) + w.start(&df) wg.Done() }() @@ -120,7 +120,7 @@ func TestWorker(t *testing.T) { assert.Equal(t, w.inProgressQueue, df.InProgressQueue()) t.Run("cannot start while running", func(t *testing.T) { - w.start(df) + w.start(&df) // This test would time out if w.start doesn't return immediately }) @@ -192,7 +192,7 @@ func TestWorkerProcessesAndAcksMessages(t *testing.T) { go func() { wg.Add(1) - w.start(df) + w.start(&df) wg.Done() }()