ed5085ab6b
Rewrite TestFakeSourceEmits to synchronize through a channel (it now asserts emission instead of racing on a shared slice and discarding it). Skip the live X11 smoke test under -race: xgbutil's event loop has an internal Quit/Quitting race on shutdown that is never reached in production (Watch runs under a never-cancelled context.Background()). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
44 lines
1.2 KiB
Go
44 lines
1.2 KiB
Go
//go:build linux
|
|
|
|
package evidence
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestX11SourceEmitsWhenDisplaySet(t *testing.T) {
|
|
if os.Getenv("DISPLAY") == "" {
|
|
t.Skip("no DISPLAY; skipping live X11 smoke test")
|
|
}
|
|
if raceDetectorEnabled {
|
|
// xgbutil's event loop has an internal Quit/Quitting data race on its
|
|
// shutdown flag (xevent.Quit vs xevent.Quitting). It is in the library,
|
|
// not our code, and is never reached in production: the daemon's Watch
|
|
// runs under context.Background(), which is never cancelled. Skip under
|
|
// -race so the rest of the suite stays clean.
|
|
t.Skip("xgbutil event loop races on shutdown under -race; not exercised in production")
|
|
}
|
|
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
|
|
defer cancel()
|
|
|
|
got := make(chan WindowSnapshot, 1)
|
|
go NewSource().Watch(ctx, func(s WindowSnapshot) {
|
|
select {
|
|
case got <- s:
|
|
default:
|
|
}
|
|
})
|
|
|
|
select {
|
|
case snap := <-got:
|
|
// Either a real window or a clean Unavailable — both are valid; we only
|
|
// assert the sensor produced an observation without panicking.
|
|
t.Logf("first snapshot: %+v", snap)
|
|
case <-ctx.Done():
|
|
t.Fatal("x11 source emitted no snapshot within timeout")
|
|
}
|
|
}
|