lib/model: Improve TestIssue5063 (#5509)

* lib/model: Improve TestIssue5063

* add not that helpful issue comment
This commit is contained in:
Simon Frei 2019-02-06 00:07:21 +01:00 committed by Audrius Butkevicius
parent 5df8219bcb
commit e538797ce1

View File

@ -17,6 +17,7 @@ import (
"os" "os"
"path/filepath" "path/filepath"
"runtime" "runtime"
"runtime/pprof"
"strconv" "strconv"
"strings" "strings"
"sync" "sync"
@ -1116,14 +1117,20 @@ func TestIssue4897(t *testing.T) {
} }
} }
// TestIssue5063 is about a panic in connection with modifying config in quick
// succession, related with auto accepted folders. It's unclear what exactly, a
// relevant bit seems to be here:
// PR-comments: https://github.com/syncthing/syncthing/pull/5069/files#r203146546
// Issue: https://github.com/syncthing/syncthing/pull/5509
func TestIssue5063(t *testing.T) { func TestIssue5063(t *testing.T) {
testOs := &fatalOs{t} testOs := &fatalOs{t}
wcfg, m := newState(defaultAutoAcceptCfg) wcfg, m := newState(defaultAutoAcceptCfg)
defer testOs.Remove(wcfg.ConfigPath()) defer testOs.Remove(wcfg.ConfigPath())
addAndVerify := func(wg *sync.WaitGroup) { wg := sync.WaitGroup{}
id := srand.String(8)
addAndVerify := func(id string) {
m.ClusterConfig(device1, protocol.ClusterConfig{ m.ClusterConfig(device1, protocol.ClusterConfig{
Folders: []protocol.Folder{ Folders: []protocol.Folder{
{ {
@ -1132,20 +1139,37 @@ func TestIssue5063(t *testing.T) {
}, },
}, },
}) })
testOs.RemoveAll(id)
wg.Done()
if fcfg, ok := wcfg.Folder(id); !ok || !fcfg.SharedWith(device1) { if fcfg, ok := wcfg.Folder(id); !ok || !fcfg.SharedWith(device1) {
t.Error("expected shared", id) t.Error("expected shared", id)
} }
wg.Done()
} }
wg := &sync.WaitGroup{} reps := 10
for i := 0; i <= 10; i++ { ids := make([]string, reps)
for i := 0; i < reps; i++ {
wg.Add(1) wg.Add(1)
go addAndVerify(wg) ids[i] = srand.String(8)
go addAndVerify(ids[i])
} }
defer func() {
for _, id := range ids {
testOs.RemoveAll(id)
}
}()
defer m.Stop()
finished := make(chan struct{})
go func() {
wg.Wait() wg.Wait()
close(finished)
}()
select {
case <-finished:
case <-time.After(10 * time.Second):
pprof.Lookup("goroutine").WriteTo(os.Stdout, 1)
t.Fatal("Timed out before all devices were added")
}
} }
func TestAutoAcceptRejected(t *testing.T) { func TestAutoAcceptRejected(t *testing.T) {