18794: Wait up to 10s for rails to notice config change.
authorTom Clegg <tom@curii.com>
Thu, 5 May 2022 15:23:56 +0000 (11:23 -0400)
committerTom Clegg <tom@curii.com>
Thu, 5 May 2022 15:23:56 +0000 (11:23 -0400)
Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tom@curii.com>

lib/controller/rails_restart_test.go

index 75dd22b4a98ccbf5c04b3795ca9428710daffc04..bb307d32160cd2f9ff3d679f0b9da9a1a9ba99c9 100644 (file)
@@ -13,6 +13,7 @@ import (
        "net/http"
        "net/url"
        "os"
        "net/http"
        "net/url"
        "os"
+       "strings"
        "time"
 
        "git.arvados.org/arvados.git/lib/config"
        "time"
 
        "git.arvados.org/arvados.git/lib/config"
@@ -72,14 +73,17 @@ func (s *railsRestartSuite) TestConfigReload(c *check.C) {
        newhash := fmt.Sprintf("%x", sha256.Sum256(append(confdata, '\n')))
        c.Logf("newhash %s", newhash)
 
        newhash := fmt.Sprintf("%x", sha256.Sum256(append(confdata, '\n')))
        c.Logf("newhash %s", newhash)
 
-       // Wait 2s to give RailsAPI's 1 Hz reload_config thread time
-       // to poll and hit restart.txt
-       time.Sleep(2 * time.Second)
-
-       resp, err = hc.Do(req)
-       c.Assert(err, check.IsNil)
-       c.Check(resp.StatusCode, check.Equals, http.StatusOK)
-       body, err = ioutil.ReadAll(resp.Body)
-       c.Assert(err, check.IsNil)
+       // Wait for RailsAPI's 1 Hz reload_config thread to poll and
+       // hit restart.txt
+       for deadline := time.Now().Add(10 * time.Second); time.Now().Before(deadline); time.Sleep(time.Second) {
+               resp, err = hc.Do(req)
+               c.Assert(err, check.IsNil)
+               c.Check(resp.StatusCode, check.Equals, http.StatusOK)
+               body, err = ioutil.ReadAll(resp.Body)
+               c.Assert(err, check.IsNil)
+               if strings.Contains(string(body), newhash) {
+                       break
+               }
+       }
        c.Check(string(body), check.Matches, `(?ms).*`+newhash+`.*`)
 }
        c.Check(string(body), check.Matches, `(?ms).*`+newhash+`.*`)
 }