Skip to content

Commit c59569f

Browse files
committed
test(cli): stabilize process startup wait
1 parent c5d9c3e commit c59569f

2 files changed

Lines changed: 4 additions & 22 deletions

File tree

‎internal/cli/cp_ssh_unix_test.go‎

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"os"
1010
"os/exec"
1111
"path/filepath"
12-
"strconv"
1312
"strings"
1413
"syscall"
1514
"testing"
@@ -158,24 +157,7 @@ wait "$child"
158157
go func() {
159158
done <- copyOverResolvedSSH(ctx, SSHTarget{User: "alice", Host: "example.test", Port: "22"}, "./input", "SANDBOX:/tmp/input", false, &bytes.Buffer{}, &bytes.Buffer{})
160159
}()
161-
deadline := time.Now().Add(5 * time.Second)
162-
var childPID int
163-
for time.Now().Before(deadline) {
164-
data, err := os.ReadFile(pidPath)
165-
if err == nil {
166-
value := strings.TrimSpace(string(data))
167-
if value != "" {
168-
if parsed, parseErr := strconv.Atoi(value); parseErr == nil && parsed > 0 {
169-
childPID = parsed
170-
break
171-
}
172-
}
173-
}
174-
time.Sleep(20 * time.Millisecond)
175-
}
176-
if childPID == 0 {
177-
t.Fatal("rsync descendant did not start")
178-
}
160+
childPID := waitForPIDFile(t, pidPath)
179161
cancel()
180162
select {
181163
case err := <-done:

‎internal/cli/daemon_unix_test.go‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ func TestStopDaemonProcessKillsProcessGroup(t *testing.T) {
4444

4545
func waitForPIDFile(t *testing.T, path string) int {
4646
t.Helper()
47-
// The child fork/exec that writes this file can be slow under CI load, so
48-
// allow generous slack before declaring the descendant never started.
49-
deadline := time.Now().Add(5 * time.Second)
47+
// The child fork/exec that writes this file can be slow when the full package
48+
// runs in parallel under CI load, so allow generous startup slack.
49+
deadline := time.Now().Add(30 * time.Second)
5050
var lastErr error
5151
for {
5252
data, err := os.ReadFile(path)

0 commit comments

Comments
 (0)