From 382c766983adb8d7d7fc1e283cc841a2097817ba Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Mon, 1 Feb 2016 23:48:36 +0100 Subject: [PATCH] Move test for #405: Test Archiver instead of Repo --- ...ex_test.go => archiver_duplication_test.go | 28 +++++++++++-------- 1 file changed, 16 insertions(+), 12 deletions(-) rename repository/master_index_test.go => archiver_duplication_test.go (78%) diff --git a/repository/master_index_test.go b/archiver_duplication_test.go similarity index 78% rename from repository/master_index_test.go rename to archiver_duplication_test.go index 923eef338..f3e4c5475 100644 --- a/repository/master_index_test.go +++ b/archiver_duplication_test.go @@ -1,4 +1,4 @@ -package repository +package restic_test import ( "bytes" @@ -10,13 +10,15 @@ import ( "testing" "time" + "github.com/restic/restic" "github.com/restic/restic/backend" "github.com/restic/restic/pack" + "github.com/restic/restic/repository" ) -const parallelSaves = 20 -const saveIndexTime = 100 * time.Millisecond -const testTimeout = 1 * time.Second +const parallelSaves = 50 +const testSaveIndexTime = 100 * time.Millisecond +const testTimeout = 2 * time.Second var DupID backend.ID @@ -70,18 +72,20 @@ func forgetfulBackend() backend.Backend { return be } -func testMasterIndex(t *testing.T) { +func testArchiverDuplication(t *testing.T) { _, err := io.ReadFull(rand.Reader, DupID[:]) if err != nil { t.Fatal(err) } - repo := New(forgetfulBackend()) + repo := repository.New(forgetfulBackend()) err = repo.Init("foo") if err != nil { t.Fatal(err) } + arch := restic.NewArchiver(repo) + wg := &sync.WaitGroup{} done := make(chan struct{}) for i := 0; i < parallelSaves; i++ { @@ -103,7 +107,7 @@ func testMasterIndex(t *testing.T) { buf := make([]byte, 50) - err := repo.SaveFrom(pack.Data, &id, uint(len(buf)), bytes.NewReader(buf)) + err := arch.Save(pack.Data, id, uint(len(buf)), bytes.NewReader(buf)) if err != nil { t.Fatal(err) } @@ -111,10 +115,10 @@ func testMasterIndex(t *testing.T) { }() } - saveIndexes := func() { + saveIndex := func() { defer wg.Done() - ticker := time.NewTicker(saveIndexTime) + ticker := time.NewTicker(testSaveIndexTime) defer ticker.Stop() for { @@ -131,7 +135,7 @@ func testMasterIndex(t *testing.T) { } wg.Add(1) - go saveIndexes() + go saveIndex() <-time.After(testTimeout) close(done) @@ -139,8 +143,8 @@ func testMasterIndex(t *testing.T) { wg.Wait() } -func TestMasterIndex(t *testing.T) { +func TestArchiverDuplication(t *testing.T) { for i := 0; i < 5; i++ { - testMasterIndex(t) + testArchiverDuplication(t) } }