[#5] Add mutex to covertest
Printing coverage to file should be thread-safe Signed-off-by: Ekaterina Lebedeva <ekaterina.lebedeva@yadro.com>
This commit is contained in:
parent
8e4015f85f
commit
2c71079944
1 changed files with 6 additions and 0 deletions
|
@ -4,12 +4,15 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/compiler"
|
"github.com/nspcc-dev/neo-go/pkg/compiler"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var mu sync.Mutex
|
||||||
|
|
||||||
type coverline struct {
|
type coverline struct {
|
||||||
Doc string
|
Doc string
|
||||||
Opcode int
|
Opcode int
|
||||||
|
@ -91,6 +94,9 @@ func countInstructions(cov []coverline, codes []InstrHash) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func printToFile(t testing.TB, cov []coverline, name string) {
|
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)
|
f, err := os.OpenFile(name, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0600)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue