mirror of
https://github.com/octoleo/restic.git
synced 2024-12-24 11:55:28 +00:00
repository: speed up tests
This commit is contained in:
parent
eda9f7beb4
commit
c65459cd8a
@ -18,7 +18,7 @@ func randomSize(min, max int) int {
|
|||||||
return rand.Intn(max-min) + min
|
return rand.Intn(max-min) + min
|
||||||
}
|
}
|
||||||
|
|
||||||
func createRandomBlobs(t testing.TB, repo restic.Repository, blobs int, pData float32) {
|
func createRandomBlobs(t testing.TB, repo restic.Repository, blobs int, pData float32, smallBlobs bool) {
|
||||||
var wg errgroup.Group
|
var wg errgroup.Group
|
||||||
repo.StartPackUploader(context.TODO(), &wg)
|
repo.StartPackUploader(context.TODO(), &wg)
|
||||||
|
|
||||||
@ -30,7 +30,11 @@ func createRandomBlobs(t testing.TB, repo restic.Repository, blobs int, pData fl
|
|||||||
|
|
||||||
if rand.Float32() < pData {
|
if rand.Float32() < pData {
|
||||||
tpe = restic.DataBlob
|
tpe = restic.DataBlob
|
||||||
length = randomSize(10*1024, 1024*1024) // 10KiB to 1MiB of data
|
if smallBlobs {
|
||||||
|
length = randomSize(1*1024, 20*1024) // 1KiB to 20KiB of data
|
||||||
|
} else {
|
||||||
|
length = randomSize(10*1024, 1024*1024) // 10KiB to 1MiB of data
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
tpe = restic.TreeBlob
|
tpe = restic.TreeBlob
|
||||||
length = randomSize(1*1024, 20*1024) // 1KiB to 20KiB
|
length = randomSize(1*1024, 20*1024) // 1KiB to 20KiB
|
||||||
@ -219,7 +223,9 @@ func testRepack(t *testing.T, version uint) {
|
|||||||
rand.Seed(seed)
|
rand.Seed(seed)
|
||||||
t.Logf("rand seed is %v", seed)
|
t.Logf("rand seed is %v", seed)
|
||||||
|
|
||||||
createRandomBlobs(t, repo, 100, 0.7)
|
// add a small amount of blobs twice to create multiple pack files
|
||||||
|
createRandomBlobs(t, repo, 10, 0.7, false)
|
||||||
|
createRandomBlobs(t, repo, 10, 0.7, false)
|
||||||
|
|
||||||
packsBefore := listPacks(t, repo)
|
packsBefore := listPacks(t, repo)
|
||||||
|
|
||||||
@ -302,7 +308,9 @@ func testRepackCopy(t *testing.T, version uint) {
|
|||||||
rand.Seed(seed)
|
rand.Seed(seed)
|
||||||
t.Logf("rand seed is %v", seed)
|
t.Logf("rand seed is %v", seed)
|
||||||
|
|
||||||
createRandomBlobs(t, repo, 100, 0.7)
|
// add a small amount of blobs twice to create multiple pack files
|
||||||
|
createRandomBlobs(t, repo, 10, 0.7, false)
|
||||||
|
createRandomBlobs(t, repo, 10, 0.7, false)
|
||||||
flush(t, repo)
|
flush(t, repo)
|
||||||
|
|
||||||
_, keepBlobs := selectBlobs(t, repo, 0.2)
|
_, keepBlobs := selectBlobs(t, repo, 0.2)
|
||||||
@ -343,7 +351,7 @@ func testRepackWrongBlob(t *testing.T, version uint) {
|
|||||||
rand.Seed(seed)
|
rand.Seed(seed)
|
||||||
t.Logf("rand seed is %v", seed)
|
t.Logf("rand seed is %v", seed)
|
||||||
|
|
||||||
createRandomBlobs(t, repo, 5, 0.7)
|
createRandomBlobs(t, repo, 5, 0.7, false)
|
||||||
createRandomWrongBlob(t, repo)
|
createRandomWrongBlob(t, repo)
|
||||||
|
|
||||||
// just keep all blobs, but also rewrite every pack
|
// just keep all blobs, but also rewrite every pack
|
||||||
|
@ -109,7 +109,7 @@ func testRepairBrokenPack(t *testing.T, version uint) {
|
|||||||
rand.Seed(seed)
|
rand.Seed(seed)
|
||||||
t.Logf("rand seed is %v", seed)
|
t.Logf("rand seed is %v", seed)
|
||||||
|
|
||||||
createRandomBlobs(t, repo, 5, 0.7)
|
createRandomBlobs(t, repo, 5, 0.7, true)
|
||||||
packsBefore := listPacks(t, repo)
|
packsBefore := listPacks(t, repo)
|
||||||
blobsBefore := listBlobs(repo)
|
blobsBefore := listBlobs(repo)
|
||||||
|
|
||||||
|
@ -242,8 +242,7 @@ func loadIndex(ctx context.Context, repo restic.LoaderUnpacked, id restic.ID) (*
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestRepositoryLoadUnpackedBroken(t *testing.T) {
|
func TestRepositoryLoadUnpackedBroken(t *testing.T) {
|
||||||
repo, cleanup := repository.TestFromFixture(t, repoFixture)
|
repo := repository.TestRepository(t)
|
||||||
defer cleanup()
|
|
||||||
|
|
||||||
data := rtest.Random(23, 12345)
|
data := rtest.Random(23, 12345)
|
||||||
id := restic.Hash(data)
|
id := restic.Hash(data)
|
||||||
@ -252,7 +251,7 @@ func TestRepositoryLoadUnpackedBroken(t *testing.T) {
|
|||||||
data[0] ^= 0xff
|
data[0] ^= 0xff
|
||||||
|
|
||||||
// store broken file
|
// store broken file
|
||||||
err := repo.Backend().Save(context.TODO(), h, backend.NewByteReader(data, nil))
|
err := repo.Backend().Save(context.TODO(), h, backend.NewByteReader(data, repo.Backend().Hasher()))
|
||||||
rtest.OK(t, err)
|
rtest.OK(t, err)
|
||||||
|
|
||||||
// without a retry backend this will just return an error that the file is broken
|
// without a retry backend this will just return an error that the file is broken
|
||||||
|
Loading…
Reference in New Issue
Block a user