diff --git a/fstest/testserver/init.d/README.md b/fstest/testserver/init.d/README.md index 3a27cd48a..aedc67eb4 100644 --- a/fstest/testserver/init.d/README.md +++ b/fstest/testserver/init.d/README.md @@ -12,10 +12,15 @@ required. When start is run it should output config parameters for that remote. If a `_connect` parameter is output then that will be used for a -connection test. For example if `_connect=127.0.0.1:80` then a TCP +connection test. For example if `_connect=127.0.0.1:80` then a TCP connection will be made to `127.0.0.1:80` and only when that succeeds will the test continue. +If in addition to `_connect`, `_connect_delay=5s` is also present then +after the connection succeeds rclone will wait `5s` before continuing. +This is for servers that aren't quite ready even though they have +opened their TCP ports. + `run.bash` contains boilerplate to be included in a bash script for interpreting the command line parameters. diff --git a/fstest/testserver/testserver.go b/fstest/testserver/testserver.go index 64a83ed49..2d7fe44bd 100644 --- a/fstest/testserver/testserver.go +++ b/fstest/testserver/testserver.go @@ -74,13 +74,14 @@ var matchLine = regexp.MustCompile(`^([a-zA-Z_]+)=(.*)$`) // Start the server and set its env vars // Call with the mutex held func start(name string) error { + fs.Logf(name, "Starting server") out, err := run(name, "start") if err != nil { return err } - fs.Logf(name, "Starting server") // parse the output and set environment vars from it var connect string + var connectDelay time.Duration for _, line := range bytes.Split(out, []byte("\n")) { line = bytes.TrimSpace(line) part := matchLine.FindSubmatch(line) @@ -89,6 +90,12 @@ func start(name string) error { if string(key) == "_connect" { connect = string(value) continue + } else if string(key) == "_connect_delay" { + connectDelay, err = time.ParseDuration(string(value)) + if err != nil { + return fmt.Errorf("bad _connect_delay: %w", err) + } + continue } // fs.Debugf(name, "key = %q, envKey = %q, value = %q", key, envKey(name, string(key)), value) @@ -99,6 +106,7 @@ func start(name string) error { } } if connect == "" { + fs.Logf(name, "Started server") return nil } // If we got a _connect value then try to connect to it @@ -108,7 +116,7 @@ func start(name string) error { if i != 0 { time.Sleep(time.Second) } - fs.Debugf(name, "Attempting to connect to %q try %d/%d", connect, i, maxTries) + fs.Logf(name, "Attempting to connect to %q try %d/%d", connect, i, maxTries) conn, err := net.DialTimeout("tcp", connect, time.Second) if err != nil { fs.Debugf(name, "Connection to %q failed try %d/%d: %v", connect, i, maxTries, err) @@ -126,7 +134,11 @@ func start(name string) error { // Try again continue } - //time.Sleep(30 * time.Second) + if connectDelay > 0 { + fs.Logf(name, "Connect delay %v", connectDelay) + time.Sleep(connectDelay) + } + fs.Logf(name, "Started server and connected to %q", connect) return nil } return fmt.Errorf("failed to connect to %q on %q", name, connect)