mirror of
https://github.com/octoleo/restic.git
synced 2024-12-23 11:28:54 +00:00
Add benchmark for WalkTree with high-latency repo
This commit is contained in:
parent
50fd8f6f44
commit
4cc9d946de
BIN
testdata/walktree-test-repo.tar.gz
vendored
Normal file
BIN
testdata/walktree-test-repo.tar.gz
vendored
Normal file
Binary file not shown.
59
walk_test.go
59
walk_test.go
@ -4,9 +4,13 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/restic/restic"
|
||||
"github.com/restic/restic/backend"
|
||||
"github.com/restic/restic/pack"
|
||||
"github.com/restic/restic/pipe"
|
||||
"github.com/restic/restic/repository"
|
||||
. "github.com/restic/restic/test"
|
||||
)
|
||||
|
||||
@ -84,3 +88,58 @@ func TestWalkTree(t *testing.T) {
|
||||
"wrong number of entries: %v != %v", fsEntries, treeEntries)
|
||||
}
|
||||
}
|
||||
|
||||
type delayRepo struct {
|
||||
repo *repository.Repository
|
||||
delay time.Duration
|
||||
}
|
||||
|
||||
func (d delayRepo) LoadJSONPack(t pack.BlobType, id backend.ID, dst interface{}) error {
|
||||
time.Sleep(d.delay)
|
||||
return d.repo.LoadJSONPack(t, id, dst)
|
||||
}
|
||||
|
||||
var repoFixture = filepath.Join("testdata", "walktree-test-repo.tar.gz")
|
||||
|
||||
func TestDelayedWalkTree(t *testing.T) {
|
||||
WithTestEnvironment(t, repoFixture, func(repodir string) {
|
||||
repo := OpenLocalRepo(t, repodir)
|
||||
OK(t, repo.LoadIndex())
|
||||
|
||||
root, err := backend.ParseID("937a2f64f736c64ee700c6ab06f840c68c94799c288146a0e81e07f4c94254da")
|
||||
OK(t, err)
|
||||
|
||||
dr := delayRepo{repo, 100 * time.Millisecond}
|
||||
|
||||
// start tree walker
|
||||
treeJobs := make(chan restic.WalkTreeJob)
|
||||
go restic.WalkTree(dr, root, nil, treeJobs)
|
||||
|
||||
for range treeJobs {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func BenchmarkDelayedWalkTree(t *testing.B) {
|
||||
WithTestEnvironment(t, repoFixture, func(repodir string) {
|
||||
repo := OpenLocalRepo(t, repodir)
|
||||
OK(t, repo.LoadIndex())
|
||||
|
||||
root, err := backend.ParseID("937a2f64f736c64ee700c6ab06f840c68c94799c288146a0e81e07f4c94254da")
|
||||
OK(t, err)
|
||||
|
||||
dr := delayRepo{repo, 10 * time.Millisecond}
|
||||
|
||||
t.ResetTimer()
|
||||
|
||||
for i := 0; i < t.N; i++ {
|
||||
// start tree walker
|
||||
treeJobs := make(chan restic.WalkTreeJob)
|
||||
go restic.WalkTree(dr, root, nil, treeJobs)
|
||||
|
||||
for range treeJobs {
|
||||
// fmt.Printf("job: %v\n", job)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user