diff --git a/aggregator_test.go b/aggregator_test.go index c32ef8c..d46d639 100644 --- a/aggregator_test.go +++ b/aggregator_test.go @@ -10,9 +10,9 @@ import ( "time" "github.com/google/go-cmp/cmp" - h "github.com/hibiken/asynq/internal/asynqtest" "github.com/hibiken/asynq/internal/base" "github.com/hibiken/asynq/internal/rdb" + h "github.com/hibiken/asynq/internal/testutil" ) func TestAggregator(t *testing.T) { diff --git a/asynq_test.go b/asynq_test.go index d1081a8..ad6bc7f 100644 --- a/asynq_test.go +++ b/asynq_test.go @@ -14,8 +14,8 @@ import ( "github.com/go-redis/redis/v8" "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" - h "github.com/hibiken/asynq/internal/asynqtest" "github.com/hibiken/asynq/internal/log" + h "github.com/hibiken/asynq/internal/testutil" ) //============================================================================ diff --git a/benchmark_test.go b/benchmark_test.go index b98ea34..dfae16a 100644 --- a/benchmark_test.go +++ b/benchmark_test.go @@ -12,7 +12,7 @@ import ( "testing" "time" - h "github.com/hibiken/asynq/internal/asynqtest" + h "github.com/hibiken/asynq/internal/testutil" ) // Creates a new task of type "task" with payload {"data": n}. diff --git a/client_test.go b/client_test.go index d578d52..da24d13 100644 --- a/client_test.go +++ b/client_test.go @@ -12,8 +12,8 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" - h "github.com/hibiken/asynq/internal/asynqtest" "github.com/hibiken/asynq/internal/base" + h "github.com/hibiken/asynq/internal/testutil" ) func TestClientEnqueueWithProcessAtOption(t *testing.T) { diff --git a/forwarder_test.go b/forwarder_test.go index da251e1..a8afa73 100644 --- a/forwarder_test.go +++ b/forwarder_test.go @@ -10,9 +10,9 @@ import ( "time" "github.com/google/go-cmp/cmp" - h "github.com/hibiken/asynq/internal/asynqtest" "github.com/hibiken/asynq/internal/base" "github.com/hibiken/asynq/internal/rdb" + h "github.com/hibiken/asynq/internal/testutil" ) func TestForwarder(t *testing.T) { diff --git a/heartbeat_test.go b/heartbeat_test.go index ea12c79..ec75ace 100644 --- a/heartbeat_test.go +++ b/heartbeat_test.go @@ -12,10 +12,10 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" - h "github.com/hibiken/asynq/internal/asynqtest" "github.com/hibiken/asynq/internal/base" "github.com/hibiken/asynq/internal/rdb" "github.com/hibiken/asynq/internal/testbroker" + h "github.com/hibiken/asynq/internal/testutil" "github.com/hibiken/asynq/internal/timeutil" ) diff --git a/inspector_test.go b/inspector_test.go index 4af0941..ff8add0 100644 --- a/inspector_test.go +++ b/inspector_test.go @@ -15,9 +15,9 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - h "github.com/hibiken/asynq/internal/asynqtest" "github.com/hibiken/asynq/internal/base" "github.com/hibiken/asynq/internal/rdb" + h "github.com/hibiken/asynq/internal/testutil" "github.com/hibiken/asynq/internal/timeutil" ) diff --git a/internal/rdb/benchmark_test.go b/internal/rdb/benchmark_test.go index 8d7dfae..27903dc 100644 --- a/internal/rdb/benchmark_test.go +++ b/internal/rdb/benchmark_test.go @@ -10,19 +10,19 @@ import ( "testing" "time" - "github.com/hibiken/asynq/internal/asynqtest" "github.com/hibiken/asynq/internal/base" + "github.com/hibiken/asynq/internal/testutil" ) func BenchmarkEnqueue(b *testing.B) { r := setup(b) ctx := context.Background() - msg := asynqtest.NewTaskMessage("task1", nil) + msg := testutil.NewTaskMessage("task1", nil) b.ResetTimer() for i := 0; i < b.N; i++ { b.StopTimer() - asynqtest.FlushDB(b, r.client) + testutil.FlushDB(b, r.client) b.StartTimer() if err := r.Enqueue(ctx, msg); err != nil { @@ -45,7 +45,7 @@ func BenchmarkEnqueueUnique(b *testing.B) { for i := 0; i < b.N; i++ { b.StopTimer() - asynqtest.FlushDB(b, r.client) + testutil.FlushDB(b, r.client) b.StartTimer() if err := r.EnqueueUnique(ctx, msg, uniqueTTL); err != nil { @@ -57,13 +57,13 @@ func BenchmarkEnqueueUnique(b *testing.B) { func BenchmarkSchedule(b *testing.B) { r := setup(b) ctx := context.Background() - msg := asynqtest.NewTaskMessage("task1", nil) + msg := testutil.NewTaskMessage("task1", nil) processAt := time.Now().Add(3 * time.Minute) b.ResetTimer() for i := 0; i < b.N; i++ { b.StopTimer() - asynqtest.FlushDB(b, r.client) + testutil.FlushDB(b, r.client) b.StartTimer() if err := r.Schedule(ctx, msg, processAt); err != nil { @@ -87,7 +87,7 @@ func BenchmarkScheduleUnique(b *testing.B) { for i := 0; i < b.N; i++ { b.StopTimer() - asynqtest.FlushDB(b, r.client) + testutil.FlushDB(b, r.client) b.StartTimer() if err := r.ScheduleUnique(ctx, msg, processAt, uniqueTTL); err != nil { @@ -103,9 +103,9 @@ func BenchmarkDequeueSingleQueue(b *testing.B) { for i := 0; i < b.N; i++ { b.StopTimer() - asynqtest.FlushDB(b, r.client) + testutil.FlushDB(b, r.client) for i := 0; i < 10; i++ { - m := asynqtest.NewTaskMessageWithQueue( + m := testutil.NewTaskMessageWithQueue( fmt.Sprintf("task%d", i), nil, base.DefaultQueueName) if err := r.Enqueue(ctx, m); err != nil { b.Fatalf("Enqueue failed: %v", err) @@ -127,10 +127,10 @@ func BenchmarkDequeueMultipleQueues(b *testing.B) { for i := 0; i < b.N; i++ { b.StopTimer() - asynqtest.FlushDB(b, r.client) + testutil.FlushDB(b, r.client) for i := 0; i < 10; i++ { for _, qname := range qnames { - m := asynqtest.NewTaskMessageWithQueue( + m := testutil.NewTaskMessageWithQueue( fmt.Sprintf("%s_task%d", qname, i), nil, qname) if err := r.Enqueue(ctx, m); err != nil { b.Fatalf("Enqueue failed: %v", err) @@ -147,9 +147,9 @@ func BenchmarkDequeueMultipleQueues(b *testing.B) { func BenchmarkDone(b *testing.B) { r := setup(b) - m1 := asynqtest.NewTaskMessage("task1", nil) - m2 := asynqtest.NewTaskMessage("task2", nil) - m3 := asynqtest.NewTaskMessage("task3", nil) + m1 := testutil.NewTaskMessage("task1", nil) + m2 := testutil.NewTaskMessage("task2", nil) + m3 := testutil.NewTaskMessage("task3", nil) msgs := []*base.TaskMessage{m1, m2, m3} zs := []base.Z{ {Message: m1, Score: time.Now().Add(10 * time.Second).Unix()}, @@ -161,9 +161,9 @@ func BenchmarkDone(b *testing.B) { for i := 0; i < b.N; i++ { b.StopTimer() - asynqtest.FlushDB(b, r.client) - asynqtest.SeedActiveQueue(b, r.client, msgs, base.DefaultQueueName) - asynqtest.SeedLease(b, r.client, zs, base.DefaultQueueName) + testutil.FlushDB(b, r.client) + testutil.SeedActiveQueue(b, r.client, msgs, base.DefaultQueueName) + testutil.SeedLease(b, r.client, zs, base.DefaultQueueName) b.StartTimer() if err := r.Done(ctx, msgs[0]); err != nil { @@ -174,9 +174,9 @@ func BenchmarkDone(b *testing.B) { func BenchmarkRetry(b *testing.B) { r := setup(b) - m1 := asynqtest.NewTaskMessage("task1", nil) - m2 := asynqtest.NewTaskMessage("task2", nil) - m3 := asynqtest.NewTaskMessage("task3", nil) + m1 := testutil.NewTaskMessage("task1", nil) + m2 := testutil.NewTaskMessage("task2", nil) + m3 := testutil.NewTaskMessage("task3", nil) msgs := []*base.TaskMessage{m1, m2, m3} zs := []base.Z{ {Message: m1, Score: time.Now().Add(10 * time.Second).Unix()}, @@ -188,9 +188,9 @@ func BenchmarkRetry(b *testing.B) { for i := 0; i < b.N; i++ { b.StopTimer() - asynqtest.FlushDB(b, r.client) - asynqtest.SeedActiveQueue(b, r.client, msgs, base.DefaultQueueName) - asynqtest.SeedLease(b, r.client, zs, base.DefaultQueueName) + testutil.FlushDB(b, r.client) + testutil.SeedActiveQueue(b, r.client, msgs, base.DefaultQueueName) + testutil.SeedLease(b, r.client, zs, base.DefaultQueueName) b.StartTimer() if err := r.Retry(ctx, msgs[0], time.Now().Add(1*time.Minute), "error", true /*isFailure*/); err != nil { @@ -201,9 +201,9 @@ func BenchmarkRetry(b *testing.B) { func BenchmarkArchive(b *testing.B) { r := setup(b) - m1 := asynqtest.NewTaskMessage("task1", nil) - m2 := asynqtest.NewTaskMessage("task2", nil) - m3 := asynqtest.NewTaskMessage("task3", nil) + m1 := testutil.NewTaskMessage("task1", nil) + m2 := testutil.NewTaskMessage("task2", nil) + m3 := testutil.NewTaskMessage("task3", nil) msgs := []*base.TaskMessage{m1, m2, m3} zs := []base.Z{ {Message: m1, Score: time.Now().Add(10 * time.Second).Unix()}, @@ -215,9 +215,9 @@ func BenchmarkArchive(b *testing.B) { for i := 0; i < b.N; i++ { b.StopTimer() - asynqtest.FlushDB(b, r.client) - asynqtest.SeedActiveQueue(b, r.client, msgs, base.DefaultQueueName) - asynqtest.SeedLease(b, r.client, zs, base.DefaultQueueName) + testutil.FlushDB(b, r.client) + testutil.SeedActiveQueue(b, r.client, msgs, base.DefaultQueueName) + testutil.SeedLease(b, r.client, zs, base.DefaultQueueName) b.StartTimer() if err := r.Archive(ctx, msgs[0], "error"); err != nil { @@ -228,9 +228,9 @@ func BenchmarkArchive(b *testing.B) { func BenchmarkRequeue(b *testing.B) { r := setup(b) - m1 := asynqtest.NewTaskMessage("task1", nil) - m2 := asynqtest.NewTaskMessage("task2", nil) - m3 := asynqtest.NewTaskMessage("task3", nil) + m1 := testutil.NewTaskMessage("task1", nil) + m2 := testutil.NewTaskMessage("task2", nil) + m3 := testutil.NewTaskMessage("task3", nil) msgs := []*base.TaskMessage{m1, m2, m3} zs := []base.Z{ {Message: m1, Score: time.Now().Add(10 * time.Second).Unix()}, @@ -242,9 +242,9 @@ func BenchmarkRequeue(b *testing.B) { for i := 0; i < b.N; i++ { b.StopTimer() - asynqtest.FlushDB(b, r.client) - asynqtest.SeedActiveQueue(b, r.client, msgs, base.DefaultQueueName) - asynqtest.SeedLease(b, r.client, zs, base.DefaultQueueName) + testutil.FlushDB(b, r.client) + testutil.SeedActiveQueue(b, r.client, msgs, base.DefaultQueueName) + testutil.SeedLease(b, r.client, zs, base.DefaultQueueName) b.StartTimer() if err := r.Requeue(ctx, msgs[0]); err != nil { @@ -258,7 +258,7 @@ func BenchmarkCheckAndEnqueue(b *testing.B) { now := time.Now() var zs []base.Z for i := -100; i < 100; i++ { - msg := asynqtest.NewTaskMessage(fmt.Sprintf("task%d", i), nil) + msg := testutil.NewTaskMessage(fmt.Sprintf("task%d", i), nil) score := now.Add(time.Duration(i) * time.Second).Unix() zs = append(zs, base.Z{Message: msg, Score: score}) } @@ -266,8 +266,8 @@ func BenchmarkCheckAndEnqueue(b *testing.B) { for i := 0; i < b.N; i++ { b.StopTimer() - asynqtest.FlushDB(b, r.client) - asynqtest.SeedScheduledQueue(b, r.client, zs, base.DefaultQueueName) + testutil.FlushDB(b, r.client) + testutil.SeedScheduledQueue(b, r.client, zs, base.DefaultQueueName) b.StartTimer() if err := r.ForwardIfReady(base.DefaultQueueName); err != nil { diff --git a/internal/rdb/inspect_test.go b/internal/rdb/inspect_test.go index 5d5aea2..0da4915 100644 --- a/internal/rdb/inspect_test.go +++ b/internal/rdb/inspect_test.go @@ -16,9 +16,9 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - h "github.com/hibiken/asynq/internal/asynqtest" "github.com/hibiken/asynq/internal/base" "github.com/hibiken/asynq/internal/errors" + h "github.com/hibiken/asynq/internal/testutil" "github.com/hibiken/asynq/internal/timeutil" ) diff --git a/internal/rdb/rdb_test.go b/internal/rdb/rdb_test.go index cf4be25..5094aa9 100644 --- a/internal/rdb/rdb_test.go +++ b/internal/rdb/rdb_test.go @@ -19,9 +19,9 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "github.com/google/uuid" - h "github.com/hibiken/asynq/internal/asynqtest" "github.com/hibiken/asynq/internal/base" "github.com/hibiken/asynq/internal/errors" + h "github.com/hibiken/asynq/internal/testutil" "github.com/hibiken/asynq/internal/timeutil" ) diff --git a/internal/testbroker/testbroker.go b/internal/testbroker/testbroker.go index ef2717c..49275f8 100644 --- a/internal/testbroker/testbroker.go +++ b/internal/testbroker/testbroker.go @@ -15,7 +15,7 @@ import ( "github.com/hibiken/asynq/internal/base" ) -var errRedisDown = errors.New("asynqtest: redis is down") +var errRedisDown = errors.New("testutil: redis is down") // TestBroker is a broker implementation which enables // to simulate Redis failure in tests. diff --git a/internal/asynqtest/builder.go b/internal/testutil/builder.go similarity index 98% rename from internal/asynqtest/builder.go rename to internal/testutil/builder.go index 2c9498f..fd70552 100644 --- a/internal/asynqtest/builder.go +++ b/internal/testutil/builder.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a MIT license // that can be found in the LICENSE file. -package asynqtest +package testutil import ( "time" diff --git a/internal/asynqtest/builder_test.go b/internal/testutil/builder_test.go similarity index 99% rename from internal/asynqtest/builder_test.go rename to internal/testutil/builder_test.go index 93b8f6e..e955889 100644 --- a/internal/asynqtest/builder_test.go +++ b/internal/testutil/builder_test.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a MIT license // that can be found in the LICENSE file. -package asynqtest +package testutil import ( "testing" diff --git a/internal/asynqtest/asynqtest.go b/internal/testutil/testutil.go similarity index 99% rename from internal/asynqtest/asynqtest.go rename to internal/testutil/testutil.go index cb00a4a..dc249f8 100644 --- a/internal/asynqtest/asynqtest.go +++ b/internal/testutil/testutil.go @@ -2,8 +2,8 @@ // Use of this source code is governed by a MIT license // that can be found in the LICENSE file. -// Package asynqtest defines test helpers for asynq and its internal packages. -package asynqtest +// Package testutil defines test helpers for asynq and its internal packages. +package testutil import ( "context" diff --git a/janitor_test.go b/janitor_test.go index c22aa23..7f61278 100644 --- a/janitor_test.go +++ b/janitor_test.go @@ -10,9 +10,9 @@ import ( "time" "github.com/google/go-cmp/cmp" - h "github.com/hibiken/asynq/internal/asynqtest" "github.com/hibiken/asynq/internal/base" "github.com/hibiken/asynq/internal/rdb" + h "github.com/hibiken/asynq/internal/testutil" ) func newCompletedTask(qname, tasktype string, payload []byte, completedAt time.Time) *base.TaskMessage { diff --git a/processor_test.go b/processor_test.go index 00f7ad6..8698644 100644 --- a/processor_test.go +++ b/processor_test.go @@ -15,11 +15,11 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" - h "github.com/hibiken/asynq/internal/asynqtest" "github.com/hibiken/asynq/internal/base" "github.com/hibiken/asynq/internal/errors" "github.com/hibiken/asynq/internal/log" "github.com/hibiken/asynq/internal/rdb" + h "github.com/hibiken/asynq/internal/testutil" "github.com/hibiken/asynq/internal/timeutil" ) diff --git a/recoverer_test.go b/recoverer_test.go index 064128d..e4fea76 100644 --- a/recoverer_test.go +++ b/recoverer_test.go @@ -10,9 +10,9 @@ import ( "time" "github.com/google/go-cmp/cmp" - h "github.com/hibiken/asynq/internal/asynqtest" "github.com/hibiken/asynq/internal/base" "github.com/hibiken/asynq/internal/rdb" + h "github.com/hibiken/asynq/internal/testutil" ) func TestRecoverer(t *testing.T) { diff --git a/scheduler_test.go b/scheduler_test.go index 9ee809f..2685667 100644 --- a/scheduler_test.go +++ b/scheduler_test.go @@ -10,8 +10,8 @@ import ( "time" "github.com/google/go-cmp/cmp" - "github.com/hibiken/asynq/internal/asynqtest" "github.com/hibiken/asynq/internal/base" + "github.com/hibiken/asynq/internal/testutil" ) func TestSchedulerRegister(t *testing.T) { @@ -69,8 +69,8 @@ func TestSchedulerRegister(t *testing.T) { time.Sleep(tc.wait) scheduler.Shutdown() - got := asynqtest.GetPendingMessages(t, r, tc.queue) - if diff := cmp.Diff(tc.want, got, asynqtest.IgnoreIDOpt); diff != "" { + got := testutil.GetPendingMessages(t, r, tc.queue) + if diff := cmp.Diff(tc.want, got, testutil.IgnoreIDOpt); diff != "" { t.Errorf("mismatch found in queue %q: (-want,+got)\n%s", tc.queue, diff) } } @@ -148,7 +148,7 @@ func TestSchedulerUnregister(t *testing.T) { time.Sleep(tc.wait) scheduler.Shutdown() - got := asynqtest.GetPendingMessages(t, r, tc.queue) + got := testutil.GetPendingMessages(t, r, tc.queue) if len(got) != 0 { t.Errorf("%d tasks were enqueued, want zero", len(got)) } diff --git a/server_test.go b/server_test.go index f4f190a..edbb6b2 100644 --- a/server_test.go +++ b/server_test.go @@ -11,9 +11,9 @@ import ( "testing" "time" - "github.com/hibiken/asynq/internal/asynqtest" "github.com/hibiken/asynq/internal/rdb" "github.com/hibiken/asynq/internal/testbroker" + "github.com/hibiken/asynq/internal/testutil" "go.uber.org/goleak" ) @@ -40,12 +40,12 @@ func TestServer(t *testing.T) { t.Fatal(err) } - _, err = c.Enqueue(NewTask("send_email", asynqtest.JSON(map[string]interface{}{"recipient_id": 123}))) + _, err = c.Enqueue(NewTask("send_email", testutil.JSON(map[string]interface{}{"recipient_id": 123}))) if err != nil { t.Errorf("could not enqueue a task: %v", err) } - _, err = c.Enqueue(NewTask("send_email", asynqtest.JSON(map[string]interface{}{"recipient_id": 456})), ProcessIn(1*time.Hour)) + _, err = c.Enqueue(NewTask("send_email", testutil.JSON(map[string]interface{}{"recipient_id": 456})), ProcessIn(1*time.Hour)) if err != nil { t.Errorf("could not enqueue a task: %v", err) } diff --git a/syncer_test.go b/syncer_test.go index d592baf..542b0a7 100644 --- a/syncer_test.go +++ b/syncer_test.go @@ -11,9 +11,9 @@ import ( "testing" "time" - h "github.com/hibiken/asynq/internal/asynqtest" "github.com/hibiken/asynq/internal/base" "github.com/hibiken/asynq/internal/rdb" + h "github.com/hibiken/asynq/internal/testutil" ) func TestSyncer(t *testing.T) {