From 2d124e053cf7cf891b4e513b72894cc37d8f347f Mon Sep 17 00:00:00 2001 From: Simon Frei Date: Tue, 20 Aug 2019 10:17:11 +0200 Subject: [PATCH] test: Get integration tests up to speed (config, build and test fixes) (#5962) --- lib/rc/rc.go | 5 +++++ test/filetype_test.go | 7 ++++--- test/h1/config.xml | 14 ++++++++++---- test/h2/config.xml | 17 ++++++++++++----- test/h3/config.xml | 14 ++++++++++---- test/override_test.go | 5 +++-- test/reset_test.go | 11 +++++++++++ test/symlink_test.go | 7 ++++--- 8 files changed, 59 insertions(+), 21 deletions(-) diff --git a/lib/rc/rc.go b/lib/rc/rc.go index b87c0fcbb..78e07b4d2 100644 --- a/lib/rc/rc.go +++ b/lib/rc/rc.go @@ -155,6 +155,11 @@ func (p *Process) Stop() (*os.ProcessState, error) { return p.cmd.ProcessState, p.stopErr } +// Stopped returns a channel that will be closed when Syncthing has stopped. +func (p *Process) Stopped() chan struct{} { + return p.stopped +} + // Get performs an HTTP GET and returns the bytes and/or an error. Any non-200 // return code is returned as an error. func (p *Process) Get(path string) ([]byte, error) { diff --git a/test/filetype_test.go b/test/filetype_test.go index 922892716..8e55accde 100644 --- a/test/filetype_test.go +++ b/test/filetype_test.go @@ -14,6 +14,7 @@ import ( "testing" "github.com/syncthing/syncthing/lib/config" + "github.com/syncthing/syncthing/lib/events" "github.com/syncthing/syncthing/lib/protocol" "github.com/syncthing/syncthing/lib/rc" ) @@ -21,7 +22,7 @@ import ( func TestFileTypeChange(t *testing.T) { // Use no versioning id, _ := protocol.DeviceIDFromString(id2) - cfg, _ := config.Load("h2/config.xml", id) + cfg, _ := config.Load("h2/config.xml", id, events.NoopLogger) fld := cfg.Folders()["default"] fld.Versioning = config.VersioningConfiguration{} cfg.SetFolder(fld) @@ -35,7 +36,7 @@ func TestFileTypeChange(t *testing.T) { func TestFileTypeChangeSimpleVersioning(t *testing.T) { // Use simple versioning id, _ := protocol.DeviceIDFromString(id2) - cfg, _ := config.Load("h2/config.xml", id) + cfg, _ := config.Load("h2/config.xml", id, events.NoopLogger) fld := cfg.Folders()["default"] fld.Versioning = config.VersioningConfiguration{ Type: "simple", @@ -52,7 +53,7 @@ func TestFileTypeChangeSimpleVersioning(t *testing.T) { func TestFileTypeChangeStaggeredVersioning(t *testing.T) { // Use staggered versioning id, _ := protocol.DeviceIDFromString(id2) - cfg, _ := config.Load("h2/config.xml", id) + cfg, _ := config.Load("h2/config.xml", id, events.NoopLogger) fld := cfg.Folders()["default"] fld.Versioning = config.VersioningConfiguration{ Type: "staggered", diff --git a/test/h1/config.xml b/test/h1/config.xml index 5bd47cc87..3875c1697 100644 --- a/test/h1/config.xml +++ b/test/h1/config.xml @@ -1,4 +1,4 @@ - + basic @@ -20,7 +20,8 @@ false 25 .stfolder - true + false + 0 basic @@ -41,7 +42,8 @@ false 25 .stfolder - true + false + 0
tcp://127.0.0.1:22004
@@ -129,6 +131,10 @@ ~ true 0 - 0 + https://crash.syncthing.net/newcrash + true + 180 + 20 + default
diff --git a/test/h2/config.xml b/test/h2/config.xml index ac49499fd..afa1821bb 100644 --- a/test/h2/config.xml +++ b/test/h2/config.xml @@ -1,4 +1,4 @@ - + basic @@ -19,7 +19,8 @@ false 25 .stfolder - true + false + 0 basic @@ -40,7 +41,8 @@ false 25 .stfolder - true + false + 0 basic @@ -61,7 +63,8 @@ false 25 .stfolder - true + false + 0
tcp://127.0.0.1:22001
@@ -132,6 +135,10 @@ ~ true 0 - 0 + https://crash.syncthing.net/newcrash + true + 180 + 20 + default
diff --git a/test/h3/config.xml b/test/h3/config.xml index e29e22e85..7d2acfe46 100644 --- a/test/h3/config.xml +++ b/test/h3/config.xml @@ -1,4 +1,4 @@ - + basic @@ -21,7 +21,8 @@ false 25 .stfolder - true + false + 0 basic @@ -42,7 +43,8 @@ false 25 .stfolder - true + false + 0
tcp://127.0.0.1:22001
@@ -113,6 +115,10 @@ ~ true 0 - 0 + https://crash.syncthing.net/newcrash + true + 180 + 20 + default
diff --git a/test/override_test.go b/test/override_test.go index 01ea3c3a9..c8b0787ea 100644 --- a/test/override_test.go +++ b/test/override_test.go @@ -17,6 +17,7 @@ import ( "time" "github.com/syncthing/syncthing/lib/config" + "github.com/syncthing/syncthing/lib/events" "github.com/syncthing/syncthing/lib/protocol" "github.com/syncthing/syncthing/lib/rc" ) @@ -24,7 +25,7 @@ import ( func TestOverride(t *testing.T) { // Enable "send-only" on s1/default id, _ := protocol.DeviceIDFromString(id1) - cfg, _ := config.Load("h1/config.xml", id) + cfg, _ := config.Load("h1/config.xml", id, events.NoopLogger) fld := cfg.Folders()["default"] fld.Type = config.FolderTypeSendOnly cfg.SetFolder(fld) @@ -156,7 +157,7 @@ get to completion when in sendOnly/sendRecv mode. Needs fixing. func TestOverrideIgnores(t *testing.T) { // Enable "sendOnly" on s1/default id, _ := protocol.DeviceIDFromString(id1) - cfg, _ := config.Load("h1/config.xml", id) + cfg, _ := config.Load("h1/config.xml", id, events.NoopLogger) fld := cfg.Folders()["default"] fld.ReadOnly = true cfg.SetFolder(fld) diff --git a/test/reset_test.go b/test/reset_test.go index bb9711fe4..aa5aa6c2a 100644 --- a/test/reset_test.go +++ b/test/reset_test.go @@ -17,6 +17,7 @@ import ( "os" "path/filepath" "testing" + "time" ) func TestReset(t *testing.T) { @@ -76,6 +77,11 @@ func TestReset(t *testing.T) { } // ---- Syncthing exits here ---- + select { + case <-p.Stopped(): + case <-time.After(20 * time.Second): + t.Fatal("timed out before Syncthing stopped") + } p = startInstance(t, 1) defer p.Stop() // Not checkedStop, because Syncthing will exit on its own @@ -115,6 +121,11 @@ func TestReset(t *testing.T) { } // ---- Syncthing exits here ---- + select { + case <-p.Stopped(): + case <-time.After(20 * time.Second): + t.Fatal("timed out before Syncthing stopped") + } p = startInstance(t, 1) defer checkedStop(t, p) diff --git a/test/symlink_test.go b/test/symlink_test.go index 282db30f7..13cb2bc70 100644 --- a/test/symlink_test.go +++ b/test/symlink_test.go @@ -14,6 +14,7 @@ import ( "testing" "github.com/syncthing/syncthing/lib/config" + "github.com/syncthing/syncthing/lib/events" "github.com/syncthing/syncthing/lib/protocol" "github.com/syncthing/syncthing/lib/rc" ) @@ -25,7 +26,7 @@ func TestSymlinks(t *testing.T) { // Use no versioning id, _ := protocol.DeviceIDFromString(id2) - cfg, _ := config.Load("h2/config.xml", id) + cfg, _ := config.Load("h2/config.xml", id, events.NoopLogger) fld := cfg.Folders()["default"] fld.Versioning = config.VersioningConfiguration{} cfg.SetFolder(fld) @@ -43,7 +44,7 @@ func TestSymlinksSimpleVersioning(t *testing.T) { // Use simple versioning id, _ := protocol.DeviceIDFromString(id2) - cfg, _ := config.Load("h2/config.xml", id) + cfg, _ := config.Load("h2/config.xml", id, events.NoopLogger) fld := cfg.Folders()["default"] fld.Versioning = config.VersioningConfiguration{ Type: "simple", @@ -64,7 +65,7 @@ func TestSymlinksStaggeredVersioning(t *testing.T) { // Use staggered versioning id, _ := protocol.DeviceIDFromString(id2) - cfg, _ := config.Load("h2/config.xml", id) + cfg, _ := config.Load("h2/config.xml", id, events.NoopLogger) fld := cfg.Folders()["default"] fld.Versioning = config.VersioningConfiguration{ Type: "staggered",