Merge lp:~fwereade/juju-core/reinstate-relation-watch-tests into lp:~go-bot/juju-core/trunk
- reinstate-relation-watch-tests
- Merge into trunk
Proposed by
William Reade
Status: | Merged | ||||
---|---|---|---|---|---|
Approved by: | William Reade | ||||
Approved revision: | no longer in the source branch. | ||||
Merged at revision: | 1735 | ||||
Proposed branch: | lp:~fwereade/juju-core/reinstate-relation-watch-tests | ||||
Merge into: | lp:~go-bot/juju-core/trunk | ||||
Diff against target: |
518 lines (+484/-3) 1 file modified
state/relationunit_test.go (+484/-3) |
||||
To merge this branch: | bzr merge lp:~fwereade/juju-core/reinstate-relation-watch-tests | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Juju Engineering | Pending | ||
Review via email: mp+183189@code.launchpad.net |
Commit message
state: reinstate accidentally-
Aside from removal of the tests for the Joined field (which is no longer sent,
because it's redundant (preexisting change)), this was a mechanical rename
job from the original. It's reassuring to observe that behaviour had not
otherwise changed detectably in the interim.
Description of the change
state: reinstate accidentally-
Aside from removal of the tests for the Joined field (which is no longer sent,
because it's redundant (preexisting change)), this was a mechanical rename
job from the original. It's reassuring to observe that behaviour had not
otherwise changed detectably in the interim.
To post a comment you must log in.
Revision history for this message
William Reade (fwereade) wrote : | # |
Revision history for this message
Roger Peppe (rogpeppe) wrote : | # |
On 2013/08/30 14:30:20, fwereade wrote:
> Please take a look.
assuming this is mechanical and pre-reviewed, LGTM.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'state/relationunit_test.go' | |||
2 | --- state/relationunit_test.go 2013-08-20 15:29:55 +0000 | |||
3 | +++ state/relationunit_test.go 2013-08-30 14:19:19 +0000 | |||
4 | @@ -4,7 +4,9 @@ | |||
5 | 4 | package state_test | 4 | package state_test |
6 | 5 | 5 | ||
7 | 6 | import ( | 6 | import ( |
8 | 7 | "fmt" | ||
9 | 7 | "sort" | 8 | "sort" |
10 | 9 | "strconv" | ||
11 | 8 | "time" | 10 | "time" |
12 | 9 | 11 | ||
13 | 10 | gc "launchpad.net/gocheck" | 12 | gc "launchpad.net/gocheck" |
14 | @@ -14,9 +16,11 @@ | |||
15 | 14 | "launchpad.net/juju-core/state" | 16 | "launchpad.net/juju-core/state" |
16 | 15 | "launchpad.net/juju-core/state/testing" | 17 | "launchpad.net/juju-core/state/testing" |
17 | 16 | coretesting "launchpad.net/juju-core/testing" | 18 | coretesting "launchpad.net/juju-core/testing" |
19 | 17 | "launchpad.net/juju-core/testing/checkers" | 19 | jc "launchpad.net/juju-core/testing/checkers" |
20 | 18 | ) | 20 | ) |
21 | 19 | 21 | ||
22 | 22 | type RUs []*state.RelationUnit | ||
23 | 23 | |||
24 | 20 | type RelationUnitSuite struct { | 24 | type RelationUnitSuite struct { |
25 | 21 | ConnSuite | 25 | ConnSuite |
26 | 22 | } | 26 | } |
27 | @@ -325,7 +329,7 @@ | |||
28 | 325 | c.Assert(err, gc.IsNil) | 329 | c.Assert(err, gc.IsNil) |
29 | 326 | s.assertInScope(c, pr.ru1, false) | 330 | s.assertInScope(c, pr.ru1, false) |
30 | 327 | err = rel.Refresh() | 331 | err = rel.Refresh() |
32 | 328 | c.Assert(err, checkers.Satisfies, errors.IsNotFoundError) | 332 | c.Assert(err, jc.Satisfies, errors.IsNotFoundError) |
33 | 329 | 333 | ||
34 | 330 | // The settings were not themselves actually deleted yet... | 334 | // The settings were not themselves actually deleted yet... |
35 | 331 | assertSettings() | 335 | assertSettings() |
36 | @@ -741,4 +745,481 @@ | |||
37 | 741 | return u, ru | 745 | return u, ru |
38 | 742 | } | 746 | } |
39 | 743 | 747 | ||
41 | 744 | type RUs []*state.RelationUnit | 748 | type WatchScopeSuite struct { |
42 | 749 | ConnSuite | ||
43 | 750 | } | ||
44 | 751 | |||
45 | 752 | var _ = gc.Suite(&WatchScopeSuite{}) | ||
46 | 753 | |||
47 | 754 | func (s *WatchScopeSuite) TestPeer(c *gc.C) { | ||
48 | 755 | // Create a service and get a peer relation. | ||
49 | 756 | riak, err := s.State.AddService("riak", s.AddTestingCharm(c, "riak")) | ||
50 | 757 | c.Assert(err, gc.IsNil) | ||
51 | 758 | riakEP, err := riak.Endpoint("ring") | ||
52 | 759 | c.Assert(err, gc.IsNil) | ||
53 | 760 | rels, err := riak.Relations() | ||
54 | 761 | c.Assert(err, gc.IsNil) | ||
55 | 762 | c.Assert(rels, gc.HasLen, 1) | ||
56 | 763 | rel := rels[0] | ||
57 | 764 | |||
58 | 765 | // Add some units to the service and set their private addresses; get | ||
59 | 766 | // the relevant RelationUnits. | ||
60 | 767 | // (Private addresses should be set by their unit agents on | ||
61 | 768 | // startup; this test does not include that, but Join expects | ||
62 | 769 | // the information to be available, and uses it to populate the | ||
63 | 770 | // relation settings node.) | ||
64 | 771 | addUnit := func(i int) *state.RelationUnit { | ||
65 | 772 | unit, err := riak.AddUnit() | ||
66 | 773 | c.Assert(err, gc.IsNil) | ||
67 | 774 | err = unit.SetPrivateAddress(fmt.Sprintf("riak%d.example.com", i)) | ||
68 | 775 | c.Assert(err, gc.IsNil) | ||
69 | 776 | ru, err := rel.Unit(unit) | ||
70 | 777 | c.Assert(err, gc.IsNil) | ||
71 | 778 | c.Assert(ru.Endpoint(), gc.Equals, riakEP) | ||
72 | 779 | return ru | ||
73 | 780 | } | ||
74 | 781 | ru0 := addUnit(0) | ||
75 | 782 | ru1 := addUnit(1) | ||
76 | 783 | ru2 := addUnit(2) | ||
77 | 784 | |||
78 | 785 | // ---------- Single unit ---------- | ||
79 | 786 | |||
80 | 787 | // Start watching the relation from the perspective of the first unit. | ||
81 | 788 | w0 := ru0.Watch() | ||
82 | 789 | defer testing.AssertStop(c, w0) | ||
83 | 790 | s.assertChange(c, w0, nil, nil) | ||
84 | 791 | s.assertNoChange(c, w0) | ||
85 | 792 | |||
86 | 793 | // Join the first unit to the relation, and change the settings, and | ||
87 | 794 | // check that nothing apparently happens. | ||
88 | 795 | err = ru0.EnterScope(nil) | ||
89 | 796 | c.Assert(err, gc.IsNil) | ||
90 | 797 | s0 := changeSettings(c, ru0) | ||
91 | 798 | s.assertNoChange(c, w0) | ||
92 | 799 | |||
93 | 800 | // ---------- Two units ---------- | ||
94 | 801 | |||
95 | 802 | // Now join another unit to the relation... | ||
96 | 803 | err = ru1.EnterScope(nil) | ||
97 | 804 | c.Assert(err, gc.IsNil) | ||
98 | 805 | |||
99 | 806 | // ...and check that the first relation unit sees the change. | ||
100 | 807 | s1, err := ru1.Settings() | ||
101 | 808 | c.Assert(err, gc.IsNil) | ||
102 | 809 | expectChanged := map[string]map[string]interface{}{ | ||
103 | 810 | "riak/1": s1.Map(), | ||
104 | 811 | } | ||
105 | 812 | s.assertChange(c, w0, expectChanged, nil) | ||
106 | 813 | s.assertNoChange(c, w0) | ||
107 | 814 | |||
108 | 815 | // Join again, check it's a no-op. | ||
109 | 816 | err = ru1.EnterScope(nil) | ||
110 | 817 | c.Assert(err, gc.IsNil) | ||
111 | 818 | s.assertNoChange(c, w0) | ||
112 | 819 | |||
113 | 820 | // Start watching the relation from the perspective of the second unit, | ||
114 | 821 | // and check that it sees the right state. | ||
115 | 822 | w1 := ru1.Watch() | ||
116 | 823 | defer testing.AssertStop(c, w1) | ||
117 | 824 | expectChanged = map[string]map[string]interface{}{ | ||
118 | 825 | "riak/0": s0.Map(), | ||
119 | 826 | } | ||
120 | 827 | s.assertChange(c, w1, expectChanged, nil) | ||
121 | 828 | s.assertNoChange(c, w1) | ||
122 | 829 | |||
123 | 830 | // ---------- Three units ---------- | ||
124 | 831 | |||
125 | 832 | // Whoa, it works. Ok, check the third unit's opinion of the state. | ||
126 | 833 | w2 := ru2.Watch() | ||
127 | 834 | defer testing.AssertStop(c, w2) | ||
128 | 835 | expectChanged = map[string]map[string]interface{}{ | ||
129 | 836 | "riak/0": s0.Map(), | ||
130 | 837 | "riak/1": s1.Map(), | ||
131 | 838 | } | ||
132 | 839 | s.assertChange(c, w2, expectChanged, nil) | ||
133 | 840 | s.assertNoChange(c, w2) | ||
134 | 841 | |||
135 | 842 | // Join the third unit, and check the first and second units see it. | ||
136 | 843 | err = ru2.EnterScope(nil) | ||
137 | 844 | c.Assert(err, gc.IsNil) | ||
138 | 845 | s2, err := ru2.Settings() | ||
139 | 846 | c.Assert(err, gc.IsNil) | ||
140 | 847 | expectChanged = map[string]map[string]interface{}{ | ||
141 | 848 | "riak/2": s2.Map(), | ||
142 | 849 | } | ||
143 | 850 | s.assertChange(c, w0, expectChanged, nil) | ||
144 | 851 | s.assertNoChange(c, w0) | ||
145 | 852 | s.assertChange(c, w1, expectChanged, nil) | ||
146 | 853 | s.assertNoChange(c, w1) | ||
147 | 854 | |||
148 | 855 | // Change the second unit's settings, and check that only | ||
149 | 856 | // the first and third see changes. | ||
150 | 857 | s1 = changeSettings(c, ru1) | ||
151 | 858 | s.assertNoChange(c, w1) | ||
152 | 859 | expectChanged = map[string]map[string]interface{}{ | ||
153 | 860 | "riak/1": s1.Map(), | ||
154 | 861 | } | ||
155 | 862 | s.assertChange(c, w0, expectChanged, nil) | ||
156 | 863 | s.assertNoChange(c, w0) | ||
157 | 864 | s.assertChange(c, w2, expectChanged, nil) | ||
158 | 865 | s.assertNoChange(c, w2) | ||
159 | 866 | |||
160 | 867 | // ---------- Two units again ---------- | ||
161 | 868 | |||
162 | 869 | // Depart the second unit, and check that the first and third detect it. | ||
163 | 870 | err = ru1.LeaveScope() | ||
164 | 871 | c.Assert(err, gc.IsNil) | ||
165 | 872 | expectDeparted := []string{"riak/1"} | ||
166 | 873 | s.assertChange(c, w0, nil, expectDeparted) | ||
167 | 874 | s.assertNoChange(c, w0) | ||
168 | 875 | s.assertChange(c, w2, nil, expectDeparted) | ||
169 | 876 | s.assertNoChange(c, w2) | ||
170 | 877 | |||
171 | 878 | // Change its settings, and check the others don't observe anything. | ||
172 | 879 | s1 = changeSettings(c, ru1) | ||
173 | 880 | s.assertNoChange(c, w0) | ||
174 | 881 | s.assertNoChange(c, w2) | ||
175 | 882 | |||
176 | 883 | // Check no spurious events showed up on the second unit's watch, and check | ||
177 | 884 | // it closes cleanly. | ||
178 | 885 | s.assertNoChange(c, w1) | ||
179 | 886 | testing.AssertStop(c, w1) | ||
180 | 887 | |||
181 | 888 | // OK, we're done here. Cleanup, and error detection during same, | ||
182 | 889 | // will be handled by the deferred kill/stop calls. Phew. | ||
183 | 890 | } | ||
184 | 891 | |||
185 | 892 | func (s *WatchScopeSuite) TestProviderRequirerGlobal(c *gc.C) { | ||
186 | 893 | // Create a pair of services and a relation between them. | ||
187 | 894 | mysql, err := s.State.AddService("mysql", s.AddTestingCharm(c, "mysql")) | ||
188 | 895 | c.Assert(err, gc.IsNil) | ||
189 | 896 | mysqlEP, err := mysql.Endpoint("server") | ||
190 | 897 | c.Assert(err, gc.IsNil) | ||
191 | 898 | wordpress, err := s.State.AddService("wordpress", s.AddTestingCharm(c, "wordpress")) | ||
192 | 899 | c.Assert(err, gc.IsNil) | ||
193 | 900 | wordpressEP, err := wordpress.Endpoint("db") | ||
194 | 901 | c.Assert(err, gc.IsNil) | ||
195 | 902 | rel, err := s.State.AddRelation(mysqlEP, wordpressEP) | ||
196 | 903 | c.Assert(err, gc.IsNil) | ||
197 | 904 | |||
198 | 905 | // Add some units to the services and set their private addresses. | ||
199 | 906 | addUnit := func(srv *state.Service, sub string, ep state.Endpoint) *state.RelationUnit { | ||
200 | 907 | unit, err := srv.AddUnit() | ||
201 | 908 | c.Assert(err, gc.IsNil) | ||
202 | 909 | ru, err := rel.Unit(unit) | ||
203 | 910 | c.Assert(err, gc.IsNil) | ||
204 | 911 | c.Assert(ru.Endpoint(), gc.Equals, ep) | ||
205 | 912 | return ru | ||
206 | 913 | } | ||
207 | 914 | msru0 := addUnit(mysql, "ms0", mysqlEP) | ||
208 | 915 | msru1 := addUnit(mysql, "ms1", mysqlEP) | ||
209 | 916 | wpru0 := addUnit(wordpress, "wp0", wordpressEP) | ||
210 | 917 | wpru1 := addUnit(wordpress, "wp1", wordpressEP) | ||
211 | 918 | |||
212 | 919 | // ---------- Single role active ---------- | ||
213 | 920 | |||
214 | 921 | // Watch the relation from the perspective of the first provider unit and | ||
215 | 922 | // check initial event. | ||
216 | 923 | msw0 := msru0.Watch() | ||
217 | 924 | defer testing.AssertStop(c, msw0) | ||
218 | 925 | s.assertChange(c, msw0, nil, nil) | ||
219 | 926 | s.assertNoChange(c, msw0) | ||
220 | 927 | |||
221 | 928 | // Join the unit to the relation, change its settings, and check that | ||
222 | 929 | // nothing apparently happens. | ||
223 | 930 | err = msru0.EnterScope(nil) | ||
224 | 931 | c.Assert(err, gc.IsNil) | ||
225 | 932 | mss0 := changeSettings(c, msru0) | ||
226 | 933 | s.assertNoChange(c, msw0) | ||
227 | 934 | |||
228 | 935 | // Join the second provider unit, start its watch, and check what it thinks the | ||
229 | 936 | // state of the relation is. | ||
230 | 937 | err = msru1.EnterScope(nil) | ||
231 | 938 | c.Assert(err, gc.IsNil) | ||
232 | 939 | msw1 := msru1.Watch() | ||
233 | 940 | defer testing.AssertStop(c, msw1) | ||
234 | 941 | s.assertChange(c, msw1, nil, nil) | ||
235 | 942 | s.assertNoChange(c, msw1) | ||
236 | 943 | |||
237 | 944 | // Change the unit's settings, and check that neither provider unit | ||
238 | 945 | // observes any change. | ||
239 | 946 | mss1 := changeSettings(c, msru1) | ||
240 | 947 | s.assertNoChange(c, msw1) | ||
241 | 948 | s.assertNoChange(c, msw0) | ||
242 | 949 | |||
243 | 950 | // ---------- Two roles active ---------- | ||
244 | 951 | |||
245 | 952 | // Start watches from both requirer units' perspectives, and check that | ||
246 | 953 | // they see the provider units. | ||
247 | 954 | expectChanged := map[string]map[string]interface{}{ | ||
248 | 955 | "mysql/0": mss0.Map(), | ||
249 | 956 | "mysql/1": mss1.Map(), | ||
250 | 957 | } | ||
251 | 958 | wpw0 := wpru0.Watch() | ||
252 | 959 | defer testing.AssertStop(c, wpw0) | ||
253 | 960 | s.assertChange(c, wpw0, expectChanged, nil) | ||
254 | 961 | s.assertNoChange(c, wpw0) | ||
255 | 962 | wpw1 := wpru1.Watch() | ||
256 | 963 | defer testing.AssertStop(c, wpw1) | ||
257 | 964 | s.assertChange(c, wpw1, expectChanged, nil) | ||
258 | 965 | s.assertNoChange(c, wpw1) | ||
259 | 966 | |||
260 | 967 | // Join the first requirer unit, and check the provider units see it. | ||
261 | 968 | err = wpru0.EnterScope(nil) | ||
262 | 969 | c.Assert(err, gc.IsNil) | ||
263 | 970 | wps0, err := wpru0.Settings() | ||
264 | 971 | c.Assert(err, gc.IsNil) | ||
265 | 972 | expectChanged = map[string]map[string]interface{}{ | ||
266 | 973 | "wordpress/0": wps0.Map(), | ||
267 | 974 | } | ||
268 | 975 | s.assertChange(c, msw0, expectChanged, nil) | ||
269 | 976 | s.assertNoChange(c, msw0) | ||
270 | 977 | s.assertChange(c, msw1, expectChanged, nil) | ||
271 | 978 | s.assertNoChange(c, msw1) | ||
272 | 979 | |||
273 | 980 | // Join again, check no-op. | ||
274 | 981 | err = wpru0.EnterScope(nil) | ||
275 | 982 | c.Assert(err, gc.IsNil) | ||
276 | 983 | s.assertNoChange(c, msw0) | ||
277 | 984 | s.assertNoChange(c, msw1) | ||
278 | 985 | |||
279 | 986 | // Join the second requirer, and check the provider units see the change. | ||
280 | 987 | err = wpru1.EnterScope(nil) | ||
281 | 988 | c.Assert(err, gc.IsNil) | ||
282 | 989 | wps1, err := wpru1.Settings() | ||
283 | 990 | c.Assert(err, gc.IsNil) | ||
284 | 991 | expectChanged = map[string]map[string]interface{}{ | ||
285 | 992 | "wordpress/1": wps1.Map(), | ||
286 | 993 | } | ||
287 | 994 | s.assertChange(c, msw0, expectChanged, nil) | ||
288 | 995 | s.assertNoChange(c, msw0) | ||
289 | 996 | s.assertChange(c, msw1, expectChanged, nil) | ||
290 | 997 | s.assertNoChange(c, msw1) | ||
291 | 998 | |||
292 | 999 | // Verify that neither requirer has observed any change to the relation. | ||
293 | 1000 | s.assertNoChange(c, wpw0) | ||
294 | 1001 | s.assertNoChange(c, wpw1) | ||
295 | 1002 | |||
296 | 1003 | // Change settings for the first requirer, check providers see it... | ||
297 | 1004 | wps0 = changeSettings(c, wpru0) | ||
298 | 1005 | expectChanged = map[string]map[string]interface{}{ | ||
299 | 1006 | "wordpress/0": wps0.Map(), | ||
300 | 1007 | } | ||
301 | 1008 | s.assertChange(c, msw0, expectChanged, nil) | ||
302 | 1009 | s.assertNoChange(c, msw0) | ||
303 | 1010 | s.assertChange(c, msw1, expectChanged, nil) | ||
304 | 1011 | s.assertNoChange(c, msw1) | ||
305 | 1012 | |||
306 | 1013 | // ...and requirers don't. | ||
307 | 1014 | s.assertNoChange(c, wpw0) | ||
308 | 1015 | s.assertNoChange(c, wpw1) | ||
309 | 1016 | |||
310 | 1017 | // Depart the second requirer and check the providers see it... | ||
311 | 1018 | err = wpru1.LeaveScope() | ||
312 | 1019 | c.Assert(err, gc.IsNil) | ||
313 | 1020 | expectDeparted := []string{"wordpress/1"} | ||
314 | 1021 | s.assertChange(c, msw0, nil, expectDeparted) | ||
315 | 1022 | s.assertNoChange(c, msw0) | ||
316 | 1023 | s.assertChange(c, msw1, nil, expectDeparted) | ||
317 | 1024 | s.assertNoChange(c, msw1) | ||
318 | 1025 | |||
319 | 1026 | // ...and the requirers don't. | ||
320 | 1027 | s.assertNoChange(c, wpw0) | ||
321 | 1028 | s.assertNoChange(c, wpw1) | ||
322 | 1029 | |||
323 | 1030 | // Cleanup handled by defers as before. | ||
324 | 1031 | } | ||
325 | 1032 | |||
326 | 1033 | func (s *WatchScopeSuite) TestProviderRequirerContainer(c *gc.C) { | ||
327 | 1034 | // Create a pair of services and a relation between them. | ||
328 | 1035 | mysql, err := s.State.AddService("mysql", s.AddTestingCharm(c, "mysql")) | ||
329 | 1036 | c.Assert(err, gc.IsNil) | ||
330 | 1037 | mysqlEP, err := mysql.Endpoint("juju-info") | ||
331 | 1038 | c.Assert(err, gc.IsNil) | ||
332 | 1039 | logging, err := s.State.AddService("logging", s.AddTestingCharm(c, "logging")) | ||
333 | 1040 | c.Assert(err, gc.IsNil) | ||
334 | 1041 | loggingEP, err := logging.Endpoint("info") | ||
335 | 1042 | c.Assert(err, gc.IsNil) | ||
336 | 1043 | rel, err := s.State.AddRelation(mysqlEP, loggingEP) | ||
337 | 1044 | c.Assert(err, gc.IsNil) | ||
338 | 1045 | |||
339 | 1046 | // Change mysqlEP to match the endpoint that will actually be used by the relation. | ||
340 | 1047 | mysqlEP.Scope = charm.ScopeContainer | ||
341 | 1048 | |||
342 | 1049 | // Add some units to the services and set their private addresses. | ||
343 | 1050 | addUnits := func(i int) (*state.RelationUnit, *state.RelationUnit) { | ||
344 | 1051 | msu, err := mysql.AddUnit() | ||
345 | 1052 | c.Assert(err, gc.IsNil) | ||
346 | 1053 | msru, err := rel.Unit(msu) | ||
347 | 1054 | c.Assert(err, gc.IsNil) | ||
348 | 1055 | c.Assert(msru.Endpoint(), gc.Equals, mysqlEP) | ||
349 | 1056 | err = msru.EnterScope(nil) | ||
350 | 1057 | c.Assert(err, gc.IsNil) | ||
351 | 1058 | err = msru.LeaveScope() | ||
352 | 1059 | c.Assert(err, gc.IsNil) | ||
353 | 1060 | lgu, err := s.State.Unit("logging/" + strconv.Itoa(i)) | ||
354 | 1061 | c.Assert(err, gc.IsNil) | ||
355 | 1062 | lgru, err := rel.Unit(lgu) | ||
356 | 1063 | c.Assert(err, gc.IsNil) | ||
357 | 1064 | c.Assert(lgru.Endpoint(), gc.Equals, loggingEP) | ||
358 | 1065 | return msru, lgru | ||
359 | 1066 | } | ||
360 | 1067 | msru0, lgru0 := addUnits(0) | ||
361 | 1068 | msru1, lgru1 := addUnits(1) | ||
362 | 1069 | |||
363 | 1070 | // ---------- Single role active ---------- | ||
364 | 1071 | |||
365 | 1072 | // Start watching the relation from the perspective of the first unit, and | ||
366 | 1073 | // check the initial event. | ||
367 | 1074 | msw0 := msru0.Watch() | ||
368 | 1075 | defer testing.AssertStop(c, msw0) | ||
369 | 1076 | s.assertChange(c, msw0, nil, nil) | ||
370 | 1077 | s.assertNoChange(c, msw0) | ||
371 | 1078 | |||
372 | 1079 | // Join the unit to the relation, change its settings, and check that | ||
373 | 1080 | // nothing apparently happens. | ||
374 | 1081 | err = msru0.EnterScope(nil) | ||
375 | 1082 | c.Assert(err, gc.IsNil) | ||
376 | 1083 | mss0 := changeSettings(c, msru0) | ||
377 | 1084 | s.assertNoChange(c, msw0) | ||
378 | 1085 | |||
379 | 1086 | // Watch the relation from the perspective of the second provider, and | ||
380 | 1087 | // check initial event. | ||
381 | 1088 | msw1 := msru1.Watch() | ||
382 | 1089 | defer testing.AssertStop(c, msw1) | ||
383 | 1090 | s.assertChange(c, msw1, nil, nil) | ||
384 | 1091 | s.assertNoChange(c, msw1) | ||
385 | 1092 | |||
386 | 1093 | // Join the second provider unit to the relation, and check that neither | ||
387 | 1094 | // watching unit observes any change. | ||
388 | 1095 | err = msru1.EnterScope(nil) | ||
389 | 1096 | c.Assert(err, gc.IsNil) | ||
390 | 1097 | s.assertNoChange(c, msw1) | ||
391 | 1098 | s.assertNoChange(c, msw0) | ||
392 | 1099 | |||
393 | 1100 | // Change the unit's settings, and check that nothing apparently happens. | ||
394 | 1101 | mss1 := changeSettings(c, msru1) | ||
395 | 1102 | s.assertNoChange(c, msw1) | ||
396 | 1103 | s.assertNoChange(c, msw0) | ||
397 | 1104 | |||
398 | 1105 | // ---------- Two roles active ---------- | ||
399 | 1106 | |||
400 | 1107 | // Start a watch from the first requirer unit's perspective, and check it | ||
401 | 1108 | // only sees the first provider (with which it shares a container). | ||
402 | 1109 | lgw0 := lgru0.Watch() | ||
403 | 1110 | defer testing.AssertStop(c, lgw0) | ||
404 | 1111 | expectChanged := map[string]map[string]interface{}{ | ||
405 | 1112 | "mysql/0": mss0.Map(), | ||
406 | 1113 | } | ||
407 | 1114 | s.assertChange(c, lgw0, expectChanged, nil) | ||
408 | 1115 | s.assertNoChange(c, lgw0) | ||
409 | 1116 | |||
410 | 1117 | // Join the first requirer unit, and check that only the first provider | ||
411 | 1118 | // observes the change. | ||
412 | 1119 | err = lgru0.EnterScope(nil) | ||
413 | 1120 | c.Assert(err, gc.IsNil) | ||
414 | 1121 | lgs0, err := lgru0.Settings() | ||
415 | 1122 | c.Assert(err, gc.IsNil) | ||
416 | 1123 | expectChanged = map[string]map[string]interface{}{ | ||
417 | 1124 | "logging/0": lgs0.Map(), | ||
418 | 1125 | } | ||
419 | 1126 | s.assertChange(c, msw0, expectChanged, nil) | ||
420 | 1127 | s.assertNoChange(c, msw0) | ||
421 | 1128 | s.assertNoChange(c, msw1) | ||
422 | 1129 | s.assertNoChange(c, lgw0) | ||
423 | 1130 | |||
424 | 1131 | // Watch from the second requirer's perspective, and check it only sees the | ||
425 | 1132 | // second provider. | ||
426 | 1133 | lgw1 := lgru1.Watch() | ||
427 | 1134 | defer testing.AssertStop(c, lgw1) | ||
428 | 1135 | expectChanged = map[string]map[string]interface{}{ | ||
429 | 1136 | "mysql/1": mss1.Map(), | ||
430 | 1137 | } | ||
431 | 1138 | s.assertChange(c, lgw1, expectChanged, nil) | ||
432 | 1139 | s.assertNoChange(c, lgw1) | ||
433 | 1140 | |||
434 | 1141 | // Join the second requirer, and check that the first provider observes it... | ||
435 | 1142 | err = lgru1.EnterScope(nil) | ||
436 | 1143 | c.Assert(err, gc.IsNil) | ||
437 | 1144 | lgs1, err := lgru1.Settings() | ||
438 | 1145 | c.Assert(err, gc.IsNil) | ||
439 | 1146 | expectChanged = map[string]map[string]interface{}{ | ||
440 | 1147 | "logging/1": lgs1.Map(), | ||
441 | 1148 | } | ||
442 | 1149 | s.assertChange(c, msw1, expectChanged, nil) | ||
443 | 1150 | s.assertNoChange(c, msw1) | ||
444 | 1151 | |||
445 | 1152 | // ...and that nothing else sees anything. | ||
446 | 1153 | s.assertNoChange(c, msw0) | ||
447 | 1154 | s.assertNoChange(c, lgw0) | ||
448 | 1155 | s.assertNoChange(c, lgw1) | ||
449 | 1156 | |||
450 | 1157 | // Change the second provider's settings and check that the second | ||
451 | 1158 | // requirer notices... | ||
452 | 1159 | mss1 = changeSettings(c, msru1) | ||
453 | 1160 | expectChanged = map[string]map[string]interface{}{ | ||
454 | 1161 | "mysql/1": mss1.Map(), | ||
455 | 1162 | } | ||
456 | 1163 | s.assertChange(c, lgw1, expectChanged, nil) | ||
457 | 1164 | s.assertNoChange(c, lgw1) | ||
458 | 1165 | |||
459 | 1166 | // ...but that nothing else does. | ||
460 | 1167 | s.assertNoChange(c, msw0) | ||
461 | 1168 | s.assertNoChange(c, msw1) | ||
462 | 1169 | s.assertNoChange(c, msw0) | ||
463 | 1170 | |||
464 | 1171 | // Finally, depart the first provider, and check that only the first | ||
465 | 1172 | // requirer observes any change. | ||
466 | 1173 | err = msru0.LeaveScope() | ||
467 | 1174 | c.Assert(err, gc.IsNil) | ||
468 | 1175 | expectDeparted := []string{"mysql/0"} | ||
469 | 1176 | s.assertChange(c, lgw0, nil, expectDeparted) | ||
470 | 1177 | s.assertNoChange(c, lgw0) | ||
471 | 1178 | s.assertNoChange(c, lgw1) | ||
472 | 1179 | s.assertNoChange(c, msw0) | ||
473 | 1180 | s.assertNoChange(c, msw1) | ||
474 | 1181 | |||
475 | 1182 | // Again, I think we're done, and can be comfortable that the appropriate | ||
476 | 1183 | // connections are in place. | ||
477 | 1184 | } | ||
478 | 1185 | |||
479 | 1186 | func changeSettings(c *gc.C, ru *state.RelationUnit) *state.Settings { | ||
480 | 1187 | node, err := ru.Settings() | ||
481 | 1188 | c.Assert(err, gc.IsNil) | ||
482 | 1189 | value, _ := node.Get("value") | ||
483 | 1190 | v, _ := value.(int) | ||
484 | 1191 | node.Set("value", v+1) | ||
485 | 1192 | _, err = node.Write() | ||
486 | 1193 | c.Assert(err, gc.IsNil) | ||
487 | 1194 | return node | ||
488 | 1195 | } | ||
489 | 1196 | |||
490 | 1197 | func (s *WatchScopeSuite) assertChange( | ||
491 | 1198 | c *gc.C, w *state.RelationUnitsWatcher, | ||
492 | 1199 | changed map[string]map[string]interface{}, | ||
493 | 1200 | departed []string, | ||
494 | 1201 | ) { | ||
495 | 1202 | s.State.StartSync() | ||
496 | 1203 | select { | ||
497 | 1204 | case ch, ok := <-w.Changes(): | ||
498 | 1205 | if !ok { | ||
499 | 1206 | c.Fatalf("channel closed; watcher error: %#v", w.Err()) | ||
500 | 1207 | } | ||
501 | 1208 | c.Assert(ch.Changed, gc.HasLen, len(changed)) | ||
502 | 1209 | for name, m := range changed { | ||
503 | 1210 | c.Assert(ch.Changed[name].Settings, gc.DeepEquals, m) | ||
504 | 1211 | } | ||
505 | 1212 | c.Assert(departed, jc.SameContents, ch.Departed) | ||
506 | 1213 | case <-time.After(5 * time.Second): | ||
507 | 1214 | c.Fatalf("expected changed %#v, departed %#v; got nothing", changed, departed) | ||
508 | 1215 | } | ||
509 | 1216 | } | ||
510 | 1217 | |||
511 | 1218 | func (s *WatchScopeSuite) assertNoChange(c *gc.C, w *state.RelationUnitsWatcher) { | ||
512 | 1219 | s.State.StartSync() | ||
513 | 1220 | select { | ||
514 | 1221 | case ch := <-w.Changes(): | ||
515 | 1222 | c.Fatalf("got %#v, expected nothing", ch) | ||
516 | 1223 | case <-time.After(50 * time.Millisecond): | ||
517 | 1224 | } | ||
518 | 1225 | } |
Reviewers: mp+183189_ code.launchpad. net,
Message:
Please take a look.
Description: dropped tests
state: reinstate accidentally-
Aside from removal of the tests for the Joined field (which is no longer
sent,
because it's redundant (preexisting change)), this was a mechanical
rename
job from the original. It's reassuring to observe that behaviour had not
otherwise changed detectably in the interim.
https:/ /code.launchpad .net/~fwereade/ juju-core/ reinstate- relation- watch-tests/ +merge/ 183189
(do not edit description out of merge proposal)
Please review this at https:/ /codereview. appspot. com/13401045/
Affected files: nit_test. go
A [revision details]
M state/relationu