mirror of
https://github.com/octoleo/syncthing.git
synced 2024-11-09 14:50:56 +00:00
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:
parent
c2d8c07137
commit
dcbf68e104
@ -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()
|
||||
}
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user