1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
14 "git.curoverse.com/arvados.git/sdk/go/arvados"
15 "git.curoverse.com/arvados.git/sdk/go/arvadosclient"
16 "git.curoverse.com/arvados.git/sdk/go/arvadostest"
17 "git.curoverse.com/arvados.git/sdk/go/keepclient"
18 "github.com/sirupsen/logrus"
19 check "gopkg.in/check.v1"
22 var _ = check.Suite(&integrationSuite{})
24 type integrationSuite struct {
26 keepClient *keepclient.KeepClient
29 func (s *integrationSuite) SetUpSuite(c *check.C) {
33 arvadostest.ResetEnv()
34 arvadostest.StartAPI()
35 arvadostest.StartKeep(4, true)
37 arv, err := arvadosclient.MakeArvadosClient()
38 arv.ApiToken = arvadostest.DataManagerToken
39 c.Assert(err, check.IsNil)
41 s.keepClient, err = keepclient.MakeKeepClient(arv)
42 c.Assert(err, check.IsNil)
43 s.putReplicas(c, "foo", 4)
44 s.putReplicas(c, "bar", 1)
47 func (s *integrationSuite) putReplicas(c *check.C, data string, replicas int) {
48 s.keepClient.Want_replicas = replicas
49 _, _, err := s.keepClient.PutB([]byte(data))
50 c.Assert(err, check.IsNil)
53 func (s *integrationSuite) TearDownSuite(c *check.C) {
57 arvadostest.StopKeep(4)
61 func (s *integrationSuite) SetUpTest(c *check.C) {
63 Client: arvados.Client{
64 APIHost: os.Getenv("ARVADOS_API_HOST"),
65 AuthToken: arvadostest.DataManagerToken,
68 KeepServiceTypes: []string{"disk"},
69 RunPeriod: arvados.Duration(time.Second),
73 func (s *integrationSuite) TestBalanceAPIFixtures(c *check.C) {
74 var logBuf *bytes.Buffer
75 for iter := 0; iter < 20; iter++ {
76 logBuf := &bytes.Buffer{}
77 logger := logrus.New()
87 Metrics: newMetrics(),
89 nextOpts, err := bal.Run(s.config, opts)
90 c.Check(err, check.IsNil)
91 c.Check(nextOpts.SafeRendezvousState, check.Not(check.Equals), "")
92 c.Check(nextOpts.CommitPulls, check.Equals, true)
94 c.Check(logBuf.String(), check.Matches, `(?ms).*ChangeSet{Pulls:1.*`)
95 c.Check(logBuf.String(), check.Not(check.Matches), `(?ms).*ChangeSet{.*Trashes:[^0]}*`)
96 } else if strings.Contains(logBuf.String(), "ChangeSet{Pulls:0") {
99 time.Sleep(200 * time.Millisecond)
101 c.Check(logBuf.String(), check.Not(check.Matches), `(?ms).*0 replicas (0 blocks, 0 bytes) underreplicated.*`)