1
0
mirror of https://github.com/gilbertchen/duplicacy synced 2025-12-06 00:03:38 +00:00

Add a test for multi-threaded pruning

This commit is contained in:
Gilbert Chen
2018-06-06 13:11:19 -04:00
parent f68eb13584
commit 6f0166be6d

View File

@@ -143,6 +143,15 @@ func uploadRandomChunk(manager *SnapshotManager, chunkSize int) string {
return uploadTestChunk(manager, content)
}
func uploadRandomChunks(manager *SnapshotManager, chunkSize int, numberOfChunks int) []string {
chunkList := make([]string, 0)
for i := 0; i < numberOfChunks; i++ {
chunkHash := uploadRandomChunk(manager, chunkSize)
chunkList = append(chunkList, chunkHash)
}
return chunkList
}
func createTestSnapshot(manager *SnapshotManager, snapshotID string, revision int, startTime int64, endTime int64, chunkHashes []string, tag string) {
snapshot := &Snapshot{
@@ -535,3 +544,41 @@ func TestPruneWithFossils(t *testing.T) {
snapshotManager.PruneSnapshots("vm1@host1", "vm1@host1", []int{}, []string{}, []string{}, false, true, []string{}, false, false, false, 1)
checkTestSnapshots(snapshotManager, 2, 0)
}
func TestPruneMultipleThread(t *testing.T) {
setTestingT(t)
testDir := path.Join(os.TempDir(), "duplicacy_test", "snapshot_test")
snapshotManager := createTestSnapshotManager(testDir)
chunkSize := 1024
numberOfChunks := 256
numberOfThreads := 4
chunkList1 := uploadRandomChunks(snapshotManager, chunkSize, numberOfChunks)
chunkList2 := uploadRandomChunks(snapshotManager, chunkSize, numberOfChunks)
now := time.Now().Unix()
day := int64(24 * 3600)
t.Logf("Creating 2 snapshots")
createTestSnapshot(snapshotManager, "repository1", 1, now-4*day-3600, now-3*day-60, chunkList1, "tag")
createTestSnapshot(snapshotManager, "repository1", 2, now-3*day-3600, now-2*day-60, chunkList2, "tag")
checkTestSnapshots(snapshotManager, 2, 0)
t.Logf("Removing snapshot revisions 1 with --exclusive")
snapshotManager.PruneSnapshots("repository1", "repository1", []int{1}, []string{}, []string{}, false, true, []string{}, false, false, false, numberOfThreads)
checkTestSnapshots(snapshotManager, 1, 0)
t.Logf("Creating 1 more snapshot")
chunkList3 := uploadRandomChunks(snapshotManager, chunkSize, numberOfChunks)
createTestSnapshot(snapshotManager, "repository1", 3, now-2*day-3600, now-1*day-60, chunkList3, "tag")
t.Logf("Removing snapshot repository1 revision 2 without --exclusive")
snapshotManager.PruneSnapshots("repository1", "repository1", []int{2}, []string{}, []string{}, false, false, []string{}, false, false, false, numberOfThreads)
t.Logf("Prune without removing any snapshots but with --exclusive")
snapshotManager.PruneSnapshots("repository1", "repository1", []int{}, []string{}, []string{}, false, true, []string{}, false, false, false, numberOfThreads)
checkTestSnapshots(snapshotManager, 1, 0)
}