12 "git.curoverse.com/arvados.git/sdk/go/arvados"
13 "git.curoverse.com/arvados.git/sdk/go/arvadosclient"
14 "git.curoverse.com/arvados.git/sdk/go/arvadostest"
15 "git.curoverse.com/arvados.git/sdk/go/keepclient"
17 check "gopkg.in/check.v1"
20 var _ = check.Suite(&integrationSuite{})
22 type integrationSuite struct {
24 keepClient *keepclient.KeepClient
27 func (s *integrationSuite) SetUpSuite(c *check.C) {
31 arvadostest.ResetEnv()
32 arvadostest.StartAPI()
33 arvadostest.StartKeep(4, true)
35 arv, err := arvadosclient.MakeArvadosClient()
36 arv.ApiToken = arvadostest.DataManagerToken
37 c.Assert(err, check.IsNil)
38 s.keepClient = &keepclient.KeepClient{
40 Client: &http.Client{},
42 c.Assert(s.keepClient.DiscoverKeepServers(), 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"},
72 func (s *integrationSuite) TestBalanceAPIFixtures(c *check.C) {
73 var logBuf *bytes.Buffer
74 for iter := 0; iter < 20; iter++ {
75 logBuf := &bytes.Buffer{}
79 Logger: log.New(logBuf, "", log.LstdFlags),
81 nextOpts, err := (&Balancer{}).Run(s.config, opts)
82 c.Check(err, check.IsNil)
83 c.Check(nextOpts.SafeRendezvousState, check.Not(check.Equals), "")
84 c.Check(nextOpts.CommitPulls, check.Equals, true)
86 c.Check(logBuf.String(), check.Matches, `(?ms).*ChangeSet{Pulls:1.*`)
87 c.Check(logBuf.String(), check.Not(check.Matches), `(?ms).*ChangeSet{.*Trashes:[^0]}*`)
88 } else if strings.Contains(logBuf.String(), "ChangeSet{Pulls:0") {
91 time.Sleep(200 * time.Millisecond)
93 c.Check(logBuf.String(), check.Not(check.Matches), `(?ms).*0 replicas (0 blocks, 0 bytes) underreplicated.*`)