17217: Remove crufty test util funcs.
authorTom Clegg <tom@curii.com>
Tue, 24 Aug 2021 20:07:43 +0000 (16:07 -0400)
committerTom Clegg <tom@curii.com>
Thu, 26 Aug 2021 04:05:56 +0000 (00:05 -0400)
Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tom@curii.com>

15 files changed:
lib/costanalyzer/costanalyzer_test.go
lib/recovercollection/cmd_test.go
sdk/go/arvadostest/run_servers.go
sdk/go/dispatch/dispatch_test.go
sdk/go/keepclient/keepclient_test.go
services/arv-git-httpd/auth_handler_test.go
services/arv-git-httpd/integration_test.go
services/crunch-dispatch-local/crunch-dispatch-local_test.go
services/crunch-dispatch-slurm/crunch-dispatch-slurm_test.go
services/keep-balance/integration_test.go
services/keep-web/server_test.go
services/keepproxy/keepproxy_test.go
services/keepstore/pull_worker_integration_test.go
tools/keep-block-check/keep-block-check_test.go
tools/keep-rsync/keep-rsync_test.go

index 9fee66e1ddcb3f96463fe240a11f905be46db0cc..2975e3b3de06332d16b525efed7ebc9097fcdf82 100644 (file)
@@ -33,7 +33,6 @@ func (s *Suite) TearDownSuite(c *check.C) {
 }
 
 func (s *Suite) SetUpSuite(c *check.C) {
 }
 
 func (s *Suite) SetUpSuite(c *check.C) {
-       arvadostest.StartAPI()
        arvadostest.StartKeep(2, true)
 
        // Get the various arvados, arvadosclient, and keep client objects
        arvadostest.StartKeep(2, true)
 
        // Get the various arvados, arvadosclient, and keep client objects
index 7b3c8e1b4ed95b59f5e155fcb0392b7fe0d58a26..f891e5567757beb47189c1352911fdb4653767bf 100644 (file)
@@ -27,7 +27,6 @@ var _ = check.Suite(&Suite{})
 type Suite struct{}
 
 func (*Suite) SetUpSuite(c *check.C) {
 type Suite struct{}
 
 func (*Suite) SetUpSuite(c *check.C) {
-       arvadostest.StartAPI()
        arvadostest.StartKeep(2, true)
 }
 
        arvadostest.StartKeep(2, true)
 }
 
index 5b01db5c4bbda594fe1c5fc5353a47bf2c60e49e..8f70c5ee26a97b20ac9ac04bd3434ca946eee0b9 100644 (file)
@@ -5,53 +5,40 @@
 package arvadostest
 
 import (
 package arvadostest
 
 import (
-       "bufio"
-       "bytes"
+       "crypto/tls"
        "fmt"
        "io/ioutil"
        "log"
        "fmt"
        "io/ioutil"
        "log"
+       "net/http"
        "os"
        "os/exec"
        "path"
        "strconv"
        "strings"
        "os"
        "os/exec"
        "path"
        "strconv"
        "strings"
+
+       "gopkg.in/check.v1"
 )
 
 var authSettings = make(map[string]string)
 
 )
 
 var authSettings = make(map[string]string)
 
-// ResetEnv resets test env
+// ResetEnv resets ARVADOS_* env vars to whatever they were the first
+// time this func was called.
+//
+// Call it from your SetUpTest or SetUpSuite func if your tests modify
+// env vars.
 func ResetEnv() {
 func ResetEnv() {
-       for k, v := range authSettings {
-               os.Setenv(k, v)
-       }
-}
-
-// APIHost returns the address:port of the current test server.
-func APIHost() string {
-       h := authSettings["ARVADOS_API_HOST"]
-       if h == "" {
-               log.Fatal("arvadostest.APIHost() was called but authSettings is not populated")
-       }
-       return h
-}
-
-// ParseAuthSettings parses auth settings from given input
-func ParseAuthSettings(authScript []byte) {
-       scanner := bufio.NewScanner(bytes.NewReader(authScript))
-       for scanner.Scan() {
-               line := scanner.Text()
-               if 0 != strings.Index(line, "export ") {
-                       log.Printf("Ignoring: %v", line)
-                       continue
+       if len(authSettings) == 0 {
+               for _, e := range os.Environ() {
+                       e := strings.SplitN(e, "=", 2)
+                       if len(e) == 2 {
+                               authSettings[e[0]] = e[1]
+                       }
                }
                }
-               toks := strings.SplitN(strings.Replace(line, "export ", "", 1), "=", 2)
-               if len(toks) == 2 {
-                       authSettings[toks[0]] = toks[1]
-               } else {
-                       log.Fatalf("Could not parse: %v", line)
+       } else {
+               for k, v := range authSettings {
+                       os.Setenv(k, v)
                }
        }
                }
        }
-       log.Printf("authSettings: %v", authSettings)
 }
 
 var pythonTestDir string
 }
 
 var pythonTestDir string
@@ -80,34 +67,17 @@ func chdirToPythonTests() {
        }
 }
 
        }
 }
 
-// StartAPI starts test API server
-func StartAPI() {
-       cwd, _ := os.Getwd()
-       defer os.Chdir(cwd)
-       chdirToPythonTests()
-
-       cmd := exec.Command("python", "run_test_server.py", "start", "--auth", "admin")
-       cmd.Stdin = nil
-       cmd.Stderr = os.Stderr
-
-       authScript, err := cmd.Output()
-       if err != nil {
-               log.Fatalf("%+v: %s", cmd.Args, err)
-       }
-       ParseAuthSettings(authScript)
-       ResetEnv()
-}
-
-// StopAPI stops test API server
-func StopAPI() {
-       cwd, _ := os.Getwd()
-       defer os.Chdir(cwd)
-       chdirToPythonTests()
-
-       cmd := exec.Command("python", "run_test_server.py", "stop")
-       bgRun(cmd)
-       // Without Wait, "go test" in go1.10.1 tends to hang. https://github.com/golang/go/issues/24050
-       cmd.Wait()
+func ResetDB(c *check.C) {
+       hc := http.Client{Transport: &http.Transport{
+               TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
+       }}
+       req, err := http.NewRequest("POST", "https://"+os.Getenv("ARVADOS_TEST_API_HOST")+"/database/reset", nil)
+       c.Assert(err, check.IsNil)
+       req.Header.Set("Authorization", "Bearer "+AdminToken)
+       resp, err := hc.Do(req)
+       c.Assert(err, check.IsNil)
+       defer resp.Body.Close()
+       c.Check(resp.StatusCode, check.Equals, http.StatusOK)
 }
 
 // StartKeep starts the given number of keep servers,
 }
 
 // StartKeep starts the given number of keep servers,
index 4b115229b403bc69aadd275a0177b00d4d171f79..2a9d84639ef8ce1e4d9a987acdafdb947cafa961 100644 (file)
@@ -18,14 +18,6 @@ var _ = Suite(&suite{})
 
 type suite struct{}
 
 
 type suite struct{}
 
-func (s *suite) SetUpSuite(c *C) {
-       arvadostest.StartAPI()
-}
-
-func (s *suite) TearDownSuite(c *C) {
-       arvadostest.StopAPI()
-}
-
 func (s *suite) TestTrackContainer(c *C) {
        arv, err := arvadosclient.MakeArvadosClient()
        c.Assert(err, Equals, nil)
 func (s *suite) TestTrackContainer(c *C) {
        arv, err := arvadosclient.MakeArvadosClient()
        c.Assert(err, Equals, nil)
index 62268fa463e6dee07083a815e9b97536e83a5c40..cddf03bc37de5ba4661674e62029585dee1e61b6 100644 (file)
@@ -52,13 +52,11 @@ func pythonDir() string {
 }
 
 func (s *ServerRequiredSuite) SetUpSuite(c *C) {
 }
 
 func (s *ServerRequiredSuite) SetUpSuite(c *C) {
-       arvadostest.StartAPI()
        arvadostest.StartKeep(2, false)
 }
 
 func (s *ServerRequiredSuite) TearDownSuite(c *C) {
        arvadostest.StopKeep(2)
        arvadostest.StartKeep(2, false)
 }
 
 func (s *ServerRequiredSuite) TearDownSuite(c *C) {
        arvadostest.StopKeep(2)
-       arvadostest.StopAPI()
 }
 
 func (s *ServerRequiredSuite) SetUpTest(c *C) {
 }
 
 func (s *ServerRequiredSuite) SetUpTest(c *C) {
index 4e1a47dcb25bdff037f05b382e953a4b6627b1fe..688b256dcb0c20aeb5fb7a30fd7144eb1e25f01c 100644 (file)
@@ -26,14 +26,6 @@ type AuthHandlerSuite struct {
        cluster *arvados.Cluster
 }
 
        cluster *arvados.Cluster
 }
 
-func (s *AuthHandlerSuite) SetUpSuite(c *check.C) {
-       arvadostest.StartAPI()
-}
-
-func (s *AuthHandlerSuite) TearDownSuite(c *check.C) {
-       arvadostest.StopAPI()
-}
-
 func (s *AuthHandlerSuite) SetUpTest(c *check.C) {
        arvadostest.ResetEnv()
        repoRoot, err := filepath.Abs("../api/tmp/git/test")
 func (s *AuthHandlerSuite) SetUpTest(c *check.C) {
        arvadostest.ResetEnv()
        repoRoot, err := filepath.Abs("../api/tmp/git/test")
index 7da85ee7472af663a7307d7e91c46282689d98f7..93a46e22482380bc57162c01d18727fbe0250274 100644 (file)
@@ -33,14 +33,6 @@ type IntegrationSuite struct {
        cluster     *arvados.Cluster
 }
 
        cluster     *arvados.Cluster
 }
 
-func (s *IntegrationSuite) SetUpSuite(c *check.C) {
-       arvadostest.StartAPI()
-}
-
-func (s *IntegrationSuite) TearDownSuite(c *check.C) {
-       arvadostest.StopAPI()
-}
-
 func (s *IntegrationSuite) SetUpTest(c *check.C) {
        arvadostest.ResetEnv()
 
 func (s *IntegrationSuite) SetUpTest(c *check.C) {
        arvadostest.ResetEnv()
 
index 92b8d2adcd6fe22e20c66afc1d4f803521ccd545..7e8c42c25c193bbf3bf26bdefe80082b1ae50ff8 100644 (file)
@@ -39,15 +39,10 @@ var initialArgs []string
 
 func (s *TestSuite) SetUpSuite(c *C) {
        initialArgs = os.Args
 
 func (s *TestSuite) SetUpSuite(c *C) {
        initialArgs = os.Args
-       arvadostest.StartAPI()
        runningCmds = make(map[string]*exec.Cmd)
        logrus.SetFormatter(&logrus.TextFormatter{DisableColors: true})
 }
 
        runningCmds = make(map[string]*exec.Cmd)
        logrus.SetFormatter(&logrus.TextFormatter{DisableColors: true})
 }
 
-func (s *TestSuite) TearDownSuite(c *C) {
-       arvadostest.StopAPI()
-}
-
 func (s *TestSuite) SetUpTest(c *C) {
        args := []string{"crunch-dispatch-local"}
        os.Args = args
 func (s *TestSuite) SetUpTest(c *C) {
        args := []string{"crunch-dispatch-local"}
        os.Args = args
index e7a89db23c8743b3e2934a5c26f12a446a5bd6a9..cf83257dad5a86d77826f0cd07154389bc40efc5 100644 (file)
@@ -42,7 +42,8 @@ type IntegrationSuite struct {
 }
 
 func (s *IntegrationSuite) SetUpTest(c *C) {
 }
 
 func (s *IntegrationSuite) SetUpTest(c *C) {
-       arvadostest.StartAPI()
+       arvadostest.ResetEnv()
+       arvadostest.ResetDB(c)
        os.Setenv("ARVADOS_API_TOKEN", arvadostest.Dispatch1Token)
        s.disp = Dispatcher{}
        s.disp.cluster = &arvados.Cluster{}
        os.Setenv("ARVADOS_API_TOKEN", arvadostest.Dispatch1Token)
        s.disp = Dispatcher{}
        s.disp.cluster = &arvados.Cluster{}
@@ -52,7 +53,7 @@ func (s *IntegrationSuite) SetUpTest(c *C) {
 
 func (s *IntegrationSuite) TearDownTest(c *C) {
        arvadostest.ResetEnv()
 
 func (s *IntegrationSuite) TearDownTest(c *C) {
        arvadostest.ResetEnv()
-       arvadostest.StopAPI()
+       arvadostest.ResetDB(c)
 }
 
 type slurmFake struct {
 }
 
 type slurmFake struct {
index 52e6149158253bdff24705dcb8b6fb7a00f8cb02..a6cc3281042739191921dcc8cda04d3a4e938d59 100644 (file)
@@ -38,7 +38,6 @@ func (s *integrationSuite) SetUpSuite(c *check.C) {
                c.Skip("-short")
        }
        arvadostest.ResetEnv()
                c.Skip("-short")
        }
        arvadostest.ResetEnv()
-       arvadostest.StartAPI()
        arvadostest.StartKeep(4, true)
 
        arv, err := arvadosclient.MakeArvadosClient()
        arvadostest.StartKeep(4, true)
 
        arv, err := arvadosclient.MakeArvadosClient()
@@ -62,7 +61,6 @@ func (s *integrationSuite) TearDownSuite(c *check.C) {
                c.Skip("-short")
        }
        arvadostest.StopKeep(4)
                c.Skip("-short")
        }
        arvadostest.StopKeep(4)
-       arvadostest.StopAPI()
 }
 
 func (s *integrationSuite) SetUpTest(c *check.C) {
 }
 
 func (s *integrationSuite) SetUpTest(c *check.C) {
index a65a48892ae75d709ae578e3354fe58803bddac1..21d767208740dedd148051714410747e0f0a8da2 100644 (file)
@@ -410,7 +410,7 @@ func (s *IntegrationSuite) TestMetrics(c *check.C) {
 }
 
 func (s *IntegrationSuite) SetUpSuite(c *check.C) {
 }
 
 func (s *IntegrationSuite) SetUpSuite(c *check.C) {
-       arvadostest.StartAPI()
+       arvadostest.ResetDB(c)
        arvadostest.StartKeep(2, true)
 
        arv, err := arvadosclient.MakeArvadosClient()
        arvadostest.StartKeep(2, true)
 
        arv, err := arvadosclient.MakeArvadosClient()
@@ -426,7 +426,6 @@ func (s *IntegrationSuite) SetUpSuite(c *check.C) {
 
 func (s *IntegrationSuite) TearDownSuite(c *check.C) {
        arvadostest.StopKeep(2)
 
 func (s *IntegrationSuite) TearDownSuite(c *check.C) {
        arvadostest.StopKeep(2)
-       arvadostest.StopAPI()
 }
 
 func (s *IntegrationSuite) SetUpTest(c *check.C) {
 }
 
 func (s *IntegrationSuite) SetUpTest(c *check.C) {
index 4bdb4202026e3aeb2705fa79faa0ef3e7a296307..052109bf29b925af9ef8945274ce099c96e9f112 100644 (file)
@@ -76,7 +76,6 @@ func closeListener() {
 }
 
 func (s *ServerRequiredSuite) SetUpSuite(c *C) {
 }
 
 func (s *ServerRequiredSuite) SetUpSuite(c *C) {
-       arvadostest.StartAPI()
        arvadostest.StartKeep(2, false)
 }
 
        arvadostest.StartKeep(2, false)
 }
 
@@ -86,11 +85,9 @@ func (s *ServerRequiredSuite) SetUpTest(c *C) {
 
 func (s *ServerRequiredSuite) TearDownSuite(c *C) {
        arvadostest.StopKeep(2)
 
 func (s *ServerRequiredSuite) TearDownSuite(c *C) {
        arvadostest.StopKeep(2)
-       arvadostest.StopAPI()
 }
 
 func (s *ServerRequiredConfigYmlSuite) SetUpSuite(c *C) {
 }
 
 func (s *ServerRequiredConfigYmlSuite) SetUpSuite(c *C) {
-       arvadostest.StartAPI()
        // config.yml defines 4 keepstores
        arvadostest.StartKeep(4, false)
 }
        // config.yml defines 4 keepstores
        arvadostest.StartKeep(4, false)
 }
@@ -101,11 +98,9 @@ func (s *ServerRequiredConfigYmlSuite) SetUpTest(c *C) {
 
 func (s *ServerRequiredConfigYmlSuite) TearDownSuite(c *C) {
        arvadostest.StopKeep(4)
 
 func (s *ServerRequiredConfigYmlSuite) TearDownSuite(c *C) {
        arvadostest.StopKeep(4)
-       arvadostest.StopAPI()
 }
 
 func (s *NoKeepServerSuite) SetUpSuite(c *C) {
 }
 
 func (s *NoKeepServerSuite) SetUpSuite(c *C) {
-       arvadostest.StartAPI()
        // We need API to have some keep services listed, but the
        // services themselves should be unresponsive.
        arvadostest.StartKeep(2, false)
        // We need API to have some keep services listed, but the
        // services themselves should be unresponsive.
        arvadostest.StartKeep(2, false)
@@ -116,10 +111,6 @@ func (s *NoKeepServerSuite) SetUpTest(c *C) {
        arvadostest.ResetEnv()
 }
 
        arvadostest.ResetEnv()
 }
 
-func (s *NoKeepServerSuite) TearDownSuite(c *C) {
-       arvadostest.StopAPI()
-}
-
 func runProxy(c *C, bogusClientToken bool, loadKeepstoresFromConfig bool, kp *arvados.UploadDownloadRolePermissions) (*keepclient.KeepClient, *bytes.Buffer) {
        cfg, err := config.NewLoader(nil, ctxlog.TestLogger(c)).Load()
        c.Assert(err, Equals, nil)
 func runProxy(c *C, bogusClientToken bool, loadKeepstoresFromConfig bool, kp *arvados.UploadDownloadRolePermissions) (*keepclient.KeepClient, *bytes.Buffer) {
        cfg, err := config.NewLoader(nil, ctxlog.TestLogger(c)).Load()
        c.Assert(err, Equals, nil)
index ad7ec15e7275a248fdcd723eb9a3598cea513ad4..eb7fe5fd6730421937b8c1efb49e4f201f6c1ca2 100644 (file)
@@ -58,7 +58,6 @@ func (s *HandlerSuite) TestPullWorkerIntegration_GetNonExistingLocator(c *check.
        }
 
        pullRequest := s.setupPullWorkerIntegrationTest(c, testData, false)
        }
 
        pullRequest := s.setupPullWorkerIntegrationTest(c, testData, false)
-       defer arvadostest.StopAPI()
        defer arvadostest.StopKeep(2)
 
        s.performPullWorkerIntegrationTest(testData, pullRequest, c)
        defer arvadostest.StopKeep(2)
 
        s.performPullWorkerIntegrationTest(testData, pullRequest, c)
@@ -76,7 +75,6 @@ func (s *HandlerSuite) TestPullWorkerIntegration_GetExistingLocator(c *check.C)
        }
 
        pullRequest := s.setupPullWorkerIntegrationTest(c, testData, true)
        }
 
        pullRequest := s.setupPullWorkerIntegrationTest(c, testData, true)
-       defer arvadostest.StopAPI()
        defer arvadostest.StopKeep(2)
 
        s.performPullWorkerIntegrationTest(testData, pullRequest, c)
        defer arvadostest.StopKeep(2)
 
        s.performPullWorkerIntegrationTest(testData, pullRequest, c)
index 9f409e6af05b5c3afebd154013b1a168bc1c0d09..e6519fb3773b790fbec300885858e55e8765d1d5 100644 (file)
@@ -43,12 +43,7 @@ var TestHash2 = "aaaac516f788aec4f30932ffb6395c39"
 
 var blobSignatureTTL = time.Duration(2*7*24) * time.Hour
 
 
 var blobSignatureTTL = time.Duration(2*7*24) * time.Hour
 
-func (s *ServerRequiredSuite) SetUpSuite(c *C) {
-       arvadostest.StartAPI()
-}
-
 func (s *ServerRequiredSuite) TearDownSuite(c *C) {
 func (s *ServerRequiredSuite) TearDownSuite(c *C) {
-       arvadostest.StopAPI()
        arvadostest.ResetEnv()
 }
 
        arvadostest.ResetEnv()
 }
 
index 38968ae128709c97240aaec0c358468c146fe4ce..45ed3f67f52cc41e16782bd3a6c6144e3d64ecad 100644 (file)
@@ -43,12 +43,7 @@ var _ = Suite(&DoMainTestSuite{})
 
 type ServerRequiredSuite struct{}
 
 
 type ServerRequiredSuite struct{}
 
-func (s *ServerRequiredSuite) SetUpSuite(c *C) {
-       arvadostest.StartAPI()
-}
-
 func (s *ServerRequiredSuite) TearDownSuite(c *C) {
 func (s *ServerRequiredSuite) TearDownSuite(c *C) {
-       arvadostest.StopAPI()
        arvadostest.ResetEnv()
 }
 
        arvadostest.ResetEnv()
 }