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

View File

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