diff options
author | Patrick Steinhardt <psteinhardt@gitlab.com> | 2021-12-09 11:29:15 +0300 |
---|---|---|
committer | Patrick Steinhardt <psteinhardt@gitlab.com> | 2021-12-10 18:04:03 +0300 |
commit | 647d47c0ab8733e3695862882af428944021da01 (patch) | |
tree | 1f9a5acc40c41edd33d54f9bc63051d522c01c32 | |
parent | 152eed395a273b99541257609664241296aef62e (diff) |
backup: Parallelize tests
Use better parallelization for tests by adding `t.Parallel()` calls as
required. Like this, tests drop from 28 seconds of execution time to
only 8 seconds.
-rw-r--r-- | cmd/gitaly-backup/restore_test.go | 2 | ||||
-rw-r--r-- | internal/backup/backup_test.go | 25 | ||||
-rw-r--r-- | internal/backup/filesystem_sink_test.go | 14 | ||||
-rw-r--r-- | internal/backup/lazy_test.go | 4 | ||||
-rw-r--r-- | internal/backup/locator_test.go | 24 | ||||
-rw-r--r-- | internal/backup/pipeline_test.go | 10 | ||||
-rw-r--r-- | internal/backup/storage_service_sink_test.go | 2 |
7 files changed, 76 insertions, 5 deletions
diff --git a/cmd/gitaly-backup/restore_test.go b/cmd/gitaly-backup/restore_test.go index 0b309db30..a207651ad 100644 --- a/cmd/gitaly-backup/restore_test.go +++ b/cmd/gitaly-backup/restore_test.go @@ -20,6 +20,8 @@ import ( ) func TestRestoreSubcommand(t *testing.T) { + t.Parallel() + cfg := testcfg.Build(t) testcfg.BuildGitalyHooks(t, cfg) diff --git a/internal/backup/backup_test.go b/internal/backup/backup_test.go index 1843999b8..1cbd7addb 100644 --- a/internal/backup/backup_test.go +++ b/internal/backup/backup_test.go @@ -29,6 +29,8 @@ import ( ) func TestManager_Create(t *testing.T) { + t.Parallel() + const backupID = "abc123" cfg := testcfg.Build(t) @@ -150,6 +152,8 @@ func TestManager_Create(t *testing.T) { } func TestManager_Create_incremental(t *testing.T) { + t.Parallel() + const backupID = "abc123" cfg := testcfg.Build(t) @@ -261,6 +265,8 @@ func TestManager_Create_incremental(t *testing.T) { } func TestManager_Restore(t *testing.T) { + t.Parallel() + cfg := testcfg.Build(t) testcfg.BuildGitalyHooks(t, cfg) @@ -270,6 +276,8 @@ func TestManager_Restore(t *testing.T) { } func TestManager_Restore_praefect(t *testing.T) { + t.Parallel() + gitalyCfg := testcfg.Build(t, testcfg.WithStorages("gitaly-1")) testcfg.BuildPraefect(t, gitalyCfg) @@ -324,11 +332,14 @@ func TestManager_Restore_praefect(t *testing.T) { } func testManagerRestore(t *testing.T, cfg config.Cfg, gitalyAddr string) { - testhelper.NewFeatureSets( - featureflag.AtomicRemoveRepository, - featureflag.TxAtomicRepositoryCreation, - ).Run(t, func(t *testing.T, ctx context.Context) { - testManagerRestoreWithContext(t, ctx, cfg, gitalyAddr) + t.Run("parallel", func(t *testing.T) { + testhelper.NewFeatureSets( + featureflag.AtomicRemoveRepository, + featureflag.TxAtomicRepositoryCreation, + ).Run(t, func(t *testing.T, ctx context.Context) { + t.Parallel() + testManagerRestoreWithContext(t, ctx, cfg, gitalyAddr) + }) }) } @@ -581,6 +592,8 @@ func testManagerRestoreWithContext(t *testing.T, ctx context.Context, cfg config } func TestResolveSink(t *testing.T) { + t.Parallel() + isStorageServiceSink := func(expErrMsg string) func(t *testing.T, sink Sink) { return func(t *testing.T, sink Sink) { t.Helper() @@ -673,6 +686,8 @@ func TestResolveSink(t *testing.T) { } func TestResolveLocator(t *testing.T) { + t.Parallel() + for _, tc := range []struct { layout string expectedErr string diff --git a/internal/backup/filesystem_sink_test.go b/internal/backup/filesystem_sink_test.go index 86be459a1..6c0fe6030 100644 --- a/internal/backup/filesystem_sink_test.go +++ b/internal/backup/filesystem_sink_test.go @@ -13,7 +13,11 @@ import ( ) func TestFilesystemSink_GetReader(t *testing.T) { + t.Parallel() + t.Run("ok", func(t *testing.T) { + t.Parallel() + ctx, cancel := testhelper.Context() defer cancel() @@ -33,6 +37,8 @@ func TestFilesystemSink_GetReader(t *testing.T) { }) t.Run("no file", func(t *testing.T) { + t.Parallel() + ctx, cancel := testhelper.Context() defer cancel() @@ -47,7 +53,11 @@ func TestFilesystemSink_GetReader(t *testing.T) { } func TestFilesystemSink_Write(t *testing.T) { + t.Parallel() + t.Run("ok", func(t *testing.T) { + t.Parallel() + ctx, cancel := testhelper.Context() defer cancel() @@ -64,6 +74,8 @@ func TestFilesystemSink_Write(t *testing.T) { }) t.Run("overrides existing data", func(t *testing.T) { + t.Parallel() + ctx, cancel := testhelper.Context() defer cancel() @@ -84,6 +96,8 @@ func TestFilesystemSink_Write(t *testing.T) { }) t.Run("dir creation error", func(t *testing.T) { + t.Parallel() + ctx, cancel := testhelper.Context() defer cancel() diff --git a/internal/backup/lazy_test.go b/internal/backup/lazy_test.go index 5c4db0c1e..e8964faea 100644 --- a/internal/backup/lazy_test.go +++ b/internal/backup/lazy_test.go @@ -13,6 +13,8 @@ import ( ) func TestLazyWrite_noData(t *testing.T) { + t.Parallel() + ctx, cancel := testhelper.Context() defer cancel() @@ -30,6 +32,8 @@ func TestLazyWrite_noData(t *testing.T) { } func TestLazyWrite_data(t *testing.T) { + t.Parallel() + ctx, cancel := testhelper.Context() defer cancel() diff --git a/internal/backup/locator_test.go b/internal/backup/locator_test.go index 7dd9bc454..17e4f859a 100644 --- a/internal/backup/locator_test.go +++ b/internal/backup/locator_test.go @@ -15,10 +15,14 @@ import ( ) func TestLegacyLocator(t *testing.T) { + t.Parallel() + _, repo, _ := testcfg.BuildWithRepo(t) l := LegacyLocator{} t.Run("Begin/Commit Full", func(t *testing.T) { + t.Parallel() + ctx, cancel := testhelper.Context() defer cancel() @@ -36,6 +40,8 @@ func TestLegacyLocator(t *testing.T) { }) t.Run("FindLatest", func(t *testing.T) { + t.Parallel() + ctx, cancel := testhelper.Context() defer cancel() @@ -58,11 +64,15 @@ func TestLegacyLocator(t *testing.T) { } func TestPointerLocator(t *testing.T) { + t.Parallel() + const backupID = "abc123" _, repo, _ := testcfg.BuildWithRepo(t) t.Run("Begin/Commit full", func(t *testing.T) { + t.Parallel() + backupPath := testhelper.TempDir(t) var l Locator = PointerLocator{ Sink: NewFilesystemSink(backupPath), @@ -91,6 +101,8 @@ func TestPointerLocator(t *testing.T) { }) t.Run("Begin/Commit incremental", func(t *testing.T) { + t.Parallel() + const fallbackBackupID = "fallback123" for _, tc := range []struct { @@ -114,6 +126,8 @@ func TestPointerLocator(t *testing.T) { }, } { t.Run(tc.desc, func(t *testing.T) { + t.Parallel() + backupPath := testhelper.TempDir(t) sink := NewFilesystemSink(backupPath) var l Locator = PointerLocator{Sink: sink} @@ -157,7 +171,11 @@ func TestPointerLocator(t *testing.T) { }) t.Run("FindLatest", func(t *testing.T) { + t.Parallel() + t.Run("no fallback", func(t *testing.T) { + t.Parallel() + backupPath := testhelper.TempDir(t) var l Locator = PointerLocator{ Sink: NewFilesystemSink(backupPath), @@ -200,6 +218,8 @@ func TestPointerLocator(t *testing.T) { }) t.Run("fallback", func(t *testing.T) { + t.Parallel() + backupPath := testhelper.TempDir(t) var l Locator = PointerLocator{ Sink: NewFilesystemSink(backupPath), @@ -243,6 +263,8 @@ func TestPointerLocator(t *testing.T) { }) t.Run("invalid backup LATEST", func(t *testing.T) { + t.Parallel() + backupPath := testhelper.TempDir(t) var l Locator = PointerLocator{ Sink: NewFilesystemSink(backupPath), @@ -261,6 +283,8 @@ func TestPointerLocator(t *testing.T) { }) t.Run("invalid incremental LATEST", func(t *testing.T) { + t.Parallel() + backupPath := testhelper.TempDir(t) var l Locator = PointerLocator{ Sink: NewFilesystemSink(backupPath), diff --git a/internal/backup/pipeline_test.go b/internal/backup/pipeline_test.go index 44a90afb7..afe844f9f 100644 --- a/internal/backup/pipeline_test.go +++ b/internal/backup/pipeline_test.go @@ -16,12 +16,16 @@ import ( ) func TestLoggingPipeline(t *testing.T) { + t.Parallel() + testPipeline(t, func() Pipeline { return NewLoggingPipeline(logrus.StandardLogger()) }) } func TestParallelPipeline(t *testing.T) { + t.Parallel() + testPipeline(t, func() Pipeline { return NewParallelPipeline(NewLoggingPipeline(logrus.StandardLogger()), 2, 0) }) @@ -116,6 +120,8 @@ func (s MockStrategy) Restore(ctx context.Context, req *RestoreRequest) error { func testPipeline(t *testing.T, init func() Pipeline) { t.Run("create command", func(t *testing.T) { + t.Parallel() + strategy := MockStrategy{ CreateFunc: func(_ context.Context, req *CreateRequest) error { switch req.Repository.StorageName { @@ -148,6 +154,8 @@ func testPipeline(t *testing.T, init func() Pipeline) { }) t.Run("restore command", func(t *testing.T) { + t.Parallel() + strategy := MockStrategy{ RestoreFunc: func(_ context.Context, req *RestoreRequest) error { switch req.Repository.StorageName { @@ -181,6 +189,8 @@ func testPipeline(t *testing.T, init func() Pipeline) { } func TestPipelineError(t *testing.T) { + t.Parallel() + for _, tc := range []struct { name string repos []*gitalypb.Repository diff --git a/internal/backup/storage_service_sink_test.go b/internal/backup/storage_service_sink_test.go index 5b740df46..3289bf2a5 100644 --- a/internal/backup/storage_service_sink_test.go +++ b/internal/backup/storage_service_sink_test.go @@ -12,6 +12,8 @@ import ( ) func TestStorageServiceSink(t *testing.T) { + t.Parallel() + ctx, cancel := testhelper.Context() defer cancel() |