A worker bound for a pull was kept for the process, so a later connection's pull used a worker bound on a closed connection and answered "connection closed" (every run of TestAHolderPullsOneMessageWhenItHasRoom after the first). The bound workers and the pulled messages are now the Conn's. The two tests that failed main.165 and main.115 asserted on bus figures before the bus had delivered them: the worker's pending count right after a publish, a no-wait pull right after a publish, a callback counter read when a flush returned, a 300 ms delay and a 2 s ack wait a loaded machine overruns. They now count binds on a channel the watcher's reader fills, pull with a wait that ends at the delivery, prove "nothing fetched ahead" by the second message's first delivery, and use bounds a loaded machine stays within. Builds: design 47 H H-A-363 (fix-a-bug-met-twice; whole-module tests under load, H-A-327)
86 lines
4.2 KiB
Go
86 lines
4.2 KiB
Go
package bus_test
|
|
|
|
import (
|
|
"encoding/json"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/novox/mesh-tools/node-tools/internal/bus"
|
|
)
|
|
|
|
// 1887/A11: a holder pulls one message at a time, only from a worker its membership lists, never a prefetch; it settles
|
|
// only what it pulled, and a message handed back comes again.
|
|
func TestAHolderPullsOneMessageWhenItHasRoom(t *testing.T) {
|
|
_, conn, js := seatMesh(t)
|
|
for _, id := range []string{"a1", "a2"} {
|
|
if _, err := conn.SeatPublish("mesh-delivery", "mesh.seat.operator-channel.accept.ask.mesh-delivery",
|
|
json.RawMessage(`{"id":"`+id+`"}`), id); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
// A pull that wants a message waits for it: the worker learns of a stored message after the publish is answered, so
|
|
// a pull that waits for nothing can find none yet on a loaded machine (design 47 H, H-A-363). A wait is a bound, not a
|
|
// measure: it ends at the delivery.
|
|
first, err := conn.SeatPull("messenger", "SEAT_OPERATOR_CHANNEL_worker", 10*time.Second)
|
|
if err != nil || first == nil || string(first.Body) != `{"id":"a1"}` || first.Delivered != 1 {
|
|
t.Fatalf("the first pull = %+v, %v", first, err)
|
|
}
|
|
// One pulled and in hand, the other never delivered: nothing was fetched ahead. What is in hand is the worker's own
|
|
// count, set by the delivery itself; the count still waiting is the worker's figure of the stream, learnt later, so
|
|
// the second message's first delivery says it instead.
|
|
info, err := js.ConsumerInfo("SEAT_OPERATOR_CHANNEL", "SEAT_OPERATOR_CHANNEL_worker")
|
|
if err != nil || info.NumAckPending != 1 {
|
|
t.Fatalf("after one pull: in hand %d (%v); want 1", info.NumAckPending, err)
|
|
}
|
|
second, err := conn.SeatPull("messenger", "SEAT_OPERATOR_CHANNEL_worker", 10*time.Second)
|
|
if err != nil || second == nil || string(second.Body) != `{"id":"a2"}` || second.Delivered != 1 {
|
|
t.Fatalf("the second pull = %+v, %v", second, err)
|
|
}
|
|
if none, err := conn.SeatPull("messenger", "SEAT_OPERATOR_CHANNEL_worker", 0); err != nil || none != nil {
|
|
t.Fatalf("an empty worker answered %+v, %v", none, err)
|
|
}
|
|
began := time.Now()
|
|
if none, err := conn.SeatPull("messenger", "SEAT_OPERATOR_CHANNEL_worker", 200*time.Millisecond); err != nil || none != nil || time.Since(began) < 150*time.Millisecond {
|
|
t.Fatalf("a waiting pull answered %+v, %v after %v", none, err, time.Since(began))
|
|
}
|
|
if err := conn.SeatSettle("telegram", first.ID, bus.SettleAck); err == nil {
|
|
t.Error("a module settled another's message")
|
|
}
|
|
if err := conn.SeatSettle("messenger", first.ID, bus.SettleProgress); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := conn.SeatSettle("messenger", first.ID, bus.SettleAck); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := conn.SeatSettle("messenger", first.ID, bus.SettleAck); err == nil {
|
|
t.Error("a message was settled twice")
|
|
}
|
|
if err := conn.SeatSettle("messenger", second.ID, bus.SettleNak); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
again, err := conn.SeatPull("messenger", "SEAT_OPERATOR_CHANNEL_worker", 10*time.Second)
|
|
if err != nil || again == nil || string(again.Body) != `{"id":"a2"}` || again.Delivered != 2 {
|
|
t.Fatalf("the message handed back = %+v, %v", again, err)
|
|
}
|
|
// Issue 1748: a message settled with a delay is not given again at once, is after it, one delivery higher; a delay
|
|
// of 0 settles nothing. The delay is what the next pull must come within to see nothing, so it is a second, not a
|
|
// moment a loaded machine can spend between two calls.
|
|
if err := conn.SeatSettleAfter("messenger", again.ID, 0); err == nil {
|
|
t.Error("a delay of 0 was accepted")
|
|
}
|
|
if err := conn.SeatSettleAfter("messenger", again.ID, time.Second); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if early, err := conn.SeatPull("messenger", "SEAT_OPERATOR_CHANNEL_worker", 0); err != nil || early != nil {
|
|
t.Fatalf("a message given again after a delay came at once: %+v, %v", early, err)
|
|
}
|
|
late, err := conn.SeatPull("messenger", "SEAT_OPERATOR_CHANNEL_worker", 10*time.Second)
|
|
if err != nil || late == nil || late.Delivered != 3 {
|
|
t.Fatalf("the message given again after its delay = %+v, %v", late, err)
|
|
}
|
|
if _, err := conn.SeatPull("telegram", "SEAT_OPERATOR_CHANNEL_worker", 0); err == nil || !strings.Contains(err.Error(), "membership lists") {
|
|
t.Errorf("a channel pulled the router's work: %v", err)
|
|
}
|
|
}
|