@@ -2,13 +2,23 @@ package testutils
22
33import (
44 "fmt"
5+ "os"
56 "testing"
67 "time"
78
89 "github.com/docker/libkv/store"
910 "github.com/stretchr/testify/assert"
1011)
1112
13+ func getShortTimeout () time.Duration {
14+ if timeout := os .Getenv ("LIBKV_TEST_SHORT_TIMEOUT" ); timeout != "" {
15+ if timeout , err := time .ParseDuration (timeout ); err != nil {
16+ return timeout
17+ }
18+ }
19+ return 5 * time .Second
20+ }
21+
1222// RunTestCommon tests the minimal required APIs which
1323// should be supported by all K/V backends
1424func RunTestCommon (t * testing.T , kv store.Store ) {
@@ -184,7 +194,7 @@ func testWatch(t *testing.T, kv store.Store) {
184194 if eventCount >= 4 {
185195 return
186196 }
187- case <- time .After (4 * time . Second ):
197+ case <- time .After (getShortTimeout () ):
188198 t .Fatal ("Timeout reached" )
189199 return
190200 }
@@ -240,7 +250,7 @@ func testWatchTree(t *testing.T, kv store.Store) {
240250 return
241251 }
242252 eventCount ++
243- case <- time .After (4 * time . Second ):
253+ case <- time .After (getShortTimeout () ):
244254 t .Fatal ("Timeout reached" )
245255 return
246256 }
@@ -457,7 +467,7 @@ func testLockTTL(t *testing.T, kv store.Store, otherConn store.Store) {
457467 select {
458468 case _ = <- done :
459469 t .Fatal ("Lock succeeded on a key that is supposed to be locked by another client" )
460- case <- time .After (4 * time . Second ):
470+ case <- time .After (getShortTimeout () ):
461471 // Stop requesting the lock as we are blocked as expected
462472 stop <- struct {}{}
463473 break
@@ -484,7 +494,7 @@ func testLockTTL(t *testing.T, kv store.Store, otherConn store.Store) {
484494 select {
485495 case _ = <- locked :
486496 break
487- case <- time .After (4 * time . Second ):
497+ case <- time .After (getShortTimeout () ):
488498 t .Fatal ("Unable to take the lock, timed out" )
489499 }
490500
@@ -539,7 +549,7 @@ func testLockWait(t *testing.T, kv, otherConn store.Store) {
539549 select {
540550 case <- gotLock2 :
541551 t .FailNow () // The other client should not have the lock.
542- case <- time .After (5 * time . Second ):
552+ case <- time .After (getShortTimeout () ):
543553 // Success! The other client is still waiting.
544554 }
545555
@@ -551,7 +561,7 @@ func testLockWait(t *testing.T, kv, otherConn store.Store) {
551561 select {
552562 case <- gotLock2 :
553563 // Success! The other client has acquired the lock.
554- case <- time .After (5 * time . Second ):
564+ case <- time .After (getShortTimeout () ):
555565 t .FailNow () // The other client should no longer be blocking.
556566 }
557567 assert .NoError (t , lock2 .Unlock ())
0 commit comments