test(wayland): synchronize exclusion and prefetched frame assertions
Round-trip after a refused exclusion before inspecting server destruction stats. Wait for the prefetched successful frame before injecting failures so request scheduling cannot shift the expected failure count.
2 files · +6 -1
M internal/adapters/wayland/extensions_test.go +2 -0
| @@ -259,6 +259,8 @@ func TestRefusedExclusionDoesNotPinStoppedSession(t *testing.T) { | |||
| 259 | 259 | target := ports.Target{OutputID: firstOutput(t, s).ID} | |
| 260 | 260 | _, err := s.BeginExclusion(context.Background(), target) | |
| 261 | 261 | require.ErrorIs(t, err, ErrExclusionUnavailable) | |
| 262 | + | // BeginExclusion sends destroy but does not wait for the server to read it. | |
| 263 | + | require.NoError(t, s.roundtrip()) | |
| 262 | 264 | require.Equal(t, 1, srv.Stats().DestroyedExclusions, "the failed exclusion object is destroyed") | |
| 263 | 265 | srv.StopSessions() | |
| 264 | 266 | _, err = s.Capture(context.Background(), target) | |
| @@ -259,6 +259,8 @@ func TestRefusedExclusionDoesNotPinStoppedSession(t *testing.T) { | |||||
| 259 | target := ports.Target{OutputID: firstOutput(t, s).ID} | 259 | target := ports.Target{OutputID: firstOutput(t, s).ID} | ||
| 260 | _, err := s.BeginExclusion(context.Background(), target) | 260 | _, err := s.BeginExclusion(context.Background(), target) | ||
| 261 | require.ErrorIs(t, err, ErrExclusionUnavailable) | 261 | require.ErrorIs(t, err, ErrExclusionUnavailable) | ||
| 262 | + | // BeginExclusion sends destroy but does not wait for the server to read it. | |||
| 263 | + | require.NoError(t, s.roundtrip()) | |||
| 262 | require.Equal(t, 1, srv.Stats().DestroyedExclusions, "the failed exclusion object is destroyed") | 264 | require.Equal(t, 1, srv.Stats().DestroyedExclusions, "the failed exclusion object is destroyed") | ||
| 263 | srv.StopSessions() | 265 | srv.StopSessions() | ||
| 264 | _, err = s.Capture(context.Background(), target) | 266 | _, err = s.Capture(context.Background(), target) | ||
M internal/adapters/wayland/source_test.go +4 -1
| @@ -171,8 +171,11 @@ func TestFailedUnknownRepeatsLastFrame(t *testing.T) { | |||
| 171 | 171 | require.NoError(t, err, "recording continues") | |
| 172 | 172 | require.NotEqual(t, want, fresh.Pixels, "with a new frame") | |
| 173 | 173 | ||
| 174 | + | // Capture prefetched the next frame. Wait for the server to answer it | |
| 175 | + | // before arming failures, so it cannot consume the first injected failure. | |
| 176 | + | require.NoError(t, s.roundtrip()) | |
| 174 | 177 | srv.Fail(maxFrameAttempts, 0) | |
| 175 | - | // The capture started after the previous frame was answered before Fail. | |
| 178 | + | // Consume the successful prefetched frame before counting failures. | |
| 176 | 179 | _, err = s.Capture(context.Background(), target) | |
| 177 | 180 | require.NoError(t, err) | |
| 178 | 181 | for range maxFrameAttempts - 1 { | |
| @@ -171,8 +171,11 @@ func TestFailedUnknownRepeatsLastFrame(t *testing.T) { | |||||
| 171 | require.NoError(t, err, "recording continues") | 171 | require.NoError(t, err, "recording continues") | ||
| 172 | require.NotEqual(t, want, fresh.Pixels, "with a new frame") | 172 | require.NotEqual(t, want, fresh.Pixels, "with a new frame") | ||
| 173 | 173 | ||||
| 174 | + | // Capture prefetched the next frame. Wait for the server to answer it | |||
| 175 | + | // before arming failures, so it cannot consume the first injected failure. | |||
| 176 | + | require.NoError(t, s.roundtrip()) | |||
| 174 | srv.Fail(maxFrameAttempts, 0) | 177 | srv.Fail(maxFrameAttempts, 0) | ||
| 175 | - | // The capture started after the previous frame was answered before Fail. | 178 | + | // Consume the successful prefetched frame before counting failures. |
| 176 | _, err = s.Capture(context.Background(), target) | 179 | _, err = s.Capture(context.Background(), target) | ||
| 177 | require.NoError(t, err) | 180 | require.NoError(t, err) | ||
| 178 | for range maxFrameAttempts - 1 { | 181 | for range maxFrameAttempts - 1 { | ||