46 lines
1.4 KiB
Go
46 lines
1.4 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
// A cascade round gives its hold back on every way out: a declaration that cannot be marshalled
|
|
// and a send that fails leave nobody waiting for the node.
|
|
func TestASendRoundGivesItsHoldBackOnEveryWayOut(t *testing.T) {
|
|
open := aMesh(t)
|
|
ctx := t.Context()
|
|
unmarshallable := func(context.Context, string) (sendable, error) {
|
|
return sendable{Resources: []map[string]any{{"id": "x", "bad": make(chan int)}}}, nil
|
|
}
|
|
plain := func(context.Context, string) (sendable, error) {
|
|
return sendable{Resources: []map[string]any{{"id": "x"}}}, nil
|
|
}
|
|
failing := func(readyNode, []byte) error { return errors.New("the broker went away") }
|
|
fine := func(readyNode, []byte) error { return nil }
|
|
|
|
for name, round := range map[string]func() error{
|
|
"a body that cannot be marshalled": func() error {
|
|
_, err := sendRound(ctx, open, []string{"anchor"}, unmarshallable, fine)
|
|
return err
|
|
},
|
|
"a send that fails": func() error {
|
|
_, err := sendRound(ctx, open, []string{"anchor"}, plain, failing)
|
|
return err
|
|
},
|
|
} {
|
|
if err := round(); err == nil {
|
|
t.Fatalf("%s was not an error", name)
|
|
}
|
|
waiting, cancel := context.WithTimeout(ctx, 2*time.Second)
|
|
release, err := open.inventory.HoldNodes(waiting, []string{"anchor"})
|
|
cancel()
|
|
if err != nil {
|
|
t.Fatalf("after %s the node is still held: %v", name, err)
|
|
}
|
|
release()
|
|
}
|
|
}
|