8
11
gc "launchpad.net/gocheck"
13
"launchpad.net/juju-core/state"
10
14
coretesting "launchpad.net/juju-core/testing"
11
15
jc "launchpad.net/juju-core/testing/checkers"
12
16
"launchpad.net/juju-core/testing/testbase"
15
19
func TestPackage(t *stdtesting.T) {
20
coretesting.MgoTestPackage(t)
19
23
var _ = gc.Suite(&updaterSuite{})
45
49
c.Assert(watcher.stopped, jc.IsTrue)
48
type testPublisherContext struct {
52
func (*updaterSuite) TestWatchMachinesWaitsForMachinePollers(c *gc.C) {
53
// We can't see that the machine pollers are still alive directly,
54
// but we can make the machine's Refresh method block,
55
// and test that watchMachinesLoop only terminates
57
waitRefresh := make(chan struct{})
62
refresh: func() error {
63
// Signal that we're in Refresh.
64
waitRefresh <- struct{}{}
65
// Wait to be unblocked.
70
dyingc := make(chan struct{})
71
context := &testUpdaterContext{
73
newMachineContextFunc: func() machineContext {
74
return &testMachineContext{
75
getAddresses: addressesGetter(c, "i1234", testAddrs, nil),
79
getMachineFunc: func(id string) (machine, error) {
80
c.Check(id, gc.Equals, m.id)
84
watcher := &testMachinesWatcher{
85
changes: make(chan []string),
87
done := make(chan error)
89
done <- watchMachinesLoop(context, watcher)
91
// Send two changes; the first one should start the machineLoop;
92
// the second should call Refresh.
93
watcher.changes <- []string{"99"}
94
watcher.changes <- []string{"99"}
95
// Wait for the machineLoop to call Refresh
98
c.Logf("poller called Refresh")
99
case <-time.After(coretesting.LongWait):
100
c.Fatalf("timed out waiting for machine to be refreshed")
102
close(context.dyingc)
103
// Wait a little while to be sure that watchMachinesLoop is
104
// actually waiting for its machine poller to finish.
107
c.Fatalf("watchMachinesLoop terminated prematurely: %v", err)
108
case <-time.After(coretesting.ShortWait):
111
waitRefresh <- struct{}{}
114
c.Assert(err, gc.IsNil)
115
case <-time.After(coretesting.LongWait):
116
c.Fatalf("timed out waiting for watchMachinesLoop to terminate")
118
c.Assert(watcher.stopped, jc.IsTrue)
121
type testUpdaterContext struct {
49
122
newMachineContextFunc func() machineContext
50
123
getMachineFunc func(id string) (machine, error)
51
124
dyingc chan struct{}
54
func (context *testPublisherContext) newMachineContext() machineContext {
127
func (context *testUpdaterContext) newMachineContext() machineContext {
55
128
return context.newMachineContextFunc()
58
func (context *testPublisherContext) getMachine(id string) (machine, error) {
131
func (context *testUpdaterContext) getMachine(id string) (machine, error) {
59
132
return context.getMachineFunc(id)
62
func (context *testPublisherContext) dying() <-chan struct{} {
135
func (context *testUpdaterContext) dying() <-chan struct{} {
63
136
return context.dyingc