lib/versioner: Hack to make test coverage stable from run to run

GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/3485
This commit is contained in:
Jakob Borg 2016-08-08 18:27:55 +00:00
parent c2d8c07137
commit dcbf68e104
2 changed files with 12 additions and 0 deletions

View File

@ -35,6 +35,8 @@ type Staggered struct {
mutex sync.Mutex
}
var testCleanDone chan struct{}
func NewStaggered(folderID, folderPath string, params map[string]string) Versioner {
maxAge, err := strconv.ParseInt(params["maxAge"], 10, 0)
if err != nil {
@ -72,6 +74,9 @@ func NewStaggered(folderID, folderPath string, params map[string]string) Version
go func() {
s.clean()
if testCleanDone != nil {
close(testCleanDone)
}
for _ = range time.Tick(time.Duration(cleanInterval) * time.Second) {
s.clean()
}

View File

@ -7,6 +7,7 @@
package versioner
import (
"os"
"sort"
"strconv"
"testing"
@ -58,7 +59,13 @@ func TestStaggeredVersioningVersionCount(t *testing.T) {
}
sort.Strings(delete)
os.MkdirAll("testdata/.stversions", 0755)
defer os.RemoveAll("testdata")
testCleanDone = make(chan struct{})
v := NewStaggered("", "testdata", map[string]string{"maxAge": strconv.Itoa(365 * 86400)}).(Staggered)
<-testCleanDone
rem := v.toRemove(files, now)
if diff, equal := messagediff.PrettyDiff(delete, rem); !equal {
t.Errorf("Incorrect deleted files; got %v, expected %v\n%v", rem, delete, diff)