mirror of
https://github.com/hibiken/asynq.git
synced 2025-09-19 05:17:30 +08:00
Move unique key generator function to base
This commit is contained in:
@@ -561,72 +561,6 @@ func TestClientDefaultOptions(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestUniqueKey(t *testing.T) {
|
||||
tests := []struct {
|
||||
desc string
|
||||
task *Task
|
||||
ttl time.Duration
|
||||
qname string
|
||||
want string
|
||||
}{
|
||||
{
|
||||
"with zero TTL",
|
||||
NewTask("email:send", map[string]interface{}{"a": 123, "b": "hello", "c": true}),
|
||||
0,
|
||||
"default",
|
||||
"",
|
||||
},
|
||||
{
|
||||
"with primitive types",
|
||||
NewTask("email:send", map[string]interface{}{"a": 123, "b": "hello", "c": true}),
|
||||
10 * time.Minute,
|
||||
"default",
|
||||
"email:send:a=123,b=hello,c=true:default",
|
||||
},
|
||||
{
|
||||
"with unsorted keys",
|
||||
NewTask("email:send", map[string]interface{}{"b": "hello", "c": true, "a": 123}),
|
||||
10 * time.Minute,
|
||||
"default",
|
||||
"email:send:a=123,b=hello,c=true:default",
|
||||
},
|
||||
{
|
||||
"with composite types",
|
||||
NewTask("email:send",
|
||||
map[string]interface{}{
|
||||
"address": map[string]string{"line": "123 Main St", "city": "Boston", "state": "MA"},
|
||||
"names": []string{"bob", "mike", "rob"}}),
|
||||
10 * time.Minute,
|
||||
"default",
|
||||
"email:send:address=map[city:Boston line:123 Main St state:MA],names=[bob mike rob]:default",
|
||||
},
|
||||
{
|
||||
"with complex types",
|
||||
NewTask("email:send",
|
||||
map[string]interface{}{
|
||||
"time": time.Date(2020, time.July, 28, 0, 0, 0, 0, time.UTC),
|
||||
"duration": time.Hour}),
|
||||
10 * time.Minute,
|
||||
"default",
|
||||
"email:send:duration=1h0m0s,time=2020-07-28 00:00:00 +0000 UTC:default",
|
||||
},
|
||||
{
|
||||
"with nil payload",
|
||||
NewTask("reindex", nil),
|
||||
10 * time.Minute,
|
||||
"default",
|
||||
"reindex:nil:default",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range tests {
|
||||
got := uniqueKey(tc.task, tc.ttl, tc.qname)
|
||||
if got != tc.want {
|
||||
t.Errorf("%s: uniqueKey(%v, %v, %q) = %q, want %q", tc.desc, tc.task, tc.ttl, tc.qname, got, tc.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestEnqueueUnique(t *testing.T) {
|
||||
r := setup(t)
|
||||
c := NewClient(RedisClientOpt{
|
||||
|
Reference in New Issue
Block a user