Skip to content

Commit

Permalink
feat: ci test-plans: Parse test timeout parameter for interop test (#…
Browse files Browse the repository at this point in the history
…2014)

* Parse test timeout parameter for interop test

* Update test-plans/cmd/ping/main.go

Co-authored-by: Marten Seemann <martenseemann@gmail.com>

Co-authored-by: Marten Seemann <martenseemann@gmail.com>
  • Loading branch information
MarcoPolo and marten-seemann committed Jan 25, 2023
1 parent faddf1a commit 6a37331
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions test-plans/cmd/ping/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"log"
"os"
"strconv"
"time"

"github.com/go-redis/redis/v8"
Expand All @@ -24,24 +25,33 @@ import (

func main() {
var (
transport = os.Getenv("transport")
secureChannel = os.Getenv("security")
muxer = os.Getenv("muxer")
isDialerStr = os.Getenv("is_dialer")
ip = os.Getenv("ip")
redisAddr = os.Getenv("REDIS_ADDR")
transport = os.Getenv("transport")
secureChannel = os.Getenv("security")
muxer = os.Getenv("muxer")
isDialerStr = os.Getenv("is_dialer")
ip = os.Getenv("ip")
testTimeoutStr = os.Getenv("test_timeout")
redisAddr = os.Getenv("REDIS_ADDR")
)

testTimeout := 10 * time.Second
if testTimeoutStr != "" {
secs, err := strconv.ParseInt(testTimeoutStr, 10, 32)
if err == nil {
testTimeout = time.Duration(secs) * time.Second
}
}

if redisAddr == "" {
redisAddr = "redis:6379"
}

ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
ctx, cancel := context.WithTimeout(context.Background(), testTimeout)
defer cancel()

// Get peer information via redis
rClient := redis.NewClient(&redis.Options{
DialTimeout: 10 * time.Second,
DialTimeout: testTimeout,
Addr: redisAddr,
Password: "",
DB: 0,
Expand Down Expand Up @@ -110,7 +120,7 @@ func main() {
fmt.Println("My multiaddr is: ", host.Addrs())

if isDialer {
val, err := rClient.BLPop(ctx, 20*time.Second, "listenerAddr").Result()
val, err := rClient.BLPop(ctx, testTimeout, "listenerAddr").Result()
if err != nil {
log.Fatal("Failed to wait for listener to be ready")
}
Expand Down Expand Up @@ -144,7 +154,7 @@ func main() {
if err != nil {
log.Fatal("Failed to send listener address")
}
_, err = rClient.BLPop(ctx, 20*time.Second, "dialerDone").Result()
_, err = rClient.BLPop(ctx, testTimeout, "dialerDone").Result()
if err != nil {
log.Fatal("Failed to wait for dialer conclusion")
}
Expand Down

0 comments on commit 6a37331

Please sign in to comment.