1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
14 "git.arvados.org/arvados.git/lib/config"
15 "git.arvados.org/arvados.git/sdk/go/arvados"
16 "git.arvados.org/arvados.git/sdk/go/arvadosclient"
17 "git.arvados.org/arvados.git/sdk/go/arvadostest"
18 "git.arvados.org/arvados.git/sdk/go/ctxlog"
19 "git.arvados.org/arvados.git/sdk/go/keepclient"
20 "github.com/prometheus/client_golang/prometheus"
21 "github.com/sirupsen/logrus"
22 check "gopkg.in/check.v1"
25 var _ = check.Suite(&integrationSuite{})
27 type integrationSuite struct {
28 config *arvados.Cluster
29 client *arvados.Client
30 keepClient *keepclient.KeepClient
33 func (s *integrationSuite) SetUpSuite(c *check.C) {
37 arvadostest.ResetEnv()
38 arvadostest.StartAPI()
39 arvadostest.StartKeep(4, true)
41 arv, err := arvadosclient.MakeArvadosClient()
42 arv.ApiToken = arvadostest.SystemRootToken
43 c.Assert(err, check.IsNil)
45 s.keepClient, err = keepclient.MakeKeepClient(arv)
46 c.Assert(err, check.IsNil)
47 s.putReplicas(c, "foo", 4)
48 s.putReplicas(c, "bar", 1)
51 func (s *integrationSuite) putReplicas(c *check.C, data string, replicas int) {
52 s.keepClient.Want_replicas = replicas
53 _, _, err := s.keepClient.PutB([]byte(data))
54 c.Assert(err, check.IsNil)
57 func (s *integrationSuite) TearDownSuite(c *check.C) {
61 arvadostest.StopKeep(4)
65 func (s *integrationSuite) SetUpTest(c *check.C) {
66 cfg, err := config.NewLoader(nil, ctxlog.TestLogger(c)).Load()
67 c.Assert(err, check.Equals, nil)
68 s.config, err = cfg.GetCluster("")
69 c.Assert(err, check.Equals, nil)
70 s.config.Collections.BalancePeriod = arvados.Duration(time.Second)
72 s.client = &arvados.Client{
73 APIHost: os.Getenv("ARVADOS_API_HOST"),
74 AuthToken: arvadostest.SystemRootToken,
79 func (s *integrationSuite) TestBalanceAPIFixtures(c *check.C) {
80 var logBuf bytes.Buffer
81 for iter := 0; iter < 20; iter++ {
83 logger := logrus.New()
93 Metrics: newMetrics(prometheus.NewRegistry()),
95 nextOpts, err := bal.Run(s.client, s.config, opts)
96 c.Check(err, check.IsNil)
97 c.Check(nextOpts.SafeRendezvousState, check.Not(check.Equals), "")
98 c.Check(nextOpts.CommitPulls, check.Equals, true)
100 c.Check(logBuf.String(), check.Matches, `(?ms).*ChangeSet{Pulls:1.*`)
101 c.Check(logBuf.String(), check.Not(check.Matches), `(?ms).*ChangeSet{.*Trashes:[^0]}*`)
102 } else if strings.Contains(logBuf.String(), "ChangeSet{Pulls:0") {
105 time.Sleep(200 * time.Millisecond)
107 c.Check(logBuf.String(), check.Not(check.Matches), `(?ms).*0 replicas (0 blocks, 0 bytes) underreplicated.*`)