test(daemon): cover coordinator send lock order
- commit
- b906d90bc4c0af74903c7e3a13d8dcd530328441
- author
- brice · · 2026-07-11 19:01 UTC
- parent
- 91e8bae
- signature
- GPG Verified
CD88F9E564E0102646FB6077A1A07C7C7C3E349D· arch-gpg Verified for the committer email
1 file · +54 -0
M internal/usecase/daemon/render_coordinator_test.go +54 -0
| @@ -313,6 +313,60 @@ func TestRenderCoordinatorUrgentDeadlineCannotBeExtended(t *testing.T) { | |||
| 313 | 313 | ||
| 314 | 314 | // --- ACK gating ---------------------------------------------------------------- | |
| 315 | 315 | ||
| 316 | + | func TestRenderCoordinatorAckReadinessReentersWithoutBlockingResize(t *testing.T) { | |
| 317 | + | owner := &attachedClient{} | |
| 318 | + | wakes := make(chan renderWake, 1) | |
| 319 | + | ackEntered := make(chan struct{}) | |
| 320 | + | resizeDone := make(chan uint64, 1) | |
| 321 | + | fireDone := make(chan struct{}) | |
| 322 | + | ||
| 323 | + | var rc *renderCoordinator | |
| 324 | + | rc = newRenderCoordinator(renderCoordinatorOptions{ | |
| 325 | + | ackReady: func() bool { | |
| 326 | + | close(ackEntered) | |
| 327 | + | // The readiness probe models the output send path reading coordinator | |
| 328 | + | // metadata after sendMu is held. It must never run under c.mu. | |
| 329 | + | _ = rc.resizeSnapshot() | |
| 330 | + | return true | |
| 331 | + | }, | |
| 332 | + | wake: func(w renderWake) { wakes <- w }, | |
| 333 | + | }) | |
| 334 | + | rc.attach(owner) | |
| 335 | + | rc.invalidate(renderInvalidation{class: invalidateOutput, producer: "render.go"}) | |
| 336 | + | ||
| 337 | + | go func() { | |
| 338 | + | rc.fire(1, false, true) | |
| 339 | + | close(fireDone) | |
| 340 | + | }() | |
| 341 | + | for range 4096 { | |
| 342 | + | select { | |
| 343 | + | case <-ackEntered: | |
| 344 | + | goto resize | |
| 345 | + | default: | |
| 346 | + | runtime.Gosched() | |
| 347 | + | } | |
| 348 | + | } | |
| 349 | + | t.Fatal("ack readiness was not evaluated") | |
| 350 | + | ||
| 351 | + | resize: | |
| 352 | + | go func() { resizeDone <- rc.recordResizeRequest(domain.Size{Cols: 120, Rows: 40}, owner) }() | |
| 353 | + | for range 4096 { | |
| 354 | + | select { | |
| 355 | + | case epoch := <-resizeDone: | |
| 356 | + | require.Equal(t, uint64(1), epoch) | |
| 357 | + | select { | |
| 358 | + | case <-fireDone: | |
| 359 | + | case <-wakes: | |
| 360 | + | t.Fatal("fire did not return after wake") | |
| 361 | + | } | |
| 362 | + | return | |
| 363 | + | default: | |
| 364 | + | runtime.Gosched() | |
| 365 | + | } | |
| 366 | + | } | |
| 367 | + | t.Fatal("ack readiness re-entry blocked resize metadata") | |
| 368 | + | } | |
| 369 | + | ||
| 316 | 370 | func TestRenderCoordinatorAckDoesNotBypassAnUnexpiredDeadline(t *testing.T) { | |
| 317 | 371 | h := newCoordinatorHarness(t) | |
| 318 | 372 | h.rc.invalidate(renderInvalidation{class: invalidateOutput, producer: "render.go"}) | |
| @@ -313,6 +313,60 @@ func TestRenderCoordinatorUrgentDeadlineCannotBeExtended(t *testing.T) { | |||||
| 313 | 313 | ||||
| 314 | // --- ACK gating ---------------------------------------------------------------- | 314 | // --- ACK gating ---------------------------------------------------------------- | ||
| 315 | 315 | ||||
| 316 | + | func TestRenderCoordinatorAckReadinessReentersWithoutBlockingResize(t *testing.T) { | |||
| 317 | + | owner := &attachedClient{} | |||
| 318 | + | wakes := make(chan renderWake, 1) | |||
| 319 | + | ackEntered := make(chan struct{}) | |||
| 320 | + | resizeDone := make(chan uint64, 1) | |||
| 321 | + | fireDone := make(chan struct{}) | |||
| 322 | + | ||||
| 323 | + | var rc *renderCoordinator | |||
| 324 | + | rc = newRenderCoordinator(renderCoordinatorOptions{ | |||
| 325 | + | ackReady: func() bool { | |||
| 326 | + | close(ackEntered) | |||
| 327 | + | // The readiness probe models the output send path reading coordinator | |||
| 328 | + | // metadata after sendMu is held. It must never run under c.mu. | |||
| 329 | + | _ = rc.resizeSnapshot() | |||
| 330 | + | return true | |||
| 331 | + | }, | |||
| 332 | + | wake: func(w renderWake) { wakes <- w }, | |||
| 333 | + | }) | |||
| 334 | + | rc.attach(owner) | |||
| 335 | + | rc.invalidate(renderInvalidation{class: invalidateOutput, producer: "render.go"}) | |||
| 336 | + | ||||
| 337 | + | go func() { | |||
| 338 | + | rc.fire(1, false, true) | |||
| 339 | + | close(fireDone) | |||
| 340 | + | }() | |||
| 341 | + | for range 4096 { | |||
| 342 | + | select { | |||
| 343 | + | case <-ackEntered: | |||
| 344 | + | goto resize | |||
| 345 | + | default: | |||
| 346 | + | runtime.Gosched() | |||
| 347 | + | } | |||
| 348 | + | } | |||
| 349 | + | t.Fatal("ack readiness was not evaluated") | |||
| 350 | + | ||||
| 351 | + | resize: | |||
| 352 | + | go func() { resizeDone <- rc.recordResizeRequest(domain.Size{Cols: 120, Rows: 40}, owner) }() | |||
| 353 | + | for range 4096 { | |||
| 354 | + | select { | |||
| 355 | + | case epoch := <-resizeDone: | |||
| 356 | + | require.Equal(t, uint64(1), epoch) | |||
| 357 | + | select { | |||
| 358 | + | case <-fireDone: | |||
| 359 | + | case <-wakes: | |||
| 360 | + | t.Fatal("fire did not return after wake") | |||
| 361 | + | } | |||
| 362 | + | return | |||
| 363 | + | default: | |||
| 364 | + | runtime.Gosched() | |||
| 365 | + | } | |||
| 366 | + | } | |||
| 367 | + | t.Fatal("ack readiness re-entry blocked resize metadata") | |||
| 368 | + | } | |||
| 369 | + | ||||
| 316 | func TestRenderCoordinatorAckDoesNotBypassAnUnexpiredDeadline(t *testing.T) { | 370 | func TestRenderCoordinatorAckDoesNotBypassAnUnexpiredDeadline(t *testing.T) { | ||
| 317 | h := newCoordinatorHarness(t) | 371 | h := newCoordinatorHarness(t) | ||
| 318 | h.rc.invalidate(renderInvalidation{class: invalidateOutput, producer: "render.go"}) | 372 | h.rc.invalidate(renderInvalidation{class: invalidateOutput, producer: "render.go"}) | ||