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"
20 check "gopkg.in/check.v1"
23 var _ = check.Suite(&integrationSuite{})
25 type integrationSuite struct {
27 keepClient *keepclient.KeepClient
30 func (s *integrationSuite) SetUpSuite(c *check.C) {
34 arvadostest.ResetEnv()
35 arvadostest.StartAPI()
36 arvadostest.StartKeep(4, true)
38 arv, err := arvadosclient.MakeArvadosClient()
39 arv.ApiToken = arvadostest.DataManagerToken
40 c.Assert(err, check.IsNil)
42 s.keepClient, err = keepclient.MakeKeepClient(arv)
43 c.Assert(err, check.IsNil)
44 s.putReplicas(c, "foo", 4)
45 s.putReplicas(c, "bar", 1)
48 func (s *integrationSuite) putReplicas(c *check.C, data string, replicas int) {
49 s.keepClient.Want_replicas = replicas
50 _, _, err := s.keepClient.PutB([]byte(data))
51 c.Assert(err, check.IsNil)
54 func (s *integrationSuite) TearDownSuite(c *check.C) {
58 arvadostest.StopKeep(4)
62 func (s *integrationSuite) SetUpTest(c *check.C) {
64 Client: arvados.Client{
65 APIHost: os.Getenv("ARVADOS_API_HOST"),
66 AuthToken: arvadostest.DataManagerToken,
69 KeepServiceTypes: []string{"disk"},
70 RunPeriod: arvados.Duration(time.Second),
74 func (s *integrationSuite) TestBalanceAPIFixtures(c *check.C) {
75 var logBuf *bytes.Buffer
76 for iter := 0; iter < 20; iter++ {
77 logBuf := &bytes.Buffer{}
78 logger := logrus.New()
88 Metrics: newMetrics(),
90 nextOpts, err := bal.Run(s.config, opts)
91 c.Check(err, check.IsNil)
92 c.Check(nextOpts.SafeRendezvousState, check.Not(check.Equals), "")
93 c.Check(nextOpts.CommitPulls, check.Equals, true)
95 c.Check(logBuf.String(), check.Matches, `(?ms).*ChangeSet{Pulls:1.*`)
96 c.Check(logBuf.String(), check.Not(check.Matches), `(?ms).*ChangeSet{.*Trashes:[^0]}*`)
97 } else if strings.Contains(logBuf.String(), "ChangeSet{Pulls:0") {
100 time.Sleep(200 * time.Millisecond)
102 c.Check(logBuf.String(), check.Not(check.Matches), `(?ms).*0 replicas (0 blocks, 0 bytes) underreplicated.*`)