-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support task delivery method uni for sticky task ownership (#30)
- Loading branch information
Showing
28 changed files
with
1,956 additions
and
365 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,176 @@ | ||
//go:build redis | ||
|
||
package lister | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/xh3b4sd/logger" | ||
"github.com/xh3b4sd/redigo" | ||
"github.com/xh3b4sd/rescue" | ||
"github.com/xh3b4sd/rescue/engine" | ||
"github.com/xh3b4sd/rescue/task" | ||
) | ||
|
||
func Test_Engine_Exists_Host(t *testing.T) { | ||
var err error | ||
|
||
var red redigo.Interface | ||
{ | ||
red = redigo.Default() | ||
} | ||
|
||
{ | ||
err = red.Purge() | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
} | ||
|
||
var eon rescue.Interface | ||
{ | ||
eon = engine.New(engine.Config{ | ||
Logger: logger.Fake(), | ||
Redigo: red, | ||
}) | ||
} | ||
|
||
{ | ||
exi, err := eon.Exists(&task.Task{Host: &task.Host{task.Method: task.MthdAll}}) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
if exi { | ||
t.Fatal("expected", false, "got", true) | ||
} | ||
} | ||
|
||
{ | ||
exi, err := eon.Exists(&task.Task{Host: &task.Host{task.Method: task.MthdUni}}) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
if exi { | ||
t.Fatal("expected", false, "got", true) | ||
} | ||
} | ||
|
||
{ | ||
exi, err := eon.Exists(&task.Task{Host: &task.Host{task.Method: task.MthdUni, task.Worker: "etw"}}) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
if exi { | ||
t.Fatal("expected", false, "got", true) | ||
} | ||
} | ||
|
||
{ | ||
exi, err := eon.Exists(&task.Task{Host: &task.Host{task.Method: task.MthdAny}}) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
if exi { | ||
t.Fatal("expected", false, "got", true) | ||
} | ||
} | ||
|
||
{ | ||
tas := &task.Task{ | ||
Host: &task.Host{ | ||
task.Method: task.MthdAll, | ||
}, | ||
Meta: &task.Meta{ | ||
"test.api.io/key": "foo", | ||
}, | ||
} | ||
|
||
err = eon.Create(tas) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
} | ||
|
||
{ | ||
tas := &task.Task{ | ||
Host: &task.Host{ | ||
task.Method: task.MthdUni, | ||
task.Worker: "eon", | ||
}, | ||
Meta: &task.Meta{ | ||
"test.api.io/key": "bar", | ||
}, | ||
} | ||
|
||
err = eon.Create(tas) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
} | ||
|
||
{ | ||
tas := &task.Task{ | ||
Host: &task.Host{ | ||
task.Method: task.MthdUni, | ||
task.Worker: "etw", | ||
}, | ||
Meta: &task.Meta{ | ||
"test.api.io/key": "baz", | ||
}, | ||
} | ||
|
||
err = eon.Create(tas) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
} | ||
|
||
{ | ||
exi, err := eon.Exists(&task.Task{Host: &task.Host{task.Method: task.MthdAll}}) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
if !exi { | ||
t.Fatal("expected", true, "got", false) | ||
} | ||
} | ||
|
||
{ | ||
exi, err := eon.Exists(&task.Task{Host: &task.Host{task.Method: task.MthdUni}}) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
if !exi { | ||
t.Fatal("expected", true, "got", false) | ||
} | ||
} | ||
|
||
{ | ||
exi, err := eon.Exists(&task.Task{Host: &task.Host{task.Method: task.MthdUni, task.Worker: "etw"}}) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
if !exi { | ||
t.Fatal("expected", true, "got", false) | ||
} | ||
} | ||
|
||
// There is no "any" task created, so it must not exist. | ||
{ | ||
exi, err := eon.Exists(&task.Task{Host: &task.Host{task.Method: task.MthdAny}}) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
if exi { | ||
t.Fatal("expected", false, "got", true) | ||
} | ||
} | ||
} |
Oops, something went wrong.