1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
15 "git.curoverse.com/arvados.git/sdk/go/arvados"
16 "git.curoverse.com/arvados.git/sdk/go/arvadosclient"
17 "git.curoverse.com/arvados.git/sdk/go/arvadostest"
18 "git.curoverse.com/arvados.git/sdk/go/keepclient"
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"},
73 func (s *integrationSuite) TestBalanceAPIFixtures(c *check.C) {
74 var logBuf *bytes.Buffer
75 for iter := 0; iter < 20; iter++ {
76 logBuf := &bytes.Buffer{}
80 Logger: log.New(logBuf, "", log.LstdFlags),
82 nextOpts, err := (&Balancer{}).Run(s.config, opts)
83 c.Check(err, check.IsNil)
84 c.Check(nextOpts.SafeRendezvousState, check.Not(check.Equals), "")
85 c.Check(nextOpts.CommitPulls, check.Equals, true)
87 c.Check(logBuf.String(), check.Matches, `(?ms).*ChangeSet{Pulls:1.*`)
88 c.Check(logBuf.String(), check.Not(check.Matches), `(?ms).*ChangeSet{.*Trashes:[^0]}*`)
89 } else if strings.Contains(logBuf.String(), "ChangeSet{Pulls:0") {
92 time.Sleep(200 * time.Millisecond)
94 c.Check(logBuf.String(), check.Not(check.Matches), `(?ms).*0 replicas (0 blocks, 0 bytes) underreplicated.*`)