Skip to content

Commit 9d35774

Browse files
authored
Merge pull request moby#3804 from amurzeau/contrib3-dont-hang-on-process-early-exit
test: don't hang if a process doesn't run
2 parents e05d10f + 423a43b commit 9d35774

File tree

5 files changed

+11
-7
lines changed

5 files changed

+11
-7
lines changed

util/testutil/integration/containerd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ disabled_plugins = ["cri"]
185185
if err != nil {
186186
return nil, nil, err
187187
}
188-
if err := waitUnix(address, 10*time.Second); err != nil {
188+
if err := waitUnix(address, 10*time.Second, cmd); err != nil {
189189
ctdStop()
190190
return nil, nil, errors.Wrapf(err, "containerd did not start up: %s", formatLogs(cfg.Logs))
191191
}

util/testutil/integration/dockerd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ func (c moby) New(ctx context.Context, cfg *BackendConfig) (b Backend, cl func()
145145
}
146146
deferF.append(d.StopWithError)
147147

148-
if err := waitUnix(d.Sock(), 5*time.Second); err != nil {
148+
if err := waitUnix(d.Sock(), 5*time.Second, nil); err != nil {
149149
return nil, nil, errors.Errorf("dockerd did not start up: %q, %s", err, formatLogs(cfg.Logs))
150150
}
151151

util/testutil/integration/run.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ func runStargzSnapshotter(cfg *BackendConfig) (address string, cl func() error,
448448
if err != nil {
449449
return "", nil, err
450450
}
451-
if err = waitUnix(address, 10*time.Second); err != nil {
451+
if err = waitUnix(address, 10*time.Second, cmd); err != nil {
452452
snStop()
453453
return "", nil, errors.Wrapf(err, "containerd-stargz-grpc did not start up: %s", formatLogs(cfg.Logs))
454454
}

util/testutil/integration/sandbox.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ func runBuildkitd(ctx context.Context, conf *BackendConfig, args []string, logs
229229
}
230230
deferF.append(stop)
231231

232-
if err := waitUnix(address, 15*time.Second); err != nil {
232+
if err := waitUnix(address, 15*time.Second, cmd); err != nil {
233233
return "", nil, err
234234
}
235235

util/testutil/integration/util.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ func startCmd(cmd *exec.Cmd, logs map[string]*bytes.Buffer) (func() error, error
4444
stopped := make(chan struct{})
4545
stop := make(chan struct{})
4646
eg.Go(func() error {
47-
st, err := cmd.Process.Wait()
48-
fmt.Fprintf(cmd.Stderr, "> stopped %v %+v %v\n", time.Now(), st, st.ExitCode())
47+
err := cmd.Wait()
48+
fmt.Fprintf(cmd.Stderr, "> stopped %v %+v %v\n", time.Now(), cmd.ProcessState, cmd.ProcessState.ExitCode())
4949
close(stopped)
5050
select {
5151
case <-stop:
@@ -88,7 +88,7 @@ func setCmdLogs(cmd *exec.Cmd, logs map[string]*bytes.Buffer) {
8888
cmd.Stderr = &lockingWriter{Writer: b}
8989
}
9090

91-
func waitUnix(address string, d time.Duration) error {
91+
func waitUnix(address string, d time.Duration, cmd *exec.Cmd) error {
9292
address = strings.TrimPrefix(address, "unix://")
9393
addr, err := net.ResolveUnixAddr("unix", address)
9494
if err != nil {
@@ -98,6 +98,10 @@ func waitUnix(address string, d time.Duration) error {
9898
step := 50 * time.Millisecond
9999
i := 0
100100
for {
101+
if cmd != nil && cmd.ProcessState != nil {
102+
return errors.Errorf("process exited: %s", cmd.String())
103+
}
104+
101105
if conn, err := net.DialUnix("unix", nil, addr); err == nil {
102106
conn.Close()
103107
break

0 commit comments

Comments
 (0)