Skip to content

Commit

Permalink
support task delivery method uni for sticky task ownership (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
xh3b4sd committed Oct 21, 2023
1 parent c144f8e commit 5641df0
Show file tree
Hide file tree
Showing 28 changed files with 1,956 additions and 365 deletions.
176 changes: 176 additions & 0 deletions conformance/exists/host_redis_test.go
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)
}
}
}
Loading

0 comments on commit 5641df0

Please sign in to comment.