diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 3d5fdc5..8f52922 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -31,3 +31,6 @@ jobs: - name: Test run: go test -v ./... + env: + REDIS_ADDR: localhost:6379 + diff --git a/redis/jobstore_test.go b/redis/jobstore_test.go index 890a6b9..b4932d6 100644 --- a/redis/jobstore_test.go +++ b/redis/jobstore_test.go @@ -74,8 +74,6 @@ func TestStoreCreateOrUpdate(t *testing.T) { if got.Status != taskqueue.JobStatusCompleted { t.Errorf("job status does not match the expected one. Diff:\n%s", cmp.Diff(job, got)) } - - t.Log("Job updated", got.UpdatedAt) } func TestStoreLastHeartbeats(t *testing.T) { @@ -132,51 +130,54 @@ func TestMetricsBackend(t *testing.T) { mb := NewMetricsBackend(client, WithNamespace("test")) now := time.Now() + gaugeKey := redisZSetKeyGaugeMetrics("test", taskqueue.MetricPendingQueueSize, map[string]string{"name": "test_redis_queue"}) + client.Del(context.Background(), gaugeKey) + if err := mb.RecordGauge(context.Background(), taskqueue.Metric{ Name: taskqueue.MetricPendingQueueSize, - Labels: map[string]string{"name": "email_queue"}, + Labels: map[string]string{"name": "test_redis_queue"}, }, 45, now.Add(-time.Minute*120)); err != nil { t.Fatal(err) } if err := mb.RecordGauge(context.Background(), taskqueue.Metric{ Name: taskqueue.MetricPendingQueueSize, - Labels: map[string]string{"name": "email_queue"}, + Labels: map[string]string{"name": "test_redis_queue"}, }, 60, now.Add(-time.Minute*60)); err != nil { t.Fatal(err) } if err := mb.RecordGauge(context.Background(), taskqueue.Metric{ Name: taskqueue.MetricPendingQueueSize, - Labels: map[string]string{"name": "email_queue"}, + Labels: map[string]string{"name": "test_redis_queue"}, }, 45, now.Add(-time.Minute*45)); err != nil { t.Fatal(err) } if err := mb.RecordGauge(context.Background(), taskqueue.Metric{ Name: taskqueue.MetricPendingQueueSize, - Labels: map[string]string{"name": "email_queue"}, + Labels: map[string]string{"name": "test_redis_queue"}, }, 32, now.Add(-time.Minute*30)); err != nil { t.Fatal(err) } if err := mb.RecordGauge(context.Background(), taskqueue.Metric{ Name: taskqueue.MetricPendingQueueSize, - Labels: map[string]string{"name": "email_queue"}, + Labels: map[string]string{"name": "test_redis_queue"}, }, 2, now.Add(-time.Minute*15)); err != nil { t.Fatal(err) } if err := mb.RecordGauge(context.Background(), taskqueue.Metric{ Name: taskqueue.MetricPendingQueueSize, - Labels: map[string]string{"name": "email_queue"}, + Labels: map[string]string{"name": "test_redis_queue"}, }, 80, now); err != nil { t.Fatal(err) } gv, err := mb.QueryRangeGaugeValues(context.Background(), taskqueue.Metric{ Name: taskqueue.MetricPendingQueueSize, - Labels: map[string]string{"name": "email_queue"}, + Labels: map[string]string{"name": "test_redis_queue"}, }, now.Add(-time.Minute*120), now) if err != nil { t.Fatal(err) diff --git a/redis/redisq_test.go b/redis/redisq_test.go index 9e273d9..0a5d118 100644 --- a/redis/redisq_test.go +++ b/redis/redisq_test.go @@ -3,6 +3,7 @@ package redis import ( "bytes" "context" + "os" "testing" "time" @@ -26,7 +27,12 @@ const testPayload = `{ }` func TestRedisQueue(t *testing.T) { - client := redis.NewClient(&redis.Options{Addr: "localhost:6379"}) + redisAddr := os.Getenv("REDIS_ADDR") + if redisAddr == "" { + t.Skip("Skipping TestRedisQueue. Please set REDIS_ADDR environment variable.") + } + + client := redis.NewClient(&redis.Options{Addr: redisAddr}) q := NewQueue(client, WithCompletedJobTTL(time.Minute*30))