From ad7454c3045607f4059f521c4e6443076f1e3163 Mon Sep 17 00:00:00 2001 From: Michael Hoffmann Date: Sat, 31 Dec 2022 16:03:46 +0100 Subject: [PATCH] misc: add race flag to devcam and fix fallout --- dev/devcam/test.go | 5 +++++ pkg/index/index_test.go | 8 ++++++++ 2 files changed, 13 insertions(+) diff --git a/dev/devcam/test.go b/dev/devcam/test.go index e54b5fa21..10b7db40f 100644 --- a/dev/devcam/test.go +++ b/dev/devcam/test.go @@ -36,6 +36,7 @@ type testCmd struct { verbose bool precommit bool short bool + race bool run string sqlite bool } @@ -44,6 +45,7 @@ func init() { cmdmain.RegisterMode("test", func(flags *flag.FlagSet) cmdmain.CommandRunner { cmd := new(testCmd) flags.BoolVar(&cmd.short, "short", false, "Use '-short' with go test.") + flags.BoolVar(&cmd.race, "race", false, "Use '-race' with go test.") flags.BoolVar(&cmd.precommit, "precommit", true, "Run the pre-commit githook as part of tests.") flags.BoolVar(&cmd.verbose, "v", false, "Use '-v' (for verbose) with go test.") flags.StringVar(&cmd.run, "run", "", "Use '-run' with go test.") @@ -128,6 +130,9 @@ func (c *testCmd) runTests(args []string) error { if c.short { targs = append(targs, "-short") } + if c.race { + targs = append(targs, "-race") + } if c.verbose { targs = append(targs, "-v") } diff --git a/pkg/index/index_test.go b/pkg/index/index_test.go index fd3ffa654..b292e0136 100644 --- a/pkg/index/index_test.go +++ b/pkg/index/index_test.go @@ -254,6 +254,7 @@ func TestInitNeededMaps(t *testing.T) { } ix.InitBlobSource(bs) { + ix.Lock() needs, neededBy, _ := ix.NeededMapsForTest() needsWant := map[blob.Ref][]blob.Ref{ fileBlobRef: {chunk1ref, chunk2ref, chunk3ref}, @@ -269,11 +270,13 @@ func TestInitNeededMaps(t *testing.T) { if !reflect.DeepEqual(neededBy, neededByWant) { t.Errorf("neededBy = %v; want %v", neededBy, neededByWant) } + ix.Unlock() } ix.Exp_noteBlobIndexed(chunk2ref) { + ix.Lock() needs, neededBy, ready := ix.NeededMapsForTest() needsWant := map[blob.Ref][]blob.Ref{ fileBlobRef: {chunk1ref, chunk3ref}, @@ -291,11 +294,13 @@ func TestInitNeededMaps(t *testing.T) { if len(ready) != 0 { t.Errorf("ready = %v; want nothing", ready) } + ix.Unlock() } ix.Exp_noteBlobIndexed(chunk1ref) { + ix.Lock() needs, neededBy, ready := ix.NeededMapsForTest() needsWant := map[blob.Ref][]blob.Ref{ fileBlobRef: {chunk3ref}, @@ -312,11 +317,13 @@ func TestInitNeededMaps(t *testing.T) { if len(ready) != 0 { t.Errorf("ready = %v; want nothing", ready) } + ix.Unlock() } ix.Exp_noteBlobIndexed(chunk3ref) { + ix.Lock() needs, neededBy, ready := ix.NeededMapsForTest() needsWant := map[blob.Ref][]blob.Ref{} neededByWant := map[blob.Ref][]blob.Ref{} @@ -329,6 +336,7 @@ func TestInitNeededMaps(t *testing.T) { if !ready[fileBlobRef] { t.Error("fileBlobRef not ready") } + ix.Unlock() } // We also technically don't need to wait for the ooo indexing goroutine // to finish for this unit test, but it's cleaner.