4b115229b403bc69aadd275a0177b00d4d171f79
[arvados.git] / sdk / go / dispatch / dispatch_test.go
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: Apache-2.0
4
5 package dispatch
6
7 import (
8         "time"
9
10         "git.arvados.org/arvados.git/sdk/go/arvados"
11         "git.arvados.org/arvados.git/sdk/go/arvadosclient"
12         "git.arvados.org/arvados.git/sdk/go/arvadostest"
13         . "gopkg.in/check.v1"
14 )
15
16 // Gocheck boilerplate
17 var _ = Suite(&suite{})
18
19 type suite struct{}
20
21 func (s *suite) SetUpSuite(c *C) {
22         arvadostest.StartAPI()
23 }
24
25 func (s *suite) TearDownSuite(c *C) {
26         arvadostest.StopAPI()
27 }
28
29 func (s *suite) TestTrackContainer(c *C) {
30         arv, err := arvadosclient.MakeArvadosClient()
31         c.Assert(err, Equals, nil)
32         arv.ApiToken = arvadostest.Dispatch1Token
33
34         done := make(chan bool, 1)
35         time.AfterFunc(10*time.Second, func() { done <- false })
36         d := &Dispatcher{
37                 Arv: arv,
38                 RunContainer: func(dsp *Dispatcher, ctr arvados.Container, status <-chan arvados.Container) error {
39                         for ctr := range status {
40                                 c.Logf("%#v", ctr)
41                         }
42                         done <- true
43                         return nil
44                 },
45         }
46         d.TrackContainer(arvadostest.QueuedContainerUUID)
47         c.Assert(<-done, Equals, true)
48 }