42 lines
1.4 KiB
Go
42 lines
1.4 KiB
Go
//go:build integration
|
|
|
|
package main
|
|
|
|
import "testing"
|
|
|
|
func TestEachSendToANodeIsOneHigherAndReadable(t *testing.T) {
|
|
open := aMesh(t)
|
|
record, err := open.inventory.NodeByName(t.Context(), "anchor")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
// Sent nothing since numbering existed: what it would be sent is composed with zero, which is
|
|
// not on the wire, which is what it was actually sent.
|
|
if n, err := open.inventory.Sequence(t.Context(), record.ID); err != nil || n != 0 {
|
|
t.Fatalf("a fresh node reads sequence %d, %v", n, err)
|
|
}
|
|
first, err := open.inventory.NextSequence(t.Context(), record.ID)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
second, err := open.inventory.NextSequence(t.Context(), record.ID)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if first != 1 || second != 2 {
|
|
t.Fatalf("two sends were numbered %d and %d", first, second)
|
|
}
|
|
// And the read path sees the last one taken, so the comparison composes what was sent.
|
|
if n, err := open.inventory.Sequence(t.Context(), record.ID); err != nil || n != 2 {
|
|
t.Fatalf("after two sends the node reads sequence %d, %v", n, err)
|
|
}
|
|
// Another node counts on its own.
|
|
other, err := open.inventory.NodeByName(t.Context(), "laptop")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if n, err := open.inventory.NextSequence(t.Context(), other.ID); err != nil || n != 1 {
|
|
t.Fatalf("a second node's first send was numbered %d, %v", n, err)
|
|
}
|
|
}
|