test: pin pause ordering, dropped notifications and zero-alloc commit
Cover Roundtrip/Bind queueing, ring order across a pause, unwatch with a queued notification, Close inside FDReady and v1 outputs. The alloc guard now includes wl_output.done; headless test and wire peer drop the countingHandler/isConnReset helpers.
- commit
- 5dd338336beae58b9671dea6e4c723d5c454c3c7
- author
- brice · · 2026-10-01 15:41 UTC
- parent
- 77d28a9
- signature
- GPG Verified
CD88F9E564E0102646FB6077A1A07C7C7C3E349D· arch-gpg Verified for the committer email
4 files · +89 -32
M alloc_test.go +10 -8
| @@ -12,16 +12,17 @@ import ( | |||
| 12 | 12 | ||
| 13 | 13 | // countingHandler is the measured system's input, not a double of a port: it | |
| 14 | 14 | // only counts, so the test sees the cost of the library alone. | |
| 15 | - | type countingHandler struct{ fdReady, added, removed, errs int } | |
| 15 | + | type countingHandler struct { | |
| 16 | + | neferclient.NopHandler | |
| 17 | + | fdReady, errs int | |
| 18 | + | } | |
| 16 | 19 | ||
| 17 | - | func (h *countingHandler) OutputAdded(*neferclient.Output) { h.added++ } | |
| 18 | - | func (h *countingHandler) OutputRemoved(uint32) { h.removed++ } | |
| 19 | - | func (h *countingHandler) FDReady(uint64) { h.fdReady++ } | |
| 20 | - | func (h *countingHandler) Error(error) { h.errs++ } | |
| 20 | + | func (h *countingHandler) FDReady(uint64) { h.fdReady++ } | |
| 21 | + | func (h *countingHandler) Error(error) { h.errs++ } | |
| 21 | 22 | ||
| 22 | 23 | // TestAllocDispatch measures the whole steady-state pipeline over a real | |
| 23 | 24 | // socketpair: wire frames in, reader decode, queue, Dispatch (output state | |
| 24 | - | // updates and a watched-fd notification with epoll re-arm). testing's | |
| 25 | + | // updates, an output commit and a watched-fd notification with epoll re-arm). testing's | |
| 25 | 26 | // AllocsPerRun counts every goroutine, so reader and epoll allocations are | |
| 26 | 27 | // included. | |
| 27 | 28 | func TestAllocDispatch(t *testing.T) { | |
| @@ -34,6 +35,7 @@ func TestAllocDispatch(t *testing.T) { | |||
| 34 | 35 | for i := range scaleEvents { | |
| 35 | 36 | batch = append(batch, frame(obj.id, 3, appendU32(nil, uint32(1+i%2)))...) | |
| 36 | 37 | } | |
| 38 | + | batch = append(batch, frame(obj.id, 2, nil)...) // wl_output.done: commitOutput runs | |
| 37 | 39 | efd, err := unix.Eventfd(0, unix.EFD_CLOEXEC|unix.EFD_NONBLOCK) | |
| 38 | 40 | require.NoError(t, err) | |
| 39 | 41 | defer unix.Close(efd) | |
| @@ -47,7 +49,7 @@ func TestAllocDispatch(t *testing.T) { | |||
| 47 | 49 | t.Fatal(err) | |
| 48 | 50 | } | |
| 49 | 51 | _, _ = unix.Write(efd, one[:]) | |
| 50 | - | for c.QueueLen() < scaleEvents+1 { | |
| 52 | + | for c.QueueLen() < scaleEvents+2 { | |
| 51 | 53 | runtime.Gosched() | |
| 52 | 54 | } | |
| 53 | 55 | _, _ = unix.Read(efd, drain[:]) | |
| @@ -58,7 +60,7 @@ func TestAllocDispatch(t *testing.T) { | |||
| 58 | 60 | step() // warm-up beyond AllocsPerRun's own: grow pools and buffers | |
| 59 | 61 | step() | |
| 60 | 62 | allocs := testing.AllocsPerRun(50, step) | |
| 61 | - | t.Logf("allocs per Dispatch of %d events: %v", scaleEvents+1, allocs) | |
| 63 | + | t.Logf("allocs per Dispatch of %d events: %v", scaleEvents+2, allocs) | |
| 62 | 64 | require.Zero(t, allocs) | |
| 63 | 65 | require.Positive(t, h.fdReady) | |
| 64 | 66 | require.Zero(t, h.errs) | |
| @@ -12,16 +12,17 @@ import ( | |||||
| 12 | 12 | ||||
| 13 | // countingHandler is the measured system's input, not a double of a port: it | 13 | // countingHandler is the measured system's input, not a double of a port: it | ||
| 14 | // only counts, so the test sees the cost of the library alone. | 14 | // only counts, so the test sees the cost of the library alone. | ||
| 15 | - | type countingHandler struct{ fdReady, added, removed, errs int } | 15 | + | type countingHandler struct { |
| 16 | + | neferclient.NopHandler | |||
| 17 | + | fdReady, errs int | |||
| 18 | + | } | |||
| 16 | 19 | ||||
| 17 | - | func (h *countingHandler) OutputAdded(*neferclient.Output) { h.added++ } | 20 | + | func (h *countingHandler) FDReady(uint64) { h.fdReady++ } |
| 18 | - | func (h *countingHandler) OutputRemoved(uint32) { h.removed++ } | 21 | + | func (h *countingHandler) Error(error) { h.errs++ } |
| 19 | - | func (h *countingHandler) FDReady(uint64) { h.fdReady++ } | |||
| 20 | - | func (h *countingHandler) Error(error) { h.errs++ } | |||
| 21 | 22 | ||||
| 22 | // TestAllocDispatch measures the whole steady-state pipeline over a real | 23 | // TestAllocDispatch measures the whole steady-state pipeline over a real | ||
| 23 | // socketpair: wire frames in, reader decode, queue, Dispatch (output state | 24 | // socketpair: wire frames in, reader decode, queue, Dispatch (output state | ||
| 24 | - | // updates and a watched-fd notification with epoll re-arm). testing's | 25 | + | // updates, an output commit and a watched-fd notification with epoll re-arm). testing's |
| 25 | // AllocsPerRun counts every goroutine, so reader and epoll allocations are | 26 | // AllocsPerRun counts every goroutine, so reader and epoll allocations are | ||
| 26 | // included. | 27 | // included. | ||
| 27 | func TestAllocDispatch(t *testing.T) { | 28 | func TestAllocDispatch(t *testing.T) { | ||
| @@ -34,6 +35,7 @@ func TestAllocDispatch(t *testing.T) { | |||||
| 34 | for i := range scaleEvents { | 35 | for i := range scaleEvents { | ||
| 35 | batch = append(batch, frame(obj.id, 3, appendU32(nil, uint32(1+i%2)))...) | 36 | batch = append(batch, frame(obj.id, 3, appendU32(nil, uint32(1+i%2)))...) | ||
| 36 | } | 37 | } | ||
| 38 | + | batch = append(batch, frame(obj.id, 2, nil)...) // wl_output.done: commitOutput runs | |||
| 37 | efd, err := unix.Eventfd(0, unix.EFD_CLOEXEC|unix.EFD_NONBLOCK) | 39 | efd, err := unix.Eventfd(0, unix.EFD_CLOEXEC|unix.EFD_NONBLOCK) | ||
| 38 | require.NoError(t, err) | 40 | require.NoError(t, err) | ||
| 39 | defer unix.Close(efd) | 41 | defer unix.Close(efd) | ||
| @@ -47,7 +49,7 @@ func TestAllocDispatch(t *testing.T) { | |||||
| 47 | t.Fatal(err) | 49 | t.Fatal(err) | ||
| 48 | } | 50 | } | ||
| 49 | _, _ = unix.Write(efd, one[:]) | 51 | _, _ = unix.Write(efd, one[:]) | ||
| 50 | - | for c.QueueLen() < scaleEvents+1 { | 52 | + | for c.QueueLen() < scaleEvents+2 { |
| 51 | runtime.Gosched() | 53 | runtime.Gosched() | ||
| 52 | } | 54 | } | ||
| 53 | _, _ = unix.Read(efd, drain[:]) | 55 | _, _ = unix.Read(efd, drain[:]) | ||
| @@ -58,7 +60,7 @@ func TestAllocDispatch(t *testing.T) { | |||||
| 58 | step() // warm-up beyond AllocsPerRun's own: grow pools and buffers | 60 | step() // warm-up beyond AllocsPerRun's own: grow pools and buffers | ||
| 59 | step() | 61 | step() | ||
| 60 | allocs := testing.AllocsPerRun(50, step) | 62 | allocs := testing.AllocsPerRun(50, step) | ||
| 61 | - | t.Logf("allocs per Dispatch of %d events: %v", scaleEvents+1, allocs) | 63 | + | t.Logf("allocs per Dispatch of %d events: %v", scaleEvents+2, allocs) |
| 62 | require.Zero(t, allocs) | 64 | require.Zero(t, allocs) | ||
| 63 | require.Positive(t, h.fdReady) | 65 | require.Positive(t, h.fdReady) | ||
| 64 | require.Zero(t, h.errs) | 66 | require.Zero(t, h.errs) | ||
M conn_test.go +75 -7
| @@ -61,7 +61,9 @@ func TestConnectInitialOutputs(t *testing.T) { | |||
| 61 | 61 | assert.Equal(t, uint32(4), srv.waitBound(7).version, "bound at min(announced, 4)") | |
| 62 | 62 | assert.Equal(t, uint32(2), srv.waitBound(9).version) | |
| 63 | 63 | ||
| 64 | - | // Setup events are applied silently: nothing is left for the Handler. | |
| 64 | + | // Setup events are applied silently: nothing is left for the Handler. The | |
| 65 | + | // roundtrip moves everything handled so far into the ring, so a leaked | |
| 66 | + | // setup event would reach the strict mock here. | |
| 65 | 67 | h := neferclientmocks.NewMockHandler(t) | |
| 66 | 68 | require.NoError(t, c.Roundtrip()) | |
| 67 | 69 | require.NoError(t, c.Dispatch(h)) | |
| @@ -118,15 +120,48 @@ func TestRingBackpressureKeepsOrder(t *testing.T) { | |||
| 118 | 120 | var buf []byte | |
| 119 | 121 | for i := 1; i <= total; i++ { | |
| 120 | 122 | buf = append(buf, frame(obj.id, 3, appendU32(nil, uint32(i)))...) | |
| 123 | + | buf = append(buf, frame(obj.id, 2, nil)...) | |
| 121 | 124 | } | |
| 122 | - | buf = append(buf, frame(obj.id, 2, nil)...) | |
| 123 | 125 | go srv.write(buf) | |
| 124 | 126 | waitFor(t, func() bool { return c.QueueLen() == neferclient.RingSize }, "full ring") | |
| 125 | 127 | ||
| 126 | 128 | // A pause (Roundtrip) must not deadlock against a producer blocked on the | |
| 127 | - | // full ring, and must not reorder what it held back. | |
| 129 | + | // full ring, and must not reorder what it held back: the visible scale | |
| 130 | + | // only ever grows, ending at total. | |
| 128 | 131 | require.NoError(t, c.Roundtrip()) | |
| 129 | - | dispatchUntil(t, c, nil, func() bool { return c.Outputs()[0].Scale == total }) | |
| 132 | + | prev := int32(0) | |
| 133 | + | dispatchUntil(t, c, nil, func() bool { | |
| 134 | + | got := c.Outputs()[0].Scale | |
| 135 | + | require.GreaterOrEqual(t, got, prev, "scale went backwards: events were reordered") | |
| 136 | + | prev = got | |
| 137 | + | return got == total | |
| 138 | + | }) | |
| 139 | + | } | |
| 140 | + | ||
| 141 | + | func TestRoundtripQueuesEventsForNextDispatch(t *testing.T) { | |
| 142 | + | c, srv := connectWire(t, []wireGlobal{{7, outputIface, 4}}, map[uint32]outputSpec{7: {"DP-1", 1, 100, 100}}) | |
| 143 | + | obj := srv.waitBound(7) | |
| 144 | + | srv.write(frame(obj.id, 3, appendU32(nil, 4))) // scale 4 | |
| 145 | + | srv.write(frame(obj.id, 2, nil)) // done | |
| 146 | + | require.NoError(t, c.Roundtrip()) | |
| 147 | + | // No Wake wait: the events handled during the roundtrip are already queued. | |
| 148 | + | require.NoError(t, c.Dispatch(nil)) | |
| 149 | + | assert.Equal(t, int32(4), c.Outputs()[0].Scale) | |
| 150 | + | } | |
| 151 | + | ||
| 152 | + | func TestBindQueuesEventsForNextDispatch(t *testing.T) { | |
| 153 | + | c, srv := connectWire(t, []wireGlobal{{7, outputIface, 4}, {3, wayland.CompositorInterface, 6}}, | |
| 154 | + | map[uint32]outputSpec{7: {"DP-1", 1, 100, 100}}) | |
| 155 | + | obj := srv.waitBound(7) | |
| 156 | + | srv.write(frame(obj.id, 3, appendU32(nil, 2))) | |
| 157 | + | srv.write(frame(obj.id, 2, nil)) | |
| 158 | + | // The bind pauses the reader; wait until the reader has the events so they | |
| 159 | + | // are handled during the pause or before it, never after Bind returns. | |
| 160 | + | waitFor(t, func() bool { return c.QueueLen() == 2 }, "events queued") | |
| 161 | + | _, _, err := c.Bind[*wayland.Compositor](wayland.CompositorInterface, 4, wayland.NewCompositor) | |
| 162 | + | require.NoError(t, err) | |
| 163 | + | require.NoError(t, c.Dispatch(nil)) | |
| 164 | + | assert.Equal(t, int32(2), c.Outputs()[0].Scale) | |
| 130 | 165 | } | |
| 131 | 166 | ||
| 132 | 167 | func waitFor(t *testing.T, cond func() bool, what string) { | |
| @@ -179,9 +214,42 @@ func TestWatchFD(t *testing.T) { | |||
| 179 | 214 | ||
| 180 | 215 | require.NoError(t, c.UnwatchFD(efd)) | |
| 181 | 216 | assert.Error(t, c.UnwatchFD(efd)) | |
| 182 | - | signal() | |
| 183 | - | require.NoError(t, c.Roundtrip()) | |
| 184 | - | require.NoError(t, c.Dispatch(h)) // would fail the mock's Times(2) | |
| 217 | + | } | |
| 218 | + | ||
| 219 | + | func TestUnwatchDropsQueuedNotification(t *testing.T) { | |
| 220 | + | c, _ := connectWire(t, nil, nil) | |
| 221 | + | efd, err := unix.Eventfd(0, unix.EFD_CLOEXEC|unix.EFD_NONBLOCK) | |
| 222 | + | require.NoError(t, err) | |
| 223 | + | defer unix.Close(efd) | |
| 224 | + | require.NoError(t, c.WatchFD(efd, 9)) | |
| 225 | + | one := [8]byte{1} | |
| 226 | + | _, err = unix.Write(efd, one[:]) | |
| 227 | + | require.NoError(t, err) | |
| 228 | + | waitFor(t, func() bool { return c.QueueLen() > 0 }, "queued fd notification") | |
| 229 | + | require.NoError(t, c.UnwatchFD(efd)) | |
| 230 | + | h := neferclientmocks.NewMockHandler(t) // no FDReady expectation: a call fails | |
| 231 | + | require.NoError(t, c.Dispatch(h)) | |
| 232 | + | } | |
| 233 | + | ||
| 234 | + | func TestCloseInsideFDReady(t *testing.T) { | |
| 235 | + | c, _ := connectWire(t, nil, nil) | |
| 236 | + | efd, err := unix.Eventfd(0, unix.EFD_CLOEXEC|unix.EFD_NONBLOCK) | |
| 237 | + | require.NoError(t, err) | |
| 238 | + | defer unix.Close(efd) | |
| 239 | + | require.NoError(t, c.WatchFD(efd, 1)) | |
| 240 | + | h := neferclientmocks.NewMockHandler(t) // Error must not be called after Close | |
| 241 | + | h.EXPECT().FDReady(uint64(1)).Run(func(uint64) { require.NoError(t, c.Close()) }).Once() | |
| 242 | + | one := [8]byte{1} | |
| 243 | + | _, _ = unix.Write(efd, one[:]) | |
| 244 | + | waitFor(t, func() bool { return c.QueueLen() > 0 }, "queued fd notification") | |
| 245 | + | assert.ErrorIs(t, c.Dispatch(h), neferclient.ErrClosed) | |
| 246 | + | } | |
| 247 | + | ||
| 248 | + | func TestOutputVersionOneIgnored(t *testing.T) { | |
| 249 | + | c, _ := connectWire(t, []wireGlobal{{5, outputIface, 1}, {7, outputIface, 2}}, | |
| 250 | + | map[uint32]outputSpec{5: {"old", 1, 10, 10}, 7: {"DP-1", 1, 100, 100}}) | |
| 251 | + | require.Len(t, c.Outputs(), 1) | |
| 252 | + | assert.Equal(t, uint32(7), c.Outputs()[0].Global) | |
| 185 | 253 | } | |
| 186 | 254 | ||
| 187 | 255 | func TestUnwatchInsideHandler(t *testing.T) { | |
| @@ -61,7 +61,9 @@ func TestConnectInitialOutputs(t *testing.T) { | |||||
| 61 | assert.Equal(t, uint32(4), srv.waitBound(7).version, "bound at min(announced, 4)") | 61 | assert.Equal(t, uint32(4), srv.waitBound(7).version, "bound at min(announced, 4)") | ||
| 62 | assert.Equal(t, uint32(2), srv.waitBound(9).version) | 62 | assert.Equal(t, uint32(2), srv.waitBound(9).version) | ||
| 63 | 63 | ||||
| 64 | - | // Setup events are applied silently: nothing is left for the Handler. | 64 | + | // Setup events are applied silently: nothing is left for the Handler. The |
| 65 | + | // roundtrip moves everything handled so far into the ring, so a leaked | |||
| 66 | + | // setup event would reach the strict mock here. | |||
| 65 | h := neferclientmocks.NewMockHandler(t) | 67 | h := neferclientmocks.NewMockHandler(t) | ||
| 66 | require.NoError(t, c.Roundtrip()) | 68 | require.NoError(t, c.Roundtrip()) | ||
| 67 | require.NoError(t, c.Dispatch(h)) | 69 | require.NoError(t, c.Dispatch(h)) | ||
| @@ -118,15 +120,48 @@ func TestRingBackpressureKeepsOrder(t *testing.T) { | |||||
| 118 | var buf []byte | 120 | var buf []byte | ||
| 119 | for i := 1; i <= total; i++ { | 121 | for i := 1; i <= total; i++ { | ||
| 120 | buf = append(buf, frame(obj.id, 3, appendU32(nil, uint32(i)))...) | 122 | buf = append(buf, frame(obj.id, 3, appendU32(nil, uint32(i)))...) | ||
| 123 | + | buf = append(buf, frame(obj.id, 2, nil)...) | |||
| 121 | } | 124 | } | ||
| 122 | - | buf = append(buf, frame(obj.id, 2, nil)...) | |||
| 123 | go srv.write(buf) | 125 | go srv.write(buf) | ||
| 124 | waitFor(t, func() bool { return c.QueueLen() == neferclient.RingSize }, "full ring") | 126 | waitFor(t, func() bool { return c.QueueLen() == neferclient.RingSize }, "full ring") | ||
| 125 | 127 | ||||
| 126 | // A pause (Roundtrip) must not deadlock against a producer blocked on the | 128 | // A pause (Roundtrip) must not deadlock against a producer blocked on the | ||
| 127 | - | // full ring, and must not reorder what it held back. | 129 | + | // full ring, and must not reorder what it held back: the visible scale |
| 130 | + | // only ever grows, ending at total. | |||
| 128 | require.NoError(t, c.Roundtrip()) | 131 | require.NoError(t, c.Roundtrip()) | ||
| 129 | - | dispatchUntil(t, c, nil, func() bool { return c.Outputs()[0].Scale == total }) | 132 | + | prev := int32(0) |
| 133 | + | dispatchUntil(t, c, nil, func() bool { | |||
| 134 | + | got := c.Outputs()[0].Scale | |||
| 135 | + | require.GreaterOrEqual(t, got, prev, "scale went backwards: events were reordered") | |||
| 136 | + | prev = got | |||
| 137 | + | return got == total | |||
| 138 | + | }) | |||
| 139 | + | } | |||
| 140 | + | ||||
| 141 | + | func TestRoundtripQueuesEventsForNextDispatch(t *testing.T) { | |||
| 142 | + | c, srv := connectWire(t, []wireGlobal{{7, outputIface, 4}}, map[uint32]outputSpec{7: {"DP-1", 1, 100, 100}}) | |||
| 143 | + | obj := srv.waitBound(7) | |||
| 144 | + | srv.write(frame(obj.id, 3, appendU32(nil, 4))) // scale 4 | |||
| 145 | + | srv.write(frame(obj.id, 2, nil)) // done | |||
| 146 | + | require.NoError(t, c.Roundtrip()) | |||
| 147 | + | // No Wake wait: the events handled during the roundtrip are already queued. | |||
| 148 | + | require.NoError(t, c.Dispatch(nil)) | |||
| 149 | + | assert.Equal(t, int32(4), c.Outputs()[0].Scale) | |||
| 150 | + | } | |||
| 151 | + | ||||
| 152 | + | func TestBindQueuesEventsForNextDispatch(t *testing.T) { | |||
| 153 | + | c, srv := connectWire(t, []wireGlobal{{7, outputIface, 4}, {3, wayland.CompositorInterface, 6}}, | |||
| 154 | + | map[uint32]outputSpec{7: {"DP-1", 1, 100, 100}}) | |||
| 155 | + | obj := srv.waitBound(7) | |||
| 156 | + | srv.write(frame(obj.id, 3, appendU32(nil, 2))) | |||
| 157 | + | srv.write(frame(obj.id, 2, nil)) | |||
| 158 | + | // The bind pauses the reader; wait until the reader has the events so they | |||
| 159 | + | // are handled during the pause or before it, never after Bind returns. | |||
| 160 | + | waitFor(t, func() bool { return c.QueueLen() == 2 }, "events queued") | |||
| 161 | + | _, _, err := c.Bind[*wayland.Compositor](wayland.CompositorInterface, 4, wayland.NewCompositor) | |||
| 162 | + | require.NoError(t, err) | |||
| 163 | + | require.NoError(t, c.Dispatch(nil)) | |||
| 164 | + | assert.Equal(t, int32(2), c.Outputs()[0].Scale) | |||
| 130 | } | 165 | } | ||
| 131 | 166 | ||||
| 132 | func waitFor(t *testing.T, cond func() bool, what string) { | 167 | func waitFor(t *testing.T, cond func() bool, what string) { | ||
| @@ -179,9 +214,42 @@ func TestWatchFD(t *testing.T) { | |||||
| 179 | 214 | ||||
| 180 | require.NoError(t, c.UnwatchFD(efd)) | 215 | require.NoError(t, c.UnwatchFD(efd)) | ||
| 181 | assert.Error(t, c.UnwatchFD(efd)) | 216 | assert.Error(t, c.UnwatchFD(efd)) | ||
| 182 | - | signal() | 217 | + | } |
| 183 | - | require.NoError(t, c.Roundtrip()) | 218 | + | |
| 184 | - | require.NoError(t, c.Dispatch(h)) // would fail the mock's Times(2) | 219 | + | func TestUnwatchDropsQueuedNotification(t *testing.T) { |
| 220 | + | c, _ := connectWire(t, nil, nil) | |||
| 221 | + | efd, err := unix.Eventfd(0, unix.EFD_CLOEXEC|unix.EFD_NONBLOCK) | |||
| 222 | + | require.NoError(t, err) | |||
| 223 | + | defer unix.Close(efd) | |||
| 224 | + | require.NoError(t, c.WatchFD(efd, 9)) | |||
| 225 | + | one := [8]byte{1} | |||
| 226 | + | _, err = unix.Write(efd, one[:]) | |||
| 227 | + | require.NoError(t, err) | |||
| 228 | + | waitFor(t, func() bool { return c.QueueLen() > 0 }, "queued fd notification") | |||
| 229 | + | require.NoError(t, c.UnwatchFD(efd)) | |||
| 230 | + | h := neferclientmocks.NewMockHandler(t) // no FDReady expectation: a call fails | |||
| 231 | + | require.NoError(t, c.Dispatch(h)) | |||
| 232 | + | } | |||
| 233 | + | ||||
| 234 | + | func TestCloseInsideFDReady(t *testing.T) { | |||
| 235 | + | c, _ := connectWire(t, nil, nil) | |||
| 236 | + | efd, err := unix.Eventfd(0, unix.EFD_CLOEXEC|unix.EFD_NONBLOCK) | |||
| 237 | + | require.NoError(t, err) | |||
| 238 | + | defer unix.Close(efd) | |||
| 239 | + | require.NoError(t, c.WatchFD(efd, 1)) | |||
| 240 | + | h := neferclientmocks.NewMockHandler(t) // Error must not be called after Close | |||
| 241 | + | h.EXPECT().FDReady(uint64(1)).Run(func(uint64) { require.NoError(t, c.Close()) }).Once() | |||
| 242 | + | one := [8]byte{1} | |||
| 243 | + | _, _ = unix.Write(efd, one[:]) | |||
| 244 | + | waitFor(t, func() bool { return c.QueueLen() > 0 }, "queued fd notification") | |||
| 245 | + | assert.ErrorIs(t, c.Dispatch(h), neferclient.ErrClosed) | |||
| 246 | + | } | |||
| 247 | + | ||||
| 248 | + | func TestOutputVersionOneIgnored(t *testing.T) { | |||
| 249 | + | c, _ := connectWire(t, []wireGlobal{{5, outputIface, 1}, {7, outputIface, 2}}, | |||
| 250 | + | map[uint32]outputSpec{5: {"old", 1, 10, 10}, 7: {"DP-1", 1, 100, 100}}) | |||
| 251 | + | require.Len(t, c.Outputs(), 1) | |||
| 252 | + | assert.Equal(t, uint32(7), c.Outputs()[0].Global) | |||
| 185 | } | 253 | } | ||
| 186 | 254 | ||||
| 187 | func TestUnwatchInsideHandler(t *testing.T) { | 255 | func TestUnwatchInsideHandler(t *testing.T) { | ||
M headless_test.go +1 -2
| @@ -108,11 +108,10 @@ func TestHeadlessConnect(t *testing.T) { | |||
| 108 | 108 | ||
| 109 | 109 | // The compositor creates its virtual output just after the socket appears, | |
| 110 | 110 | // so it may arrive through OutputAdded instead of being there at Connect. | |
| 111 | - | h := &countingHandler{} | |
| 112 | 111 | for len(c.Outputs()) == 0 { | |
| 113 | 112 | select { | |
| 114 | 113 | case <-c.Wake(): | |
| 115 | - | require.NoError(t, c.Dispatch(h)) | |
| 114 | + | require.NoError(t, c.Dispatch(nil)) | |
| 116 | 115 | case <-ctx.Done(): | |
| 117 | 116 | t.Fatal("no output announced") | |
| 118 | 117 | } | |
| @@ -108,11 +108,10 @@ func TestHeadlessConnect(t *testing.T) { | |||||
| 108 | 108 | ||||
| 109 | // The compositor creates its virtual output just after the socket appears, | 109 | // The compositor creates its virtual output just after the socket appears, | ||
| 110 | // so it may arrive through OutputAdded instead of being there at Connect. | 110 | // so it may arrive through OutputAdded instead of being there at Connect. | ||
| 111 | - | h := &countingHandler{} | |||
| 112 | for len(c.Outputs()) == 0 { | 111 | for len(c.Outputs()) == 0 { | ||
| 113 | select { | 112 | select { | ||
| 114 | case <-c.Wake(): | 113 | case <-c.Wake(): | ||
| 115 | - | require.NoError(t, c.Dispatch(h)) | 114 | + | require.NoError(t, c.Dispatch(nil)) |
| 116 | case <-ctx.Done(): | 115 | case <-ctx.Done(): | ||
| 117 | t.Fatal("no output announced") | 116 | t.Fatal("no output announced") | ||
| 118 | } | 117 | } | ||
M wire_test.go +3 -15
| @@ -3,6 +3,7 @@ package neferclient_test | |||
| 3 | 3 | import ( | |
| 4 | 4 | "context" | |
| 5 | 5 | "encoding/binary" | |
| 6 | + | "errors" | |
| 6 | 7 | "io" | |
| 7 | 8 | "net" | |
| 8 | 9 | "os" | |
| @@ -108,21 +109,8 @@ func (s *wireServer) write(b []byte) { | |||
| 108 | 109 | } | |
| 109 | 110 | ||
| 110 | 111 | func isClosed(err error) bool { | |
| 111 | - | return err != nil && (err == io.EOF || err == net.ErrClosed || os.IsTimeout(err) || isConnReset(err)) | |
| 112 | - | } | |
| 113 | - | ||
| 114 | - | func isConnReset(err error) bool { | |
| 115 | - | for err != nil { | |
| 116 | - | if err == unix.EPIPE || err == unix.ECONNRESET { | |
| 117 | - | return true | |
| 118 | - | } | |
| 119 | - | u, ok := err.(interface{ Unwrap() error }) | |
| 120 | - | if !ok { | |
| 121 | - | return false | |
| 122 | - | } | |
| 123 | - | err = u.Unwrap() | |
| 124 | - | } | |
| 125 | - | return false | |
| 112 | + | return errors.Is(err, io.EOF) || errors.Is(err, net.ErrClosed) || errors.Is(err, os.ErrDeadlineExceeded) || | |
| 113 | + | errors.Is(err, unix.EPIPE) || errors.Is(err, unix.ECONNRESET) | |
| 126 | 114 | } | |
| 127 | 115 | ||
| 128 | 116 | func (s *wireServer) serve() { | |
| @@ -3,6 +3,7 @@ package neferclient_test | |||||
| 3 | import ( | 3 | import ( | ||
| 4 | "context" | 4 | "context" | ||
| 5 | "encoding/binary" | 5 | "encoding/binary" | ||
| 6 | + | "errors" | |||
| 6 | "io" | 7 | "io" | ||
| 7 | "net" | 8 | "net" | ||
| 8 | "os" | 9 | "os" | ||
| @@ -108,21 +109,8 @@ func (s *wireServer) write(b []byte) { | |||||
| 108 | } | 109 | } | ||
| 109 | 110 | ||||
| 110 | func isClosed(err error) bool { | 111 | func isClosed(err error) bool { | ||
| 111 | - | return err != nil && (err == io.EOF || err == net.ErrClosed || os.IsTimeout(err) || isConnReset(err)) | 112 | + | return errors.Is(err, io.EOF) || errors.Is(err, net.ErrClosed) || errors.Is(err, os.ErrDeadlineExceeded) || |
| 112 | - | } | 113 | + | errors.Is(err, unix.EPIPE) || errors.Is(err, unix.ECONNRESET) |
| 113 | - | ||||
| 114 | - | func isConnReset(err error) bool { | |||
| 115 | - | for err != nil { | |||
| 116 | - | if err == unix.EPIPE || err == unix.ECONNRESET { | |||
| 117 | - | return true | |||
| 118 | - | } | |||
| 119 | - | u, ok := err.(interface{ Unwrap() error }) | |||
| 120 | - | if !ok { | |||
| 121 | - | return false | |||
| 122 | - | } | |||
| 123 | - | err = u.Unwrap() | |||
| 124 | - | } | |||
| 125 | - | return false | |||
| 126 | } | 114 | } | ||
| 127 | 115 | ||||
| 128 | func (s *wireServer) serve() { | 116 | func (s *wireServer) serve() { | ||