backend: Improve test for pagination in list

This commit is contained in:
Alexander Neumann 2017-09-17 11:36:45 +02:00
parent dd49e2b12d
commit 649c536250

View file

@ -11,6 +11,7 @@ import (
"reflect"
"sort"
"strings"
"sync"
"testing"
"time"
@ -250,14 +251,37 @@ func (s *Suite) TestList(t *testing.T) {
const numTestFiles = 1233
list1 := restic.NewIDSet()
var wg sync.WaitGroup
input := make(chan int, numTestFiles)
for i := 0; i < numTestFiles; i++ {
data := []byte(fmt.Sprintf("random test blob %v", i))
id := restic.Hash(data)
h := restic.Handle{Type: restic.DataFile, Name: id.String()}
err := b.Save(context.TODO(), h, bytes.NewReader(data))
if err != nil {
t.Fatal(err)
}
input <- i
}
close(input)
output := make(chan restic.ID, numTestFiles)
for worker := 0; worker < 5; worker++ {
wg.Add(1)
go func() {
defer wg.Done()
for i := range input {
data := []byte(fmt.Sprintf("random test blob %v", i))
id := restic.Hash(data)
h := restic.Handle{Type: restic.DataFile, Name: id.String()}
err := b.Save(context.TODO(), h, bytes.NewReader(data))
if err != nil {
t.Fatal(err)
}
output <- id
}
}()
}
wg.Wait()
close(output)
for id := range output {
list1.Insert(id)
}