From c6816de85e7e66cc69577e7b23fdc48723f793aa Mon Sep 17 00:00:00 2001 From: Martin Hutchinson Date: Thu, 5 Dec 2024 17:56:54 +0000 Subject: [PATCH] [MySQL] make the tests go faster (#392) Awaiting in the loop was causing this to take ages as it was doing one leaf at a time. They now happen in parallel, and we make sure they're all done before we allow the read parts of the test to start. --- storage/mysql/mysql_test.go | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/storage/mysql/mysql_test.go b/storage/mysql/mysql_test.go index 5989a499..d84d733e 100644 --- a/storage/mysql/mysql_test.go +++ b/storage/mysql/mysql_test.go @@ -172,18 +172,20 @@ func TestGetTile(t *testing.T) { awaiter := tessera.NewIntegrationAwaiter(ctx, s.ReadCheckpoint, 10*time.Millisecond) treeSize := 258 - var lastIndex uint64 + + wg := errgroup.Group{} for i := range treeSize { - idx, _, err := awaiter.Await(ctx, s.Add(ctx, tessera.NewEntry([]byte(fmt.Sprintf("TestGetTile %d", i))))) - if err != nil { - t.Fatalf("Failed to prep test with entry: %v", err) - } - if idx > lastIndex { - lastIndex = idx - } + wg.Go( + func() error { + _, _, err := awaiter.Await(ctx, s.Add(ctx, tessera.NewEntry([]byte(fmt.Sprintf("TestGetTile %d", i))))) + if err != nil { + return fmt.Errorf("failed to prep test with entry: %v", err) + } + return nil + }) } - if got, want := lastIndex, uint64(treeSize-1); got != want { - t.Fatalf("expected only newly created entries in database; tests are not hermetic (got %d, want %d)", got, want) + if err := wg.Wait(); err != nil { + t.Fatalf("Failed to set up database with required leaves: %v", err) } for _, test := range []struct {