Fix idle timer review issues
This commit is contained in:
@@ -57,6 +57,50 @@ func TestParentExitKillsDescendants(t *testing.T) {
|
||||
waitUntilNotLive(t, grandchild)
|
||||
}
|
||||
|
||||
// TestSpawnInstallsIdleDetectionBeforePublish guarantees that a child
|
||||
// spawned with SpawnSpec.IdleDetection has its resolved config visible
|
||||
// the instant the child appears in s.children — closing the race where
|
||||
// the classifier could read c.idleDetection before the launcher set it.
|
||||
func TestSpawnInstallsIdleDetectionBeforePublish(t *testing.T) {
|
||||
sess := NewSession(t.TempDir(), "test")
|
||||
want := &resolvedIdleDetection{
|
||||
strategy: StrategyOSCTitleStability,
|
||||
idleThresholdMS: 9999,
|
||||
}
|
||||
c, err := sess.Spawn(SpawnSpec{
|
||||
Kind: KindCommand,
|
||||
Argv: []string{"sh", "-c", "sleep 30"},
|
||||
IdleDetection: want,
|
||||
}, 80, 24)
|
||||
if err != nil {
|
||||
t.Fatalf("spawn: %v", err)
|
||||
}
|
||||
defer func() { _ = c.signal(syscall.SIGTERM) }()
|
||||
|
||||
// Read back via the same access path the classifier uses
|
||||
// (sess.Children) so the test fails if the field is set only
|
||||
// AFTER the child is published.
|
||||
var found *Child
|
||||
for _, ch := range sess.Children() {
|
||||
if ch.ID == c.ID {
|
||||
found = ch
|
||||
break
|
||||
}
|
||||
}
|
||||
if found == nil {
|
||||
t.Fatalf("spawned child %s not in Children()", c.ID)
|
||||
}
|
||||
if found.idleDetection == nil {
|
||||
t.Fatalf("idleDetection nil after Spawn returned")
|
||||
}
|
||||
if found.idleDetection.strategy != StrategyOSCTitleStability {
|
||||
t.Fatalf("strategy: got %q want %q", found.idleDetection.strategy, StrategyOSCTitleStability)
|
||||
}
|
||||
if found.idleDetection.idleThresholdMS != 9999 {
|
||||
t.Fatalf("threshold: got %d want 9999", found.idleDetection.idleThresholdMS)
|
||||
}
|
||||
}
|
||||
|
||||
func waitUntilLive(t *testing.T, c *Child) {
|
||||
t.Helper()
|
||||
deadline := time.Now().Add(5 * time.Second)
|
||||
|
||||
Reference in New Issue
Block a user