Skip to content

Commit

Permalink
CNS-337: sort out test timeout
Browse files Browse the repository at this point in the history
The e2e timeout was inconsistent:

First, "go test" default timeout is 10 minutes, which it can be changed using
"go test -timeout ...". However, the e2e test internally runs another "go test"
without any argument, so even if the user specified a longer timeout for the
test, the latter would fail within the default timeout.

Second, in at least one place the timeout was hard-coded fixed to 10 minutes.

This is fixed by settings the timeout the intenral "go test" to zero, and then
insteead settings the context.WithTimeout to the timeout requested by the user.
  • Loading branch information
orenl-lava committed May 2, 2023
1 parent 99b1d2e commit b376274
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
30 changes: 13 additions & 17 deletions testutil/e2e/e2e.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,9 @@ func (lt *lavaTest) startJSONRPCProxy(ctx context.Context) {
if err != nil {
panic("Could not find go executable path")
}
command := goExecutablePath + " test ./testutil/e2e/proxy/. -v eth"
// force go's test timeout to 0, otherwise the default is 10m; our timeout
// will be enforced by the given ctx.
command := goExecutablePath + " test ./testutil/e2e/proxy/. -v -timeout 0 eth"
logName := "02_jsonProxy"
funcName := "startJSONRPCProxy"

Expand Down Expand Up @@ -775,7 +777,7 @@ func (lt *lavaTest) checkPayments(testDuration time.Duration) {
}
}

func runE2E() {
func runE2E(timeout time.Duration) {
os.RemoveAll(logsFolder)
gopath := os.Getenv("GOPATH")
if gopath == "" {
Expand Down Expand Up @@ -806,7 +808,7 @@ func runE2E() {

utils.LavaFormatInfo("Starting Lava")
go lt.startLava(context.Background())
lt.checkLava(time.Minute * 10)
lt.checkLava(timeout)
utils.LavaFormatInfo("Starting Lava OK")
utils.LavaFormatInfo("Staking Lava")
lt.stakeLava()
Expand All @@ -822,23 +824,20 @@ func runE2E() {
// hereinafter:
// run each consumer test once for staked client and once for subscription client

// ETH1 flow
jsonCTX, cancel := context.WithCancel(context.Background())
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()

lt.startJSONRPCProxy(jsonCTX)
// ETH1 flow
lt.startJSONRPCProxy(ctx)
lt.checkJSONRPCConsumer("http://127.0.0.1:1111", time.Minute*2, "JSONRPCProxy OK") // checks proxy.
lt.startJSONRPCProvider(jsonCTX)
lt.startJSONRPCConsumer(jsonCTX)
lt.startJSONRPCProvider(ctx)
lt.startJSONRPCConsumer(ctx)
lt.checkJSONRPCConsumer("http://127.0.0.1:3331/1", time.Minute*2, "JSONRPCConsumer1 OK")
lt.checkJSONRPCConsumer("http://127.0.0.1:3332/1", time.Minute*2, "JSONRPCConsumer2 OK")

// Lava Flow
rpcCtx, cancel := context.WithCancel(context.Background())
defer cancel()

lt.startLavaProviders(rpcCtx)
lt.startLavaConsumer(rpcCtx)
lt.startLavaProviders(ctx)
lt.startLavaConsumer(ctx)
// staked client then with subscription
lt.checkTendermintConsumer("http://127.0.0.1:3340/1", time.Second*30)
lt.checkRESTConsumer("http://127.0.0.1:3341/1", time.Second*30)
Expand Down Expand Up @@ -874,7 +873,7 @@ func runE2E() {
}
utils.LavaFormatInfo("TENDERMINTRPC URI TEST OK")

lt.lavaOverLava(rpcCtx)
lt.lavaOverLava(ctx)

// staked client then with subscription
if restErr := restTests("http://127.0.0.1:3341/1", time.Second*30); restErr != nil {
Expand All @@ -897,8 +896,5 @@ func runE2E() {
}
utils.LavaFormatInfo("GRPC TEST OK")

jsonCTX.Done()
rpcCtx.Done()

lt.finishTestSuccessfully()
}
10 changes: 9 additions & 1 deletion testutil/e2e/lava_fullFlow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,16 @@ package e2e

import (
"testing"
"time"
)

func TestLava(t *testing.T) {
runE2E()
// default timeout same as `go test`
timeout := time.Minute * 10

if deadline, ok := t.Deadline(); ok {
timeout = deadline.Sub(time.Now()).Round(10*time.Second)
}

runE2E(timeout)
}

0 comments on commit b376274

Please sign in to comment.