diff --git a/go.mod b/go.mod index d3ce496..5ab581b 100644 --- a/go.mod +++ b/go.mod @@ -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 ) diff --git a/memtaskmgr/mem_task_mgr_test.go b/memtaskmgr/mem_task_mgr_test.go index ff4cf65..7d409a9 100644 --- a/memtaskmgr/mem_task_mgr_test.go +++ b/memtaskmgr/mem_task_mgr_test.go @@ -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" ) @@ -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") } } diff --git a/redistaskmgr/redis_task_mgr.go b/redistaskmgr/redis_task_mgr.go index d2d8738..3ce3fae 100644 --- a/redistaskmgr/redis_task_mgr.go +++ b/redistaskmgr/redis_task_mgr.go @@ -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 diff --git a/redistaskmgr/redis_task_mgr_test.go b/redistaskmgr/redis_task_mgr_test.go index 3e3394b..c1906b8 100644 --- a/redistaskmgr/redis_task_mgr_test.go +++ b/redistaskmgr/redis_task_mgr_test.go @@ -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) @@ -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) {