Skip to content

Commit 350ddf6

Browse files
authored
Merge pull request sorintlab#763 from sgotti/tests_store_context_timeout
tests: use test store context timeout
2 parents fc6e568 + 79ea0fc commit 350ddf6

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

tests/integration/utils.go

+8-4
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ const (
5353

5454
var (
5555
defaultPGParameters = cluster.PGParameters{"log_destination": "stderr", "logging_collector": "false"}
56+
57+
defaultStoreTimeout = 1 * time.Second
5658
)
5759

5860
var curPort = MinPort
@@ -806,7 +808,6 @@ func (tp *TestProxy) WaitListening(timeout time.Duration) error {
806808
if err == nil {
807809
return nil
808810
}
809-
tp.t.Logf("tp: %v, error: %v", tp.uid, err)
810811
time.Sleep(sleepInterval)
811812
}
812813
return fmt.Errorf("timeout")
@@ -824,7 +825,6 @@ func (tp *TestProxy) WaitNotListening(timeout time.Duration) error {
824825
if err != nil {
825826
return nil
826827
}
827-
tp.t.Logf("tp: %v, error: %v", tp.uid, err)
828828
time.Sleep(sleepInterval)
829829
}
830830
return fmt.Errorf("timeout")
@@ -1073,7 +1073,9 @@ func NewTestConsul(t *testing.T, dir string, a ...string) (*TestStore, error) {
10731073
func (ts *TestStore) WaitUp(timeout time.Duration) error {
10741074
start := time.Now()
10751075
for time.Now().Add(-timeout).Before(start) {
1076-
_, err := ts.store.Get(context.TODO(), "anykey")
1076+
ctx, cancel := context.WithTimeout(context.Background(), defaultStoreTimeout)
1077+
_, err := ts.store.Get(ctx, "anykey")
1078+
cancel()
10771079
ts.t.Logf("err: %v", err)
10781080
if err != nil && err == store.ErrKeyNotFound {
10791081
return nil
@@ -1090,7 +1092,9 @@ func (ts *TestStore) WaitUp(timeout time.Duration) error {
10901092
func (ts *TestStore) WaitDown(timeout time.Duration) error {
10911093
start := time.Now()
10921094
for time.Now().Add(-timeout).Before(start) {
1093-
_, err := ts.store.Get(context.TODO(), "anykey")
1095+
ctx, cancel := context.WithTimeout(context.Background(), defaultStoreTimeout)
1096+
_, err := ts.store.Get(ctx, "anykey")
1097+
cancel()
10941098
if err != nil && err != store.ErrKeyNotFound {
10951099
return nil
10961100
}

0 commit comments

Comments
 (0)