mirror of
https://github.com/octoleo/restic.git
synced 2024-12-23 11:28:54 +00:00
Add option to create duplicate blobs in TestCreateSnapshot
This commit is contained in:
parent
240b8f273a
commit
1058a91b39
@ -85,7 +85,7 @@ func TestFindUsedBlobs(t *testing.T) {
|
||||
|
||||
var snapshots []*Snapshot
|
||||
for i := 0; i < findTestSnapshots; i++ {
|
||||
sn := TestCreateSnapshot(t, repo, findTestTime.Add(time.Duration(i)*time.Second), findTestDepth)
|
||||
sn := TestCreateSnapshot(t, repo, findTestTime.Add(time.Duration(i)*time.Second), findTestDepth, 0)
|
||||
t.Logf("snapshot %v saved, tree %v", sn.ID().Str(), sn.Tree.Str())
|
||||
snapshots = append(snapshots, sn)
|
||||
}
|
||||
|
@ -15,11 +15,11 @@ var (
|
||||
depth = 3
|
||||
)
|
||||
|
||||
func createFilledRepo(t testing.TB, snapshots int) (*repository.Repository, func()) {
|
||||
func createFilledRepo(t testing.TB, snapshots int, dup float32) (*repository.Repository, func()) {
|
||||
repo, cleanup := repository.TestRepository(t)
|
||||
|
||||
for i := 0; i < 3; i++ {
|
||||
restic.TestCreateSnapshot(t, repo, snapshotTime.Add(time.Duration(i)*time.Second), depth)
|
||||
restic.TestCreateSnapshot(t, repo, snapshotTime.Add(time.Duration(i)*time.Second), depth, dup)
|
||||
}
|
||||
|
||||
return repo, cleanup
|
||||
@ -34,7 +34,7 @@ func validateIndex(t testing.TB, repo *repository.Repository, idx *Index) {
|
||||
}
|
||||
|
||||
func TestIndexNew(t *testing.T) {
|
||||
repo, cleanup := createFilledRepo(t, 3)
|
||||
repo, cleanup := createFilledRepo(t, 3, 0)
|
||||
defer cleanup()
|
||||
|
||||
idx, err := New(repo)
|
||||
@ -50,7 +50,7 @@ func TestIndexNew(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestIndexLoad(t *testing.T) {
|
||||
repo, cleanup := createFilledRepo(t, 3)
|
||||
repo, cleanup := createFilledRepo(t, 3, 0)
|
||||
defer cleanup()
|
||||
|
||||
loadIdx, err := Load(repo)
|
||||
@ -137,7 +137,7 @@ func openRepo(t testing.TB, dir, password string) *repository.Repository {
|
||||
}
|
||||
|
||||
func BenchmarkIndexNew(b *testing.B) {
|
||||
repo, cleanup := createFilledRepo(b, 3)
|
||||
repo, cleanup := createFilledRepo(b, 3, 0)
|
||||
defer cleanup()
|
||||
|
||||
b.ResetTimer()
|
||||
|
@ -20,9 +20,10 @@ func fakeFile(t testing.TB, seed, size int64) io.Reader {
|
||||
}
|
||||
|
||||
type fakeFileSystem struct {
|
||||
t testing.TB
|
||||
repo *repository.Repository
|
||||
knownBlobs backend.IDSet
|
||||
t testing.TB
|
||||
repo *repository.Repository
|
||||
knownBlobs backend.IDSet
|
||||
duplication float32
|
||||
}
|
||||
|
||||
// saveFile reads from rd and saves the blobs in the repository. The list of
|
||||
@ -77,6 +78,10 @@ func (fs fakeFileSystem) treeIsKnown(tree *Tree) (bool, backend.ID) {
|
||||
}
|
||||
|
||||
func (fs fakeFileSystem) blobIsKnown(id backend.ID, t pack.BlobType) bool {
|
||||
if rand.Float32() < fs.duplication {
|
||||
return false
|
||||
}
|
||||
|
||||
if fs.knownBlobs.Has(id) {
|
||||
return true
|
||||
}
|
||||
@ -142,8 +147,9 @@ func (fs fakeFileSystem) saveTree(seed int64, depth int) backend.ID {
|
||||
// TestCreateSnapshot creates a snapshot filled with fake data. The
|
||||
// fake data is generated deterministically from the timestamp `at`, which is
|
||||
// also used as the snapshot's timestamp. The tree's depth can be specified
|
||||
// with the parameter depth.
|
||||
func TestCreateSnapshot(t testing.TB, repo *repository.Repository, at time.Time, depth int) *Snapshot {
|
||||
// with the parameter depth. The parameter duplication is a probability that
|
||||
// the same blob will saved again.
|
||||
func TestCreateSnapshot(t testing.TB, repo *repository.Repository, at time.Time, depth int, duplication float32) *Snapshot {
|
||||
seed := at.Unix()
|
||||
t.Logf("create fake snapshot at %s with seed %d", at, seed)
|
||||
|
||||
@ -155,9 +161,10 @@ func TestCreateSnapshot(t testing.TB, repo *repository.Repository, at time.Time,
|
||||
snapshot.Time = at
|
||||
|
||||
fs := fakeFileSystem{
|
||||
t: t,
|
||||
repo: repo,
|
||||
knownBlobs: backend.NewIDSet(),
|
||||
t: t,
|
||||
repo: repo,
|
||||
knownBlobs: backend.NewIDSet(),
|
||||
duplication: duplication,
|
||||
}
|
||||
|
||||
treeID := fs.saveTree(seed, depth)
|
||||
|
@ -20,7 +20,7 @@ func TestCreateSnapshot(t *testing.T) {
|
||||
defer cleanup()
|
||||
|
||||
for i := 0; i < testCreateSnapshots; i++ {
|
||||
restic.TestCreateSnapshot(t, repo, testSnapshotTime.Add(time.Duration(i)*time.Second), testDepth)
|
||||
restic.TestCreateSnapshot(t, repo, testSnapshotTime.Add(time.Duration(i)*time.Second), testDepth, 0)
|
||||
}
|
||||
|
||||
snapshots, err := restic.LoadAllSnapshots(repo)
|
||||
@ -55,7 +55,7 @@ func BenchmarkCreateSnapshot(b *testing.B) {
|
||||
b.ResetTimer()
|
||||
|
||||
for i := 0; i < b.N; i++ {
|
||||
restic.TestCreateSnapshot(b, repo, testSnapshotTime, testDepth)
|
||||
restic.TestCreateSnapshot(b, repo, testSnapshotTime, testDepth, 0)
|
||||
restic.TestResetRepository(b, repo)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user