Skip to content

Commit 727a9fc

Browse files
committed
Wait for the container to be removed
Signed-off-by: akram <akram@il.ibm.com>
1 parent 7c08b22 commit 727a9fc

File tree

3 files changed

+13
-12
lines changed

3 files changed

+13
-12
lines changed

platform/view/services/storage/driver/sql/postgres/binding_test.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ package postgres
88

99
import (
1010
"testing"
11-
"time"
1211

1312
testing2 "github.com/hyperledger-labs/fabric-smart-client/platform/view/services/storage/driver/common/testing"
1413
"github.com/hyperledger-labs/fabric-smart-client/platform/view/services/storage/driver/sql/common"
@@ -17,9 +16,6 @@ import (
1716
)
1817

1918
func newBindingStoreForTests(t *testing.T) (func(), *BindingStore) {
20-
// When running this test together with other tests; it may happen that a container instance is still running
21-
// we give this test a slow start ...
22-
time.Sleep(10 * time.Second)
2319
t.Log("starting postgres")
2420
terminate, pgConnStr, err := StartPostgres(t, false)
2521
require.NoError(t, err)
@@ -34,16 +30,12 @@ func newBindingStoreForTests(t *testing.T) (func(), *BindingStore) {
3430
}
3531

3632
func TestPutBindingsMultipleEphemeralsPostgres(t *testing.T) {
37-
// if this test runs after another postgres test, wait a bit to let the previous connections close
38-
time.Sleep(10 * time.Second)
3933
terminate, db := newBindingStoreForTests(t)
4034
defer terminate()
4135
common.TestPutBindingsMultipleEphemeralsCommon(t, db.BindingStore)
4236
}
4337

4438
func TestManyManyPutBindingsPostgres(t *testing.T) {
45-
// if this test runs after another postgres test, wait a bit to let the previous connections close
46-
time.Sleep(10 * time.Second)
4739
terminate, db := newBindingStoreForTests(t)
4840
defer terminate()
4941
common.TestManyManyPutBindingsCommon(t, db.BindingStore)

platform/view/services/storage/driver/sql/postgres/test_utils.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"strings"
1717
"time"
1818

19+
"github.com/containerd/errdefs"
1920
"github.com/docker/docker/api/types/container"
2021
"github.com/docker/docker/client"
2122
"github.com/docker/go-connections/nat"
@@ -196,6 +197,18 @@ func startPostgresWithLogger(c ContainerConfig, t Logger, printLogs bool) (func(
196197
closeFunc := func() {
197198
t.Log("removing postgres container")
198199
_ = cli.ContainerRemove(ctx, resp.ID, container.RemoveOptions{RemoveVolumes: true, Force: true})
200+
// Wait until the container is gone
201+
for {
202+
_, err := cli.ContainerInspect(ctx, resp.ID)
203+
if err != nil {
204+
if errdefs.IsNotFound(err) {
205+
break // container fully removed
206+
}
207+
t.Log("unexpected error: %v", err)
208+
}
209+
time.Sleep(100 * time.Millisecond)
210+
}
211+
t.Log("container fully removed")
199212
}
200213
if err := cli.ContainerStart(ctx, resp.ID, container.StartOptions{}); err != nil {
201214
closeFunc()

platform/view/services/storage/kvs/kvs_test.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,10 +176,6 @@ func TestSQLiteKVS(t *testing.T) {
176176
}
177177

178178
func TestPostgresKVS(t *testing.T) {
179-
// When running this test together with other tests; it may happen that a container instance is still running
180-
// we give this test a slow start ...
181-
time.Sleep(10 * time.Second)
182-
183179
t.Log("starting postgres")
184180
terminate, pgConnStr, err := postgres2.StartPostgres(t, false)
185181
if err != nil {

0 commit comments

Comments
 (0)