From 2c71079944e3506db89f9d40bf764c987221023b Mon Sep 17 00:00:00 2001 From: Ekaterina Lebedeva Date: Tue, 15 Aug 2023 14:51:26 +0300 Subject: [PATCH] [#5] Add mutex to covertest Printing coverage to file should be thread-safe Signed-off-by: Ekaterina Lebedeva --- covertest/cover.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/covertest/cover.go b/covertest/cover.go index c76acc3..9d7a2e3 100644 --- a/covertest/cover.go +++ b/covertest/cover.go @@ -4,12 +4,15 @@ import ( "fmt" "os" "strings" + "sync" "testing" "github.com/nspcc-dev/neo-go/pkg/compiler" "github.com/stretchr/testify/require" ) +var mu sync.Mutex + type coverline struct { Doc string Opcode int @@ -91,6 +94,9 @@ func countInstructions(cov []coverline, codes []InstrHash) { } func printToFile(t testing.TB, cov []coverline, name string) { + mu.Lock() + defer mu.Unlock() + f, err := os.OpenFile(name, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0600) require.NoError(t, err)