lib/model: Close conn on dev pause (fixes #5873) (#5874)

This commit is contained in:
Simon Frei 2019-07-19 19:37:29 +02:00 committed by Jakob Borg
parent 1894123d3c
commit 2b622d0774
2 changed files with 30 additions and 0 deletions

View File

@ -2549,6 +2549,7 @@ func (m *model) CommitConfiguration(from, to config.Configuration) bool {
if toCfg.Paused {
l.Infoln("Pausing", deviceID)
m.closeConn(deviceID, errDevicePaused)
events.Default.Log(events.DevicePaused, map[string]string{"device": deviceID.String()})
} else {
events.Default.Log(events.DeviceResumed, map[string]string{"device": deviceID.String()})

View File

@ -26,6 +26,7 @@ import (
"github.com/syncthing/syncthing/lib/config"
"github.com/syncthing/syncthing/lib/db"
"github.com/syncthing/syncthing/lib/events"
"github.com/syncthing/syncthing/lib/fs"
"github.com/syncthing/syncthing/lib/ignore"
"github.com/syncthing/syncthing/lib/osutil"
@ -3303,3 +3304,31 @@ func TestConnCloseOnRestart(t *testing.T) {
t.Fatal("Timed out before connection was closed")
}
}
func TestDevicePause(t *testing.T) {
sub := events.Default.Subscribe(events.DevicePaused)
defer events.Default.Unsubscribe(sub)
m, _, fcfg := setupModelWithConnection()
defer cleanupModelAndRemoveDir(m, fcfg.Filesystem().URI())
m.pmut.RLock()
closed := m.closed[device1]
m.pmut.RUnlock()
dev := m.cfg.Devices()[device1]
dev.Paused = true
m.cfg.SetDevice(dev)
timeout := time.NewTimer(5 * time.Second)
select {
case <-sub.C():
select {
case <-closed:
case <-timeout.C:
t.Fatal("Timed out before connection was closed")
}
case <-timeout.C:
t.Fatal("Timed out before device was paused")
}
}