//go:build xturbo_poison package xturbo import "testing" // TestPoisonRetainedViews keeps Reply.Raw and Event.Tail past their callback // (a lifetime bug) and checks the runtime overwrote them. func TestPoisonRetainedViews(t *testing.T) { c, srv := dispatchConn(t) var raw, tail []byte h := Handler{ OnReply: func(r *Reply) { raw = r.Raw }, OnEvent: func(ev *Event) { tail = ev.Tail }, } stream := append(pktReply(1, 64), pktXGE(2, 1, 64)...) expect(t, c, 1, 3, 4) feed(t, c, srv, stream, &h) if len(raw) != 96 || len(tail) != 64 { t.Fatal(len(raw), len(tail)) } for _, p := range [][]byte{raw, tail} { for i, v := range p { if v != 0xa5 { t.Fatalf("retained byte %d = %#x, want poison", i, v) } } } // Growth poisons the old ring too. feed(t, c, srv, pktReply(3, 8), &h) old := c.rb feed(t, c, srv, pktReply(4, 200<<10), &h) if &old[0] == &c.rb[0] || old[0] != 0xa5 || old[len(old)-1] != 0xa5 { t.Fatal("old ring not poisoned after growth") } }