~juju-qa/ubuntu/xenial/juju/xenial-2.0-beta3

« back to all changes in this revision

Viewing changes to src/github.com/juju/juju/apiserver/common/watch_test.go

  • Committer: Martin Packman
  • Date: 2016-03-30 19:31:08 UTC
  • mfrom: (1.1.41)
  • Revision ID: martin.packman@canonical.com-20160330193108-h9iz3ak334uk0z5r
Merge new upstream source 2.0~beta3

Show diffs side-by-side

added added

removed removed

Lines of Context:
9
9
        "github.com/juju/names"
10
10
        jc "github.com/juju/testing/checkers"
11
11
        gc "gopkg.in/check.v1"
12
 
        "launchpad.net/tomb"
13
12
 
14
13
        "github.com/juju/juju/apiserver/common"
15
14
        "github.com/juju/juju/apiserver/params"
28
27
}
29
28
 
30
29
func (a *fakeAgentEntityWatcher) Watch() state.NotifyWatcher {
31
 
        changes := make(chan struct{}, 1)
 
30
        w := apiservertesting.NewFakeNotifyWatcher()
32
31
        // Simulate initial event.
33
 
        changes <- struct{}{}
34
 
        return &fakeNotifyWatcher{changes: changes}
35
 
}
36
 
 
37
 
type fakeNotifyWatcher struct {
38
 
        tomb    tomb.Tomb
39
 
        changes chan struct{}
40
 
}
41
 
 
42
 
func (w *fakeNotifyWatcher) Stop() error {
43
 
        w.Kill()
44
 
        return w.Wait()
45
 
}
46
 
 
47
 
func (w *fakeNotifyWatcher) Kill() {
48
 
        w.tomb.Kill(nil)
49
 
        w.tomb.Done()
50
 
}
51
 
 
52
 
func (w *fakeNotifyWatcher) Wait() error {
53
 
        return w.tomb.Wait()
54
 
}
55
 
 
56
 
func (w *fakeNotifyWatcher) Err() error {
57
 
        return w.tomb.Err()
58
 
}
59
 
 
60
 
func (w *fakeNotifyWatcher) Changes() <-chan struct{} {
61
 
        return w.changes
 
32
        w.C <- struct{}{}
 
33
        return w
62
34
}
63
35
 
64
36
func (*agentEntityWatcherSuite) TestWatch(c *gc.C) {
127
99
var _ = gc.Suite(&multiNotifyWatcherSuite{})
128
100
 
129
101
func (*multiNotifyWatcherSuite) TestMultiNotifyWatcher(c *gc.C) {
130
 
        w0 := &fakeNotifyWatcher{changes: make(chan struct{}, 1)}
131
 
        w1 := &fakeNotifyWatcher{changes: make(chan struct{}, 1)}
132
 
        w0.changes <- struct{}{}
133
 
        w1.changes <- struct{}{}
 
102
        w0 := apiservertesting.NewFakeNotifyWatcher()
 
103
        w0.C <- struct{}{}
 
104
        w1 := apiservertesting.NewFakeNotifyWatcher()
 
105
        w1.C <- struct{}{}
134
106
 
135
107
        mw := common.NewMultiNotifyWatcher(w0, w1)
136
108
        defer statetesting.AssertStop(c, mw)
138
110
        wc := statetesting.NewNotifyWatcherC(c, nopSyncStarter{}, mw)
139
111
        wc.AssertOneChange()
140
112
 
141
 
        w0.changes <- struct{}{}
 
113
        w0.C <- struct{}{}
142
114
        wc.AssertOneChange()
143
 
        w1.changes <- struct{}{}
 
115
        w1.C <- struct{}{}
144
116
        wc.AssertOneChange()
145
117
 
146
 
        w0.changes <- struct{}{}
147
 
        w1.changes <- struct{}{}
 
118
        w0.C <- struct{}{}
 
119
        w1.C <- struct{}{}
148
120
        wc.AssertOneChange()
149
121
}
150
122
 
151
123
func (*multiNotifyWatcherSuite) TestMultiNotifyWatcherStop(c *gc.C) {
152
 
        w0 := &fakeNotifyWatcher{changes: make(chan struct{}, 1)}
153
 
        w1 := &fakeNotifyWatcher{changes: make(chan struct{}, 1)}
154
 
        w0.changes <- struct{}{}
155
 
        w1.changes <- struct{}{}
 
124
        w0 := apiservertesting.NewFakeNotifyWatcher()
 
125
        w0.C <- struct{}{}
 
126
        w1 := apiservertesting.NewFakeNotifyWatcher()
 
127
        w1.C <- struct{}{}
156
128
 
157
129
        mw := common.NewMultiNotifyWatcher(w0, w1)
158
130
        wc := statetesting.NewNotifyWatcherC(c, nopSyncStarter{}, mw)