From 9de0a56492049713938bb288b2fa5d9b78f5b42b Mon Sep 17 00:00:00 2001 From: Emanuel Pargov Date: Fri, 11 Aug 2023 10:58:29 +0300 Subject: [PATCH] Feat: Add race flag to e2e tests Signed-off-by: Emanuel Pargov --- .github/workflows/build.yml | 2 +- one_signature_e2e_test.go | 34 ++++++++-------------------------- 2 files changed, 9 insertions(+), 27 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 6dde4e7d7..b0ff74dd4 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -66,7 +66,7 @@ jobs: - name: Tests Integration if: success() - run: go test -tags="e2e" -timeout 9999s -v -coverprofile=e2e.out -covermode=atomic + run: go test -tags="e2e" -timeout 9999s -v -coverprofile=e2e.out -covermode=atomic -race - name: Tests Testnets if: success() diff --git a/one_signature_e2e_test.go b/one_signature_e2e_test.go index 9580d312c..db976aba1 100644 --- a/one_signature_e2e_test.go +++ b/one_signature_e2e_test.go @@ -25,38 +25,20 @@ package hedera import ( "os" - "sync" + "sync/atomic" "testing" "github.com/stretchr/testify/require" ) -type Count struct { - mx *sync.Mutex - count int64 -} - -func NewCount() *Count { - return &Count{mx: new(sync.Mutex), count: 0} -} +var callCount int64 -func (c *Count) Incr() { - c.mx.Lock() - c.count++ - c.mx.Unlock() +func incrementCallCount() { + atomic.AddInt64(&callCount, 1) } -func (c *Count) Count() int64 { - c.mx.Lock() - count := c.count - c.mx.Unlock() - return count -} - -var fncCount = NewCount() - -func fnc() { - fncCount.Incr() +func getCallCount() int64 { + return atomic.LoadInt64(&callCount) } func TestIntegrationOneSignature(t *testing.T) { @@ -74,7 +56,7 @@ func TestIntegrationOneSignature(t *testing.T) { _, err = response.GetReceipt(client) require.NoError(t, err) - require.Equal(t, int64(1), fncCount.count) + require.Equal(t, int64(1), getCallCount()) client.Close() err = CloseIntegrationTestEnv(env, nil) require.NoError(t, err) @@ -82,7 +64,7 @@ func TestIntegrationOneSignature(t *testing.T) { func signingServiceTwo(txBytes []byte) []byte { localOperatorPrivateKey, _ := PrivateKeyFromString(os.Getenv("OPERATOR_KEY")) - go fnc() + incrementCallCount() signature := localOperatorPrivateKey.Sign(txBytes) return signature