From b376274756cc82654d7b8910144af0f163816b7d Mon Sep 17 00:00:00 2001 From: Oren Laadan Date: Sun, 2 Apr 2023 16:36:55 +0800 Subject: [PATCH] CNS-337: sort out test timeout 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. --- testutil/e2e/e2e.go | 30 +++++++++++++----------------- testutil/e2e/lava_fullFlow_test.go | 10 +++++++++- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/testutil/e2e/e2e.go b/testutil/e2e/e2e.go index 18b1ab4b83..2d75d37e86 100644 --- a/testutil/e2e/e2e.go +++ b/testutil/e2e/e2e.go @@ -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" @@ -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 == "" { @@ -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() @@ -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) @@ -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 { @@ -897,8 +896,5 @@ func runE2E() { } utils.LavaFormatInfo("GRPC TEST OK") - jsonCTX.Done() - rpcCtx.Done() - lt.finishTestSuccessfully() } diff --git a/testutil/e2e/lava_fullFlow_test.go b/testutil/e2e/lava_fullFlow_test.go index 453a8b0593..995de8b1e8 100644 --- a/testutil/e2e/lava_fullFlow_test.go +++ b/testutil/e2e/lava_fullFlow_test.go @@ -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) }