Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,6 @@ jobs:

- name: Test
run: go test -v ./...
env:
REDIS_ADDR: localhost:6379

19 changes: 10 additions & 9 deletions redis/jobstore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 7 additions & 1 deletion redis/redisq_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package redis
import (
"bytes"
"context"
"os"
"testing"
"time"

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

Expand Down