1package headless
2
3import (
4 "testing"
5
6 "github.com/bnema/neferwl/internal/ports"
7 "github.com/stretchr/testify/require"
8)
9
10// Steady-state flip reporting: the Shows snapshot is reused while it does not
11// change, and a changed one never mutates what an earlier flip handed out.
12func TestFlipShowsAllocations(t *testing.T) {
13 var f flipShows
14 scene := ports.Scene{OutputWidth: 10, OutputHeight: 10, Windows: []ports.SceneWindow{{ID: 1, Rect: ports.Rect{W: 10, H: 10}}}}
15 contents := map[ports.WindowID]ports.SurfaceContent{1: {ID: 1, Seq: 1}, 2: {ID: 2, Seq: 2}}
16 first := f.flipInfo(scene, contents, nil)
17 require.Equal(t, map[ports.WindowID]uint64{1: 1}, first.Shows)
18
19 require.Zero(t, testing.AllocsPerRun(100, func() { f.of(scene, contents, nil) }), "unchanged shows")
20 // The FlipInfo is the one allocation left: the sink's merge writes into it.
21 require.LessOrEqual(t, testing.AllocsPerRun(100, func() { f.flipInfo(scene, contents, nil) }), 1.0, "flip report")
22
23 contents[1] = ports.SurfaceContent{ID: 1, Seq: 3}
24 second := f.flipInfo(scene, contents, nil)
25 require.Equal(t, map[ports.WindowID]uint64{1: 1}, first.Shows, "an earlier snapshot is immutable")
26 require.Equal(t, map[ports.WindowID]uint64{1: 3}, second.Shows)
27 require.NotSame(t, first, second)
28}