Skip to content

Commit 2a6e225

Browse files
committed
[FAB-10493] run waits for container termination
Instead of returning after stop, wait for the containers to terminate. Change-Id: I8ebaef9808b2dff2d29155dac09bf8a19c04c180 Signed-off-by: Matthew Sykes <sykesmat@us.ibm.com>
1 parent 288a62c commit 2a6e225

File tree

5 files changed

+41
-23
lines changed

5 files changed

+41
-23
lines changed

integration/runner/couchdb.go

+13-7
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,15 @@ func (c *CouchDB) Run(sigCh <-chan os.Signal, ready chan<- struct{}) error {
140140
cancel()
141141
close(ready)
142142

143-
select {
144-
case err := <-containerExit:
145-
return err
146-
case <-sigCh:
147-
return c.Stop()
143+
for {
144+
select {
145+
case err := <-containerExit:
146+
return err
147+
case <-sigCh:
148+
if err := c.Stop(); err != nil {
149+
return err
150+
}
151+
}
148152
}
149153
}
150154

@@ -186,9 +190,11 @@ func (c *CouchDB) ready(ctx context.Context, addr string) <-chan struct{} {
186190
func (c *CouchDB) wait() <-chan error {
187191
exitCh := make(chan error)
188192
go func() {
189-
if _, err := c.Client.WaitContainer(c.containerID); err != nil {
190-
exitCh <- err
193+
exitCode, err := c.Client.WaitContainer(c.containerID)
194+
if err == nil {
195+
err = fmt.Errorf("couchdb: process exited with %d", exitCode)
191196
}
197+
exitCh <- err
192198
}()
193199

194200
return exitCh

integration/runner/couchdb_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ var _ = Describe("CouchDB Runner", func() {
195195

196196
By("terminating the container")
197197
process.Signal(syscall.SIGTERM)
198-
Eventually(process.Wait()).Should(Receive(BeNil()))
198+
Eventually(process.Wait()).Should(Receive())
199199
process = nil
200200

201201
Eventually(func() error {

integration/runner/kafka.go

+13-7
Original file line numberDiff line numberDiff line change
@@ -193,11 +193,15 @@ func (k *Kafka) Run(sigCh <-chan os.Signal, ready chan<- struct{}) error {
193193
cancel()
194194
close(ready)
195195

196-
select {
197-
case err := <-containerExit:
198-
return err
199-
case <-sigCh:
200-
return k.Stop()
196+
for {
197+
select {
198+
case err := <-containerExit:
199+
return err
200+
case <-sigCh:
201+
if err := k.Stop(); err != nil {
202+
return err
203+
}
204+
}
201205
}
202206
}
203207

@@ -248,9 +252,11 @@ func (k *Kafka) ready(ctx context.Context, addr string) <-chan struct{} {
248252
func (k *Kafka) wait() <-chan error {
249253
exitCh := make(chan error)
250254
go func() {
251-
if _, err := k.Client.WaitContainer(k.ContainerID); err != nil {
252-
exitCh <- err
255+
exitCode, err := k.Client.WaitContainer(k.ContainerID)
256+
if err == nil {
257+
err = fmt.Errorf("kafka: process exited with %d", exitCode)
253258
}
259+
exitCh <- err
254260
}()
255261

256262
return exitCh

integration/runner/kafka_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ var _ = Describe("Kafka Runner", func() {
112112

113113
By("terminating the container")
114114
process.Signal(syscall.SIGTERM)
115-
Eventually(process.Wait(), 2*time.Second).Should(Receive(BeNil()))
115+
Eventually(process.Wait(), 10*time.Second).Should(Receive())
116116

117117
_, err = client.InspectContainer("kafka1")
118118
Expect(err).To(MatchError("No such container: kafka1"))

integration/runner/zookeeper.go

+13-7
Original file line numberDiff line numberDiff line change
@@ -167,20 +167,26 @@ func (z *Zookeeper) Run(sigCh <-chan os.Signal, ready chan<- struct{}) error {
167167

168168
close(ready)
169169

170-
select {
171-
case err := <-containerExit:
172-
return err
173-
case <-sigCh:
174-
return z.Stop()
170+
for {
171+
select {
172+
case err := <-containerExit:
173+
return err
174+
case <-sigCh:
175+
if err := z.Stop(); err != nil {
176+
return err
177+
}
178+
}
175179
}
176180
}
177181

178182
func (z *Zookeeper) wait() <-chan error {
179183
exitCh := make(chan error)
180184
go func() {
181-
if _, err := z.Client.WaitContainer(z.containerID); err != nil {
182-
exitCh <- err
185+
exitCode, err := z.Client.WaitContainer(z.containerID)
186+
if err == nil {
187+
err = fmt.Errorf("zookeeper: process exited with %d", exitCode)
183188
}
189+
exitCh <- err
184190
}()
185191

186192
return exitCh

0 commit comments

Comments
 (0)