From 8132af3ee0601089f6ac6835fdedd71efe3bcd8c Mon Sep 17 00:00:00 2001 From: Alexey Semenyuk Date: Wed, 8 Nov 2023 23:22:45 +0600 Subject: [PATCH] Fix flaky test Signed-off-by: Alexey Semenyuk --- Makefile | 2 +- internal/tezos/new_block_listener_test.go | 7 ++++++- internal/tezos/retry_delay_test.go | 4 +--- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 1df007f..f011a3a 100644 --- a/Makefile +++ b/Makefile @@ -8,7 +8,7 @@ MOCKERY := $(GOBIN)/mockery all: build test go-mod-tidy test: deps - $(VGO) test ./internal/... ./cmd/... -cover -coverprofile=coverage.txt -covermode=atomic -timeout=30s + $(VGO) test ./internal/... ./cmd/... -v -short -cover -coverprofile=coverage.txt -covermode=atomic -timeout=30s coverage.html: $(VGO) tool cover -html=coverage.txt coverage: test coverage.html diff --git a/internal/tezos/new_block_listener_test.go b/internal/tezos/new_block_listener_test.go index f99b7c6..c1bd279 100644 --- a/internal/tezos/new_block_listener_test.go +++ b/internal/tezos/new_block_listener_test.go @@ -2,6 +2,7 @@ package tezos import ( "testing" + "time" "blockwatch.cc/tzgo/rpc" "blockwatch.cc/tzgo/tezos" @@ -11,7 +12,7 @@ import ( "github.com/stretchr/testify/mock" ) -func TestNewBlockListenerOK(t *testing.T) { +func TestNewBlockListenerOKWithDelay(t *testing.T) { ctx, c, mRPC, done := newTestConnector(t) defer done() @@ -24,13 +25,17 @@ func TestNewBlockListenerOK(t *testing.T) { Level: 12345, }, }, nil).Maybe() + mRPC.On("MonitorBlockHeader", mock.Anything, mock.Anything).Return(nil) req := &ffcapi.NewBlockListenerRequest{ ID: fftypes.NewUUID(), ListenerContext: ctx, BlockListener: make(chan<- *ffcapi.BlockHashEvent), } + res, _, err := c.NewBlockListener(ctx, req) + + time.Sleep(1 * time.Second) assert.NoError(t, err) assert.NotNil(t, res) } diff --git a/internal/tezos/retry_delay_test.go b/internal/tezos/retry_delay_test.go index f1c5c49..33106b6 100644 --- a/internal/tezos/retry_delay_test.go +++ b/internal/tezos/retry_delay_test.go @@ -16,9 +16,7 @@ func TestRetryDelay(t *testing.T) { c.retry.InitialDelay = 1 * time.Microsecond ctx, cancel := context.WithCancel(context.Background()) - go func() { - cancel() - }() + cancel() testCases := []struct { name string