From 528d41f904e9224df31b011ca924026be12992f8 Mon Sep 17 00:00:00 2001 From: William Banfield Date: Tue, 24 Aug 2021 11:57:09 -0400 Subject: [PATCH] inspect test timeout in ci/cd --- inspect/inspect_test.go | 63 +++++++++++++++++++++++++++++++++++------ 1 file changed, 54 insertions(+), 9 deletions(-) diff --git a/inspect/inspect_test.go b/inspect/inspect_test.go index 5d782418c..7f2f8d819 100644 --- a/inspect/inspect_test.go +++ b/inspect/inspect_test.go @@ -8,7 +8,6 @@ import ( "strings" "sync" "testing" - "time" "github.com/fortytw2/leaktest" "github.com/stretchr/testify/mock" @@ -79,13 +78,17 @@ func TestBlock(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) wg := &sync.WaitGroup{} wg.Add(1) + + startedWG := &sync.WaitGroup{} + startedWG.Add(1) go func() { + startedWG.Done() defer wg.Done() require.NoError(t, d.Run(ctx)) }() // FIXME: used to induce context switch. // Determine more deterministic method for prompting a context switch - time.Sleep(10 * time.Microsecond) + startedWG.Wait() requireConnect(t, rpcConfig.ListenAddress, 20) cli, err := httpclient.New(rpcConfig.ListenAddress) require.NoError(t, err) @@ -125,10 +128,17 @@ func TestTxSearch(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) wg := &sync.WaitGroup{} wg.Add(1) + + startedWG := &sync.WaitGroup{} + startedWG.Add(1) go func() { + startedWG.Done() defer wg.Done() require.NoError(t, d.Run(ctx)) }() + // FIXME: used to induce context switch. + // Determine more deterministic method for prompting a context switch + startedWG.Wait() requireConnect(t, rpcConfig.ListenAddress, 20) cli, err := httpclient.New(rpcConfig.ListenAddress) require.NoError(t, err) @@ -165,10 +175,17 @@ func TestTx(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) wg := &sync.WaitGroup{} wg.Add(1) + + startedWG := &sync.WaitGroup{} + startedWG.Add(1) go func() { + startedWG.Done() defer wg.Done() require.NoError(t, d.Run(ctx)) }() + // FIXME: used to induce context switch. + // Determine more deterministic method for prompting a context switch + startedWG.Wait() requireConnect(t, rpcConfig.ListenAddress, 20) cli, err := httpclient.New(rpcConfig.ListenAddress) require.NoError(t, err) @@ -205,13 +222,17 @@ func TestConsensusParams(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) wg := &sync.WaitGroup{} wg.Add(1) + + startedWG := &sync.WaitGroup{} + startedWG.Add(1) go func() { + startedWG.Done() defer wg.Done() require.NoError(t, d.Run(ctx)) }() // FIXME: used to induce context switch. // Determine more deterministic method for prompting a context switch - time.Sleep(10 * time.Microsecond) + startedWG.Wait() requireConnect(t, rpcConfig.ListenAddress, 20) cli, err := httpclient.New(rpcConfig.ListenAddress) require.NoError(t, err) @@ -252,13 +273,17 @@ func TestBlockResults(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) wg := &sync.WaitGroup{} wg.Add(1) + + startedWG := &sync.WaitGroup{} + startedWG.Add(1) go func() { + startedWG.Done() defer wg.Done() require.NoError(t, d.Run(ctx)) }() // FIXME: used to induce context switch. // Determine more deterministic method for prompting a context switch - time.Sleep(10 * time.Microsecond) + startedWG.Wait() requireConnect(t, rpcConfig.ListenAddress, 20) cli, err := httpclient.New(rpcConfig.ListenAddress) require.NoError(t, err) @@ -294,13 +319,17 @@ func TestCommit(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) wg := &sync.WaitGroup{} wg.Add(1) + + startedWG := &sync.WaitGroup{} + startedWG.Add(1) go func() { + startedWG.Done() defer wg.Done() require.NoError(t, d.Run(ctx)) }() // FIXME: used to induce context switch. // Determine more deterministic method for prompting a context switch - time.Sleep(10 * time.Microsecond) + startedWG.Wait() requireConnect(t, rpcConfig.ListenAddress, 20) cli, err := httpclient.New(rpcConfig.ListenAddress) require.NoError(t, err) @@ -342,13 +371,17 @@ func TestBlockByHash(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) wg := &sync.WaitGroup{} wg.Add(1) + + startedWG := &sync.WaitGroup{} + startedWG.Add(1) go func() { + startedWG.Done() defer wg.Done() require.NoError(t, d.Run(ctx)) }() // FIXME: used to induce context switch. // Determine more deterministic method for prompting a context switch - time.Sleep(10 * time.Microsecond) + startedWG.Wait() requireConnect(t, rpcConfig.ListenAddress, 20) cli, err := httpclient.New(rpcConfig.ListenAddress) require.NoError(t, err) @@ -389,13 +422,17 @@ func TestBlockchain(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) wg := &sync.WaitGroup{} wg.Add(1) + + startedWG := &sync.WaitGroup{} + startedWG.Add(1) go func() { + startedWG.Done() defer wg.Done() require.NoError(t, d.Run(ctx)) }() // FIXME: used to induce context switch. // Determine more deterministic method for prompting a context switch - time.Sleep(10 * time.Microsecond) + startedWG.Wait() requireConnect(t, rpcConfig.ListenAddress, 20) cli, err := httpclient.New(rpcConfig.ListenAddress) require.NoError(t, err) @@ -436,13 +473,17 @@ func TestValidators(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) wg := &sync.WaitGroup{} wg.Add(1) + + startedWG := &sync.WaitGroup{} + startedWG.Add(1) go func() { + startedWG.Done() defer wg.Done() require.NoError(t, d.Run(ctx)) }() // FIXME: used to induce context switch. // Determine more deterministic method for prompting a context switch - time.Sleep(10 * time.Microsecond) + startedWG.Wait() requireConnect(t, rpcConfig.ListenAddress, 20) cli, err := httpclient.New(rpcConfig.ListenAddress) require.NoError(t, err) @@ -491,13 +532,17 @@ func TestBlockSearch(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) wg := &sync.WaitGroup{} wg.Add(1) + + startedWG := &sync.WaitGroup{} + startedWG.Add(1) go func() { + startedWG.Done() defer wg.Done() require.NoError(t, d.Run(ctx)) }() // FIXME: used to induce context switch. // Determine more deterministic method for prompting a context switch - time.Sleep(10 * time.Microsecond) + startedWG.Wait() requireConnect(t, rpcConfig.ListenAddress, 20) cli, err := httpclient.New(rpcConfig.ListenAddress) require.NoError(t, err)