Skip to content

Commit

Permalink
Fix general warnings golang warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
stefannegrea committed May 3, 2024
1 parent 2939032 commit 1486002
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 22 deletions.
8 changes: 3 additions & 5 deletions api_retries_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)
Expand Down Expand Up @@ -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())
Expand Down
4 changes: 3 additions & 1 deletion heartbeat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 != "" {
Expand Down
1 change: 1 addition & 0 deletions producer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
28 changes: 14 additions & 14 deletions worker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
}()

Expand All @@ -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
})

Expand Down Expand Up @@ -192,7 +192,7 @@ func TestWorkerProcessesAndAcksMessages(t *testing.T) {

go func() {
wg.Add(1)
w.start(df)
w.start(&df)
wg.Done()
}()

Expand Down

0 comments on commit 1486002

Please sign in to comment.