From fd6c854a219d6d694b08e9aeb92f85c6bb983b40 Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Sat, 6 Aug 2016 17:29:08 +0200 Subject: [PATCH] Add TestResetRepository and BenchmarkCreateSnapshot --- src/restic/testing.go | 17 +++++++++++++++++ src/restic/testing_test.go | 12 ++++++++++++ 2 files changed, 29 insertions(+) diff --git a/src/restic/testing.go b/src/restic/testing.go index 12bd7cf74..ce4e98cfa 100644 --- a/src/restic/testing.go +++ b/src/restic/testing.go @@ -184,3 +184,20 @@ func TestCreateSnapshot(t testing.TB, repo *repository.Repository, at time.Time, return snapshot } + +// TestResetRepository removes all packs and indexes from the repository. +func TestResetRepository(t testing.TB, repo *repository.Repository) { + done := make(chan struct{}) + defer close(done) + + for _, tpe := range []backend.Type{backend.Snapshot, backend.Index, backend.Data} { + for id := range repo.Backend().List(tpe, done) { + err := repo.Backend().Remove(tpe, id) + if err != nil { + t.Errorf("removing %v (%v) failed: %v", id[0:12], tpe, err) + } + } + } + + repo.SetIndex(repository.NewMasterIndex()) +} diff --git a/src/restic/testing_test.go b/src/restic/testing_test.go index 8ec68b7ff..1427d4a62 100644 --- a/src/restic/testing_test.go +++ b/src/restic/testing_test.go @@ -47,3 +47,15 @@ func TestCreateSnapshot(t *testing.T) { checker.TestCheckRepo(t, repo) } + +func BenchmarkCreateSnapshot(b *testing.B) { + repo, cleanup := repository.TestRepository(b) + defer cleanup() + + b.ResetTimer() + + for i := 0; i < b.N; i++ { + restic.TestCreateSnapshot(b, repo, testSnapshotTime, testDepth) + restic.TestResetRepository(b, repo) + } +}