-
Notifications
You must be signed in to change notification settings - Fork 35
/
scheduled_test.go
45 lines (32 loc) · 1.33 KB
/
scheduled_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package workers
import (
"context"
"testing"
"github.com/digitalocean/go-workers2/storage"
"github.com/go-redis/redis/v8"
"github.com/stretchr/testify/assert"
)
func TestScheduled(t *testing.T) {
ctx := context.Background()
opts, err := SetupDefaultTestOptionsWithNamespace("prod")
assert.NoError(t, err)
scheduled := newScheduledWorker(opts)
rc := opts.client
now := nowToSecondsWithNanoPrecision()
message1, _ := NewMsg("{\"queue\":\"default\",\"foo\":\"bar1\"}")
message2, _ := NewMsg("{\"queue\":\"myqueue\",\"foo\":\"bar2\"}")
message3, _ := NewMsg("{\"queue\":\"default\",\"foo\":\"bar3\"}")
rc.ZAdd(ctx, retryQueue(opts.Namespace), &redis.Z{Score: now - 60.0, Member: message1.ToJson()}).Result()
rc.ZAdd(ctx, retryQueue(opts.Namespace), &redis.Z{Score: now - 10.0, Member: message2.ToJson()}).Result()
rc.ZAdd(ctx, retryQueue(opts.Namespace), &redis.Z{Score: now + 60.0, Member: message3.ToJson()}).Result()
scheduled.poll()
defaultCount, _ := rc.LLen(ctx, "prod:queue:default").Result()
myqueueCount, _ := rc.LLen(ctx, "prod:queue:myqueue").Result()
pending, _ := rc.ZCard(ctx, retryQueue(opts.Namespace)).Result()
assert.Equal(t, int64(1), defaultCount)
assert.Equal(t, int64(1), myqueueCount)
assert.Equal(t, int64(1), pending)
}
func retryQueue(namespace string) string {
return namespace + storage.RetryKey
}