From f85426022d3a29a187046fffb134922d6cd004c7 Mon Sep 17 00:00:00 2001 From: Nuno Cruces Date: Wed, 15 Feb 2023 16:24:34 +0000 Subject: [PATCH] Test data races. --- .github/workflows/go.yml | 10 ++++++++-- compile.go | 12 +++++------- conn_test.go | 20 ++++++++++++++++++++ stmt_test.go | 2 ++ 4 files changed, 35 insertions(+), 9 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 0cda728..a3ae712 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -28,7 +28,13 @@ jobs: - name: Test run: go test -v ./... - - if: matrix.os == 'ubuntu-latest' - name: Update coverage report + - name: Test data races + run: go test -v -race ./... + if: matrix.os == 'ubuntu-latest' + + - name: Update coverage report uses: ncruces/go-coverage-report@main + if: | + matrix.os == 'ubuntu-latest' && + github.event_name == 'push' continue-on-error: true diff --git a/compile.go b/compile.go index cd2ddb1..fd424cb 100644 --- a/compile.go +++ b/compile.go @@ -24,13 +24,11 @@ type sqlite3Runtime struct { runtime wazero.Runtime compiled wazero.CompiledModule instances atomic.Uint64 - ctx context.Context err error } func (s *sqlite3Runtime) instantiateModule(ctx context.Context) (api.Module, error) { - s.ctx = ctx - s.once.Do(s.compileModule) + s.once.Do(func() { s.compileModule(ctx) }) if s.err != nil { return nil, s.err } @@ -40,9 +38,9 @@ func (s *sqlite3Runtime) instantiateModule(ctx context.Context) (api.Module, err return s.runtime.InstantiateModule(ctx, s.compiled, cfg) } -func (s *sqlite3Runtime) compileModule() { - s.runtime = wazero.NewRuntime(s.ctx) - s.err = vfsInstantiate(s.ctx, s.runtime) +func (s *sqlite3Runtime) compileModule(ctx context.Context) { + s.runtime = wazero.NewRuntime(ctx) + s.err = vfsInstantiate(ctx, s.runtime) if s.err != nil { return } @@ -55,5 +53,5 @@ func (s *sqlite3Runtime) compileModule() { } } - s.compiled, s.err = s.runtime.CompileModule(s.ctx, bin) + s.compiled, s.err = s.runtime.CompileModule(ctx, bin) } diff --git a/conn_test.go b/conn_test.go index 4029529..5690009 100644 --- a/conn_test.go +++ b/conn_test.go @@ -15,6 +15,8 @@ func TestConn_Close(t *testing.T) { } func TestConn_Close_BUSY(t *testing.T) { + t.Parallel() + db, err := Open(":memory:") if err != nil { t.Fatal(err) @@ -44,6 +46,8 @@ func TestConn_Close_BUSY(t *testing.T) { } func TestConn_Interrupt(t *testing.T) { + t.Parallel() + db, err := Open(":memory:") if err != nil { t.Fatal(err) @@ -92,6 +96,8 @@ func TestConn_Interrupt(t *testing.T) { } func TestConn_Prepare_Empty(t *testing.T) { + t.Parallel() + db, err := Open(":memory:") if err != nil { t.Fatal(err) @@ -110,6 +116,8 @@ func TestConn_Prepare_Empty(t *testing.T) { } func TestConn_Prepare_Invalid(t *testing.T) { + t.Parallel() + db, err := Open(":memory:") if err != nil { t.Fatal(err) @@ -151,6 +159,8 @@ func TestConn_Prepare_Invalid(t *testing.T) { } func TestConn_new(t *testing.T) { + t.Parallel() + db, err := Open(":memory:") if err != nil { t.Fatal(err) @@ -163,6 +173,8 @@ func TestConn_new(t *testing.T) { } func TestConn_newArena(t *testing.T) { + t.Parallel() + db, err := Open(":memory:") if err != nil { t.Fatal(err) @@ -193,6 +205,8 @@ func TestConn_newArena(t *testing.T) { } func TestConn_newBytes(t *testing.T) { + t.Parallel() + db, err := Open(":memory:") if err != nil { t.Fatal(err) @@ -217,6 +231,8 @@ func TestConn_newBytes(t *testing.T) { } func TestConn_newString(t *testing.T) { + t.Parallel() + db, err := Open(":memory:") if err != nil { t.Fatal(err) @@ -241,6 +257,8 @@ func TestConn_newString(t *testing.T) { } func TestConn_getString(t *testing.T) { + t.Parallel() + db, err := Open(":memory:") if err != nil { t.Fatal(err) @@ -280,6 +298,8 @@ func TestConn_getString(t *testing.T) { } func TestConn_free(t *testing.T) { + t.Parallel() + db, err := Open(":memory:") if err != nil { t.Fatal(err) diff --git a/stmt_test.go b/stmt_test.go index 0afc4ee..eee9769 100644 --- a/stmt_test.go +++ b/stmt_test.go @@ -6,6 +6,8 @@ import ( ) func TestStmt(t *testing.T) { + t.Parallel() + db, err := Open(":memory:") if err != nil { t.Fatal(err)