mirror of
https://github.com/restic/restic.git
synced 2025-03-30 00:00:14 +01:00
backend/test: parallelize slow tests
This commit is contained in:
parent
c36970074d
commit
4640b3c41a
1 changed files with 125 additions and 109 deletions
|
@ -10,11 +10,13 @@ import (
|
|||
"os"
|
||||
"reflect"
|
||||
"sort"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/restic/restic/internal/errors"
|
||||
"github.com/restic/restic/internal/restic"
|
||||
"golang.org/x/sync/errgroup"
|
||||
|
||||
"github.com/restic/restic/internal/test"
|
||||
|
||||
|
@ -276,17 +278,27 @@ func (s *Suite[C]) TestList(t *testing.T) {
|
|||
}
|
||||
|
||||
list1 := make(map[restic.ID]int64)
|
||||
var m sync.Mutex
|
||||
|
||||
wg, ctx := errgroup.WithContext(context.TODO())
|
||||
for i := 0; i < numTestFiles; i++ {
|
||||
data := test.Random(random.Int(), random.Intn(100)+55)
|
||||
wg.Go(func() error {
|
||||
id := restic.Hash(data)
|
||||
h := backend.Handle{Type: backend.PackFile, Name: id.String()}
|
||||
err := b.Save(context.TODO(), h, backend.NewByteReader(data, b.Hasher()))
|
||||
err := b.Save(ctx, h, backend.NewByteReader(data, b.Hasher()))
|
||||
|
||||
m.Lock()
|
||||
defer m.Unlock()
|
||||
list1[id] = int64(len(data))
|
||||
return err
|
||||
})
|
||||
}
|
||||
|
||||
err = wg.Wait()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
list1[id] = int64(len(data))
|
||||
}
|
||||
|
||||
t.Logf("wrote %v files", len(list1))
|
||||
|
||||
|
@ -777,16 +789,19 @@ func delayedList(t testing.TB, b backend.Backend, tpe backend.FileType, max int,
|
|||
|
||||
// TestBackend tests all functions of the backend.
|
||||
func (s *Suite[C]) TestBackend(t *testing.T) {
|
||||
for _, tpe := range []backend.FileType{
|
||||
backend.PackFile, backend.KeyFile, backend.LockFile,
|
||||
backend.SnapshotFile, backend.IndexFile,
|
||||
} {
|
||||
t.Run(tpe.String(), func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
b := s.open(t)
|
||||
defer s.close(t, b)
|
||||
|
||||
test.Assert(t, !b.IsNotExist(nil), "IsNotExist() recognized nil error")
|
||||
test.Assert(t, !b.IsPermanentError(nil), "IsPermanentError() recognized nil error")
|
||||
|
||||
for _, tpe := range []backend.FileType{
|
||||
backend.PackFile, backend.KeyFile, backend.LockFile,
|
||||
backend.SnapshotFile, backend.IndexFile,
|
||||
} {
|
||||
// detect non-existing files
|
||||
for _, ts := range testStrings {
|
||||
id, err := restic.ParseID(ts.id)
|
||||
|
@ -896,6 +911,7 @@ func (s *Suite[C]) TestBackend(t *testing.T) {
|
|||
}
|
||||
|
||||
test.OK(t, s.delayedRemove(t, b, handles...))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue