Skip to content

Commit

Permalink
fix(redistaskmgr): fix id check
Browse files Browse the repository at this point in the history
  • Loading branch information
morlay committed Jan 9, 2020
1 parent 86a0244 commit f34af4e
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 19 deletions.
10 changes: 6 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
module github.com/go-courier/mq

go 1.12
go 1.13

require (
github.com/go-courier/courier v1.1.2
github.com/go-courier/metax v1.2.0
github.com/golang/protobuf v1.3.0
github.com/davecgh/go-spew v1.1.1
github.com/go-courier/courier v1.2.0
github.com/go-courier/metax v1.2.1
github.com/golang/protobuf v1.3.2
github.com/gomodule/redigo v2.0.0+incompatible
github.com/google/uuid v1.1.1
github.com/onsi/gomega v1.8.1
github.com/stretchr/testify v1.3.0
)
8 changes: 2 additions & 6 deletions memtaskmgr/mem_task_mgr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ package memtaskmgr
import (
"context"
"fmt"
"github.com/go-courier/mq/worker"
"sync"
"testing"

"github.com/stretchr/testify/require"
"github.com/go-courier/mq/worker"

"github.com/go-courier/mq"
)
Expand All @@ -17,10 +16,7 @@ var taskMgr = NewMemTaskMgr()
func BenchmarkTaskMgr(b *testing.B) {
for i := 0; i < b.N; i++ {
taskMgr.Push("TEST", mq.NewTask("", nil, fmt.Sprintf("%d", i)))

task, err := taskMgr.Shift("TEST")
require.NotNil(b, task)
require.NoError(b, err)
taskMgr.Shift("TEST")
}
}

Expand Down
2 changes: 1 addition & 1 deletion redistaskmgr/redis_task_mgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ local keyQueue = KEYS[1] .. '::queue'
local id = redis.call('LPOP', keyQueue)
local data
if (id == nil) then
if (id == nil or id == false) then
return id
end
Expand Down
19 changes: 11 additions & 8 deletions redistaskmgr/redis_task_mgr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import (

"github.com/go-courier/mq/worker"

"github.com/go-courier/mq"
"github.com/gomodule/redigo/redis"
"github.com/stretchr/testify/require"

"github.com/go-courier/mq"
. "github.com/onsi/gomega"
)

var taskMgr = NewRedisTaskMgr(r)
Expand Down Expand Up @@ -43,18 +43,21 @@ func init() {
func BenchmarkTaskMgr(b *testing.B) {
for i := 0; i < b.N; i++ {
taskMgr.Push(channel, mq.NewTask("TEST", nil, fmt.Sprintf("%d", i)))

task, err := taskMgr.Shift(channel)
require.NoError(b, err)
require.NotNil(b, task)
taskMgr.Shift(channel)
}
}

func TestSingle(t *testing.T) {
taskMgr.Push(channel, mq.NewTask("TEST", nil, "11"))
task, err := taskMgr.Shift(channel)
require.NoError(t, err)
require.NotNil(t, task)

NewWithT(t).Expect(err).To(BeNil())
NewWithT(t).Expect(task).NotTo(BeNil())
}

func TestTaskMgrEmptyShift(t *testing.T) {
_, err := taskMgr.Shift(channel)
NewWithT(t).Expect(err).To(BeNil())
}

func TestTaskMgr(t *testing.T) {
Expand Down

0 comments on commit f34af4e

Please sign in to comment.