Merge lp:~pedronis/ubuntu-push/be-nice into lp:ubuntu-push
- be-nice
- Merge into trunk
Proposed by
Samuele Pedroni
Status: | Superseded |
---|---|
Proposed branch: | lp:~pedronis/ubuntu-push/be-nice |
Merge into: | lp:ubuntu-push |
Diff against target: |
1379 lines (+633/-144) 12 files modified
.bzrignore (+2/-0) Makefile (+18/-6) README (+12/-3) client/client.go (+31/-5) client/client_test.go (+93/-44) client/gethosts/gethost_test.go (+5/-7) client/session/session.go (+156/-31) client/session/session_test.go (+307/-42) debian/config.json (+3/-0) sampleconfigs/dev.json (+2/-2) server/acceptance/suites/helpers.go (+2/-2) server/acceptance/suites/suite.go (+2/-2) |
To merge this branch: | bzr merge lp:~pedronis/ubuntu-push/be-nice |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Ubuntu Push Hackers | Pending | ||
Review via email: mp+213511@code.launchpad.net |
Commit message
update README, Makefile with more targets, move sample dev config to sampleconfigs
Description of the change
update README, Makefile with more targets, move sample dev config to sampleconfigs
To post a comment you must log in.
lp:~pedronis/ubuntu-push/be-nice
updated
- 101. By Samuele Pedroni
-
newline
- 102. By Samuele Pedroni
-
api port => 8080
- 103. By Samuele Pedroni
-
final tweaks
Unmerged revisions
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file '.bzrignore' | |||
2 | --- .bzrignore 2014-02-07 19:36:38 +0000 | |||
3 | +++ .bzrignore 2014-03-31 16:43:44 +0000 | |||
4 | @@ -11,3 +11,5 @@ | |||
5 | 11 | debian/*.ex | 11 | debian/*.ex |
6 | 12 | debian/*.EX | 12 | debian/*.EX |
7 | 13 | debian/*.substvars | 13 | debian/*.substvars |
8 | 14 | ubuntu-push-client | ||
9 | 15 | push-server-dev | ||
10 | 14 | 16 | ||
11 | === modified file 'Makefile' | |||
12 | --- Makefile 2014-03-12 13:23:26 +0000 | |||
13 | +++ Makefile 2014-03-31 16:43:44 +0000 | |||
14 | @@ -12,6 +12,8 @@ | |||
15 | 12 | GODEPS += launchpad.net/go-xdg/v0 | 12 | GODEPS += launchpad.net/go-xdg/v0 |
16 | 13 | GODEPS += code.google.com/p/gosqlite/sqlite3 | 13 | GODEPS += code.google.com/p/gosqlite/sqlite3 |
17 | 14 | 14 | ||
18 | 15 | TOTEST = $(shell env GOPATH=$(GOPATH) go list $(PROJECT)/...|grep -v acceptance{|grep -v http13client ) | ||
19 | 16 | |||
20 | 15 | bootstrap: | 17 | bootstrap: |
21 | 16 | mkdir -p $(GOPATH)/bin | 18 | mkdir -p $(GOPATH)/bin |
22 | 17 | mkdir -p $(GOPATH)/pkg | 19 | mkdir -p $(GOPATH)/pkg |
23 | @@ -21,17 +23,26 @@ | |||
24 | 21 | go install $(GODEPS) | 23 | go install $(GODEPS) |
25 | 22 | 24 | ||
26 | 23 | check: | 25 | check: |
28 | 24 | go test $(TESTFLAGS) $(PROJECT)/... | 26 | go test $(TESTFLAGS) $(TOTEST) |
29 | 25 | 27 | ||
30 | 26 | check-race: | 28 | check-race: |
32 | 27 | go test $(TESTFLAGS) -race $(PROJECT)/... | 29 | go test $(TESTFLAGS) -race $(TOTEST) |
33 | 30 | |||
34 | 31 | acceptance: | ||
35 | 32 | cd server/acceptance; ./acceptance.sh | ||
36 | 33 | |||
37 | 34 | build-client: | ||
38 | 35 | go build ubuntu-push-client.go | ||
39 | 36 | |||
40 | 37 | build-server-dev: | ||
41 | 38 | go build -o push-server-dev launchpad.net/ubuntu-push/server/dev | ||
42 | 28 | 39 | ||
43 | 29 | coverage-summary: | 40 | coverage-summary: |
45 | 30 | go test $(TESTFLAGS) -a -cover $(PROJECT)/... | 41 | go test $(TESTFLAGS) -a -cover $(TOTEST) |
46 | 31 | 42 | ||
47 | 32 | coverage-html: | 43 | coverage-html: |
48 | 33 | mkdir -p coverhtml | 44 | mkdir -p coverhtml |
50 | 34 | for pkg in $$(go list $(PROJECT)/...|grep -v acceptance ); do \ | 45 | for pkg in $(TOTEST); do \ |
51 | 35 | relname="$${pkg#$(PROJECT)/}" ; \ | 46 | relname="$${pkg#$(PROJECT)/}" ; \ |
52 | 36 | mkdir -p coverhtml/$$(dirname $${relname}) ; \ | 47 | mkdir -p coverhtml/$$(dirname $${relname}) ; \ |
53 | 37 | go test $(TESTFLAGS) -a -coverprofile=coverhtml/$${relname}.out $$pkg ; \ | 48 | go test $(TESTFLAGS) -a -coverprofile=coverhtml/$${relname}.out $$pkg ; \ |
54 | @@ -52,5 +63,6 @@ | |||
55 | 52 | # requires graphviz installed | 63 | # requires graphviz installed |
56 | 53 | dot -Tsvg $< > $@ | 64 | dot -Tsvg $< > $@ |
57 | 54 | 65 | ||
60 | 55 | .PHONY: bootstrap check check-race format check-format coverage-summary \ | 66 | .PHONY: bootstrap check check-race format check-format \ |
61 | 56 | coverage-html protocol-diagrams | 67 | acceptance build-client bluild-server-dev \ |
62 | 68 | coverage-summary coverage-html protocol-diagrams | ||
63 | 57 | 69 | ||
64 | === modified file 'README' | |||
65 | --- README 2014-02-21 16:17:28 +0000 | |||
66 | +++ README 2014-03-31 16:43:44 +0000 | |||
67 | @@ -15,8 +15,7 @@ | |||
68 | 15 | make check | 15 | make check |
69 | 16 | 16 | ||
70 | 17 | To produce coverage reports you need Go 1.2 (default on Trusty) and | 17 | To produce coverage reports you need Go 1.2 (default on Trusty) and |
73 | 18 | the cover tool (the latter can be obtained atm with something like: | 18 | the cover tool (in the golang-go.tools package), |
72 | 19 | sudo GOPATH=<go-workspace> go get code.google.com/p/go.tools/cmd/cover ), | ||
74 | 20 | then run: | 19 | then run: |
75 | 21 | 20 | ||
76 | 22 | make coverage-summary | 21 | make coverage-summary |
77 | @@ -31,4 +30,14 @@ | |||
78 | 31 | 30 | ||
79 | 32 | To run the acceptance tests, change to the acceptance subdir and run: | 31 | To run the acceptance tests, change to the acceptance subdir and run: |
80 | 33 | 32 | ||
82 | 34 | ./acceptance.sh | 33 | make acceptance |
83 | 34 | |||
84 | 35 | There are build targets to build the client: | ||
85 | 36 | |||
86 | 37 | make build-client | ||
87 | 38 | |||
88 | 39 | building ubuntu-push-client, and the development server: | ||
89 | 40 | |||
90 | 41 | make build-server-dev | ||
91 | 42 | |||
92 | 43 | building push-server-dev. | ||
93 | 35 | \ No newline at end of file | 44 | \ No newline at end of file |
94 | 36 | 45 | ||
95 | === modified file 'client/client.go' | |||
96 | --- client/client.go 2014-03-26 16:26:36 +0000 | |||
97 | +++ client/client.go 2014-03-31 16:43:44 +0000 | |||
98 | @@ -20,9 +20,14 @@ | |||
99 | 20 | 20 | ||
100 | 21 | import ( | 21 | import ( |
101 | 22 | "encoding/pem" | 22 | "encoding/pem" |
102 | 23 | "errors" | ||
103 | 23 | "fmt" | 24 | "fmt" |
104 | 24 | "io/ioutil" | 25 | "io/ioutil" |
105 | 26 | "os" | ||
106 | 27 | "strings" | ||
107 | 28 | |||
108 | 25 | "launchpad.net/go-dbus/v1" | 29 | "launchpad.net/go-dbus/v1" |
109 | 30 | |||
110 | 26 | "launchpad.net/ubuntu-push/bus" | 31 | "launchpad.net/ubuntu-push/bus" |
111 | 27 | "launchpad.net/ubuntu-push/bus/connectivity" | 32 | "launchpad.net/ubuntu-push/bus/connectivity" |
112 | 28 | "launchpad.net/ubuntu-push/bus/networkmanager" | 33 | "launchpad.net/ubuntu-push/bus/networkmanager" |
113 | @@ -34,7 +39,6 @@ | |||
114 | 34 | "launchpad.net/ubuntu-push/logger" | 39 | "launchpad.net/ubuntu-push/logger" |
115 | 35 | "launchpad.net/ubuntu-push/util" | 40 | "launchpad.net/ubuntu-push/util" |
116 | 36 | "launchpad.net/ubuntu-push/whoopsie/identifier" | 41 | "launchpad.net/ubuntu-push/whoopsie/identifier" |
117 | 37 | "os" | ||
118 | 38 | ) | 42 | ) |
119 | 39 | 43 | ||
120 | 40 | // ClientConfig holds the client configuration | 44 | // ClientConfig holds the client configuration |
121 | @@ -42,8 +46,13 @@ | |||
122 | 42 | connectivity.ConnectivityConfig // q.v. | 46 | connectivity.ConnectivityConfig // q.v. |
123 | 43 | // A reasonably large timeout for receive/answer pairs | 47 | // A reasonably large timeout for receive/answer pairs |
124 | 44 | ExchangeTimeout config.ConfigTimeDuration `json:"exchange_timeout"` | 48 | ExchangeTimeout config.ConfigTimeDuration `json:"exchange_timeout"` |
127 | 45 | // The server to connect to | 49 | // A timeout to use when trying to connect to the server |
128 | 46 | Addr config.ConfigHostPort | 50 | ConnectTimeout config.ConfigTimeDuration `json:"connect_timeout"` |
129 | 51 | // The server to connect to or url to query for hosts to connect to | ||
130 | 52 | Addr string | ||
131 | 53 | // Host list management | ||
132 | 54 | HostsCachingExpiryTime config.ConfigTimeDuration `json:"hosts_cache_expiry"` // potentially refresh host list after | ||
133 | 55 | ExpectAllRepairedTime config.ConfigTimeDuration `json:"expect_all_repaired"` // worth retrying all servers after | ||
134 | 47 | // The PEM-encoded server certificate | 56 | // The PEM-encoded server certificate |
135 | 48 | CertPEMFile string `json:"cert_pem_file"` | 57 | CertPEMFile string `json:"cert_pem_file"` |
136 | 49 | // The logging level (one of "debug", "info", "error") | 58 | // The logging level (one of "debug", "info", "error") |
137 | @@ -89,6 +98,12 @@ | |||
138 | 89 | if err != nil { | 98 | if err != nil { |
139 | 90 | return fmt.Errorf("reading config: %v", err) | 99 | return fmt.Errorf("reading config: %v", err) |
140 | 91 | } | 100 | } |
141 | 101 | // ignore spaces | ||
142 | 102 | client.config.Addr = strings.Replace(client.config.Addr, " ", "", -1) | ||
143 | 103 | if client.config.Addr == "" { | ||
144 | 104 | return errors.New("no hosts specified") | ||
145 | 105 | } | ||
146 | 106 | |||
147 | 92 | // later, we'll be specifying more logging options in the config file | 107 | // later, we'll be specifying more logging options in the config file |
148 | 93 | client.log = logger.NewSimpleLogger(os.Stderr, client.config.LogLevel) | 108 | client.log = logger.NewSimpleLogger(os.Stderr, client.config.LogLevel) |
149 | 94 | 109 | ||
150 | @@ -116,6 +131,17 @@ | |||
151 | 116 | return nil | 131 | return nil |
152 | 117 | } | 132 | } |
153 | 118 | 133 | ||
154 | 134 | // deriveSessionConfig dervies the session configuration from the client configuration bits. | ||
155 | 135 | func (client *PushClient) deriveSessionConfig() session.ClientSessionConfig { | ||
156 | 136 | return session.ClientSessionConfig{ | ||
157 | 137 | ConnectTimeout: client.config.ConnectTimeout.TimeDuration(), | ||
158 | 138 | ExchangeTimeout: client.config.ExchangeTimeout.TimeDuration(), | ||
159 | 139 | HostsCachingExpiryTime: client.config.HostsCachingExpiryTime.TimeDuration(), | ||
160 | 140 | ExpectAllRepairedTime: client.config.ExpectAllRepairedTime.TimeDuration(), | ||
161 | 141 | PEM: client.pem, | ||
162 | 142 | } | ||
163 | 143 | } | ||
164 | 144 | |||
165 | 119 | // getDeviceId gets the whoopsie identifier for the device | 145 | // getDeviceId gets the whoopsie identifier for the device |
166 | 120 | func (client *PushClient) getDeviceId() error { | 146 | func (client *PushClient) getDeviceId() error { |
167 | 121 | err := client.idder.Generate() | 147 | err := client.idder.Generate() |
168 | @@ -143,8 +169,8 @@ | |||
169 | 143 | 169 | ||
170 | 144 | // initSession creates the session object | 170 | // initSession creates the session object |
171 | 145 | func (client *PushClient) initSession() error { | 171 | func (client *PushClient) initSession() error { |
174 | 146 | sess, err := session.NewSession(string(client.config.Addr), client.pem, | 172 | sess, err := session.NewSession(client.config.Addr, |
175 | 147 | client.config.ExchangeTimeout.Duration, client.deviceId, | 173 | client.deriveSessionConfig(), client.deviceId, |
176 | 148 | client.levelMapFactory, client.log) | 174 | client.levelMapFactory, client.log) |
177 | 149 | if err != nil { | 175 | if err != nil { |
178 | 150 | return err | 176 | return err |
179 | 151 | 177 | ||
180 | === modified file 'client/client_test.go' | |||
181 | --- client/client_test.go 2014-03-26 16:26:36 +0000 | |||
182 | +++ client/client_test.go 2014-03-31 16:43:44 +0000 | |||
183 | @@ -17,10 +17,19 @@ | |||
184 | 17 | package client | 17 | package client |
185 | 18 | 18 | ||
186 | 19 | import ( | 19 | import ( |
187 | 20 | "encoding/json" | ||
188 | 20 | "errors" | 21 | "errors" |
189 | 21 | "fmt" | 22 | "fmt" |
190 | 22 | "io/ioutil" | 23 | "io/ioutil" |
191 | 24 | "net/http" | ||
192 | 25 | "net/http/httptest" | ||
193 | 26 | "path/filepath" | ||
194 | 27 | "reflect" | ||
195 | 28 | "testing" | ||
196 | 29 | "time" | ||
197 | 30 | |||
198 | 23 | . "launchpad.net/gocheck" | 31 | . "launchpad.net/gocheck" |
199 | 32 | |||
200 | 24 | "launchpad.net/ubuntu-push/bus" | 33 | "launchpad.net/ubuntu-push/bus" |
201 | 25 | "launchpad.net/ubuntu-push/bus/networkmanager" | 34 | "launchpad.net/ubuntu-push/bus/networkmanager" |
202 | 26 | "launchpad.net/ubuntu-push/bus/notifications" | 35 | "launchpad.net/ubuntu-push/bus/notifications" |
203 | @@ -32,11 +41,6 @@ | |||
204 | 32 | "launchpad.net/ubuntu-push/util" | 41 | "launchpad.net/ubuntu-push/util" |
205 | 33 | "launchpad.net/ubuntu-push/whoopsie/identifier" | 42 | "launchpad.net/ubuntu-push/whoopsie/identifier" |
206 | 34 | idtesting "launchpad.net/ubuntu-push/whoopsie/identifier/testing" | 43 | idtesting "launchpad.net/ubuntu-push/whoopsie/identifier/testing" |
207 | 35 | "net/http" | ||
208 | 36 | "net/http/httptest" | ||
209 | 37 | "path/filepath" | ||
210 | 38 | "testing" | ||
211 | 39 | "time" | ||
212 | 40 | ) | 44 | ) |
213 | 41 | 45 | ||
214 | 42 | func TestClient(t *testing.T) { TestingT(t) } | 46 | func TestClient(t *testing.T) { TestingT(t) } |
215 | @@ -83,22 +87,37 @@ | |||
216 | 83 | cs.timeouts = nil | 87 | cs.timeouts = nil |
217 | 84 | } | 88 | } |
218 | 85 | 89 | ||
219 | 90 | func (cs *clientSuite) writeTestConfig(overrides map[string]interface{}) { | ||
220 | 91 | pem_file := helpers.SourceRelative("../server/acceptance/ssl/testing.cert") | ||
221 | 92 | cfgMap := map[string]interface{}{ | ||
222 | 93 | "connect_timeout": "7ms", | ||
223 | 94 | "exchange_timeout": "10ms", | ||
224 | 95 | "hosts_cache_expiry": "1h", | ||
225 | 96 | "expect_all_repaired": "30m", | ||
226 | 97 | "stabilizing_timeout": "0ms", | ||
227 | 98 | "connectivity_check_url": "", | ||
228 | 99 | "connectivity_check_md5": "", | ||
229 | 100 | "addr": ":0", | ||
230 | 101 | "cert_pem_file": pem_file, | ||
231 | 102 | "recheck_timeout": "3h", | ||
232 | 103 | "log_level": "debug", | ||
233 | 104 | } | ||
234 | 105 | for k, v := range overrides { | ||
235 | 106 | cfgMap[k] = v | ||
236 | 107 | } | ||
237 | 108 | cfgBlob, err := json.Marshal(cfgMap) | ||
238 | 109 | if err != nil { | ||
239 | 110 | panic(err) | ||
240 | 111 | } | ||
241 | 112 | ioutil.WriteFile(cs.configPath, cfgBlob, 0600) | ||
242 | 113 | } | ||
243 | 114 | |||
244 | 86 | func (cs *clientSuite) SetUpTest(c *C) { | 115 | func (cs *clientSuite) SetUpTest(c *C) { |
245 | 87 | cs.log = helpers.NewTestLogger(c, "debug") | 116 | cs.log = helpers.NewTestLogger(c, "debug") |
246 | 88 | dir := c.MkDir() | 117 | dir := c.MkDir() |
247 | 89 | cs.configPath = filepath.Join(dir, "config") | 118 | cs.configPath = filepath.Join(dir, "config") |
260 | 90 | cfg := fmt.Sprintf(` | 119 | |
261 | 91 | { | 120 | cs.writeTestConfig(nil) |
250 | 92 | "exchange_timeout": "10ms", | ||
251 | 93 | "stabilizing_timeout": "0ms", | ||
252 | 94 | "connectivity_check_url": "", | ||
253 | 95 | "connectivity_check_md5": "", | ||
254 | 96 | "addr": ":0", | ||
255 | 97 | "cert_pem_file": %#v, | ||
256 | 98 | "recheck_timeout": "3h", | ||
257 | 99 | "log_level": "debug" | ||
258 | 100 | }`, helpers.SourceRelative("../server/acceptance/config/testing.cert")) | ||
259 | 101 | ioutil.WriteFile(cs.configPath, []byte(cfg), 0600) | ||
262 | 102 | } | 121 | } |
263 | 103 | 122 | ||
264 | 104 | type sqlientSuite struct{ clientSuite } | 123 | type sqlientSuite struct{ clientSuite } |
265 | @@ -119,7 +138,7 @@ | |||
266 | 119 | err := cli.configure() | 138 | err := cli.configure() |
267 | 120 | c.Assert(err, IsNil) | 139 | c.Assert(err, IsNil) |
268 | 121 | c.Assert(cli.config, NotNil) | 140 | c.Assert(cli.config, NotNil) |
270 | 122 | c.Check(cli.config.ExchangeTimeout.Duration, Equals, time.Duration(10*time.Millisecond)) | 141 | c.Check(cli.config.ExchangeTimeout.TimeDuration(), Equals, time.Duration(10*time.Millisecond)) |
271 | 123 | } | 142 | } |
272 | 124 | 143 | ||
273 | 125 | func (cs *clientSuite) TestConfigureSetsUpLog(c *C) { | 144 | func (cs *clientSuite) TestConfigureSetsUpLog(c *C) { |
274 | @@ -179,41 +198,70 @@ | |||
275 | 179 | } | 198 | } |
276 | 180 | 199 | ||
277 | 181 | func (cs *clientSuite) TestConfigureBailsOnBadPEMFilename(c *C) { | 200 | func (cs *clientSuite) TestConfigureBailsOnBadPEMFilename(c *C) { |
290 | 182 | ioutil.WriteFile(cs.configPath, []byte(` | 201 | cs.writeTestConfig(map[string]interface{}{ |
291 | 183 | { | 202 | "cert_pem_file": "/a/b/c", |
292 | 184 | "exchange_timeout": "10ms", | 203 | }) |
281 | 185 | "stabilizing_timeout": "0ms", | ||
282 | 186 | "connectivity_check_url": "", | ||
283 | 187 | "connectivity_check_md5": "", | ||
284 | 188 | "addr": ":0", | ||
285 | 189 | "cert_pem_file": "/a/b/c", | ||
286 | 190 | "log_level": "debug", | ||
287 | 191 | "recheck_timeout": "3h" | ||
288 | 192 | }`), 0600) | ||
289 | 193 | |||
293 | 194 | cli := NewPushClient(cs.configPath, cs.leveldbPath) | 204 | cli := NewPushClient(cs.configPath, cs.leveldbPath) |
294 | 195 | err := cli.configure() | 205 | err := cli.configure() |
295 | 196 | c.Assert(err, ErrorMatches, "reading PEM file: .*") | 206 | c.Assert(err, ErrorMatches, "reading PEM file: .*") |
296 | 197 | } | 207 | } |
297 | 198 | 208 | ||
298 | 199 | func (cs *clientSuite) TestConfigureBailsOnBadPEM(c *C) { | 209 | func (cs *clientSuite) TestConfigureBailsOnBadPEM(c *C) { |
311 | 200 | ioutil.WriteFile(cs.configPath, []byte(` | 210 | cs.writeTestConfig(map[string]interface{}{ |
312 | 201 | { | 211 | "cert_pem_file": "/etc/passwd", |
313 | 202 | "exchange_timeout": "10ms", | 212 | }) |
302 | 203 | "stabilizing_timeout": "0ms", | ||
303 | 204 | "connectivity_check_url": "", | ||
304 | 205 | "connectivity_check_md5": "", | ||
305 | 206 | "addr": ":0", | ||
306 | 207 | "cert_pem_file": "/etc/passwd", | ||
307 | 208 | "log_level": "debug", | ||
308 | 209 | "recheck_timeout": "3h" | ||
309 | 210 | }`), 0600) | ||
310 | 211 | |||
314 | 212 | cli := NewPushClient(cs.configPath, cs.leveldbPath) | 213 | cli := NewPushClient(cs.configPath, cs.leveldbPath) |
315 | 213 | err := cli.configure() | 214 | err := cli.configure() |
316 | 214 | c.Assert(err, ErrorMatches, "no PEM found.*") | 215 | c.Assert(err, ErrorMatches, "no PEM found.*") |
317 | 215 | } | 216 | } |
318 | 216 | 217 | ||
319 | 218 | func (cs *clientSuite) TestConfigureBailsOnNoHosts(c *C) { | ||
320 | 219 | cs.writeTestConfig(map[string]interface{}{ | ||
321 | 220 | "addr": " ", | ||
322 | 221 | }) | ||
323 | 222 | cli := NewPushClient(cs.configPath, cs.leveldbPath) | ||
324 | 223 | err := cli.configure() | ||
325 | 224 | c.Assert(err, ErrorMatches, "no hosts specified") | ||
326 | 225 | } | ||
327 | 226 | |||
328 | 227 | func (cs *clientSuite) TestConfigureRemovesBlanksInAddr(c *C) { | ||
329 | 228 | cs.writeTestConfig(map[string]interface{}{ | ||
330 | 229 | "addr": " foo: 443", | ||
331 | 230 | }) | ||
332 | 231 | cli := NewPushClient(cs.configPath, cs.leveldbPath) | ||
333 | 232 | err := cli.configure() | ||
334 | 233 | c.Assert(err, IsNil) | ||
335 | 234 | c.Check(cli.config.Addr, Equals, "foo:443") | ||
336 | 235 | } | ||
337 | 236 | |||
338 | 237 | /***************************************************************** | ||
339 | 238 | deriveSessionConfig tests | ||
340 | 239 | ******************************************************************/ | ||
341 | 240 | |||
342 | 241 | func (cs *clientSuite) TestDeriveSessionConfig(c *C) { | ||
343 | 242 | cli := NewPushClient(cs.configPath, cs.leveldbPath) | ||
344 | 243 | err := cli.configure() | ||
345 | 244 | c.Assert(err, IsNil) | ||
346 | 245 | expected := session.ClientSessionConfig{ | ||
347 | 246 | ConnectTimeout: 7 * time.Millisecond, | ||
348 | 247 | ExchangeTimeout: 10 * time.Millisecond, | ||
349 | 248 | HostsCachingExpiryTime: 1 * time.Hour, | ||
350 | 249 | ExpectAllRepairedTime: 30 * time.Minute, | ||
351 | 250 | PEM: cli.pem, | ||
352 | 251 | } | ||
353 | 252 | // sanity check that we are looking at all fields | ||
354 | 253 | vExpected := reflect.ValueOf(expected) | ||
355 | 254 | nf := vExpected.NumField() | ||
356 | 255 | for i := 0; i < nf; i++ { | ||
357 | 256 | fv := vExpected.Field(i) | ||
358 | 257 | // field isn't empty/zero | ||
359 | 258 | c.Assert(fv.Interface(), Not(DeepEquals), reflect.Zero(fv.Type()).Interface(), Commentf("forgot about: %s", vExpected.Type().Field(i).Name)) | ||
360 | 259 | } | ||
361 | 260 | // finally compare | ||
362 | 261 | conf := cli.deriveSessionConfig() | ||
363 | 262 | c.Check(conf, DeepEquals, expected) | ||
364 | 263 | } | ||
365 | 264 | |||
366 | 217 | /***************************************************************** | 265 | /***************************************************************** |
367 | 218 | getDeviceId tests | 266 | getDeviceId tests |
368 | 219 | ******************************************************************/ | 267 | ******************************************************************/ |
369 | @@ -308,6 +356,7 @@ | |||
370 | 308 | cli := NewPushClient(cs.configPath, cs.leveldbPath) | 356 | cli := NewPushClient(cs.configPath, cs.leveldbPath) |
371 | 309 | cli.log = cs.log | 357 | cli.log = cs.log |
372 | 310 | c.Assert(cli.initSession(), IsNil) | 358 | c.Assert(cli.initSession(), IsNil) |
373 | 359 | cs.log.ResetCapture() | ||
374 | 311 | cli.hasConnectivity = true | 360 | cli.hasConnectivity = true |
375 | 312 | cli.handleErr(errors.New("bananas")) | 361 | cli.handleErr(errors.New("bananas")) |
376 | 313 | c.Check(cs.log.Captured(), Matches, ".*session exited.*bananas\n") | 362 | c.Check(cs.log.Captured(), Matches, ".*session exited.*bananas\n") |
377 | @@ -363,7 +412,7 @@ | |||
378 | 363 | func (cs *clientSuite) TestHandleConnStateC2D(c *C) { | 412 | func (cs *clientSuite) TestHandleConnStateC2D(c *C) { |
379 | 364 | cli := NewPushClient(cs.configPath, cs.leveldbPath) | 413 | cli := NewPushClient(cs.configPath, cs.leveldbPath) |
380 | 365 | cli.log = cs.log | 414 | cli.log = cs.log |
382 | 366 | cli.session, _ = session.NewSession(string(cli.config.Addr), cli.pem, cli.config.ExchangeTimeout.Duration, cli.deviceId, levelmap.NewLevelMap, cs.log) | 415 | cli.session, _ = session.NewSession(cli.config.Addr, cli.deriveSessionConfig(), cli.deviceId, levelmap.NewLevelMap, cs.log) |
383 | 367 | cli.session.Dial() | 416 | cli.session.Dial() |
384 | 368 | cli.hasConnectivity = true | 417 | cli.hasConnectivity = true |
385 | 369 | 418 | ||
386 | @@ -376,7 +425,7 @@ | |||
387 | 376 | func (cs *clientSuite) TestHandleConnStateC2DPending(c *C) { | 425 | func (cs *clientSuite) TestHandleConnStateC2DPending(c *C) { |
388 | 377 | cli := NewPushClient(cs.configPath, cs.leveldbPath) | 426 | cli := NewPushClient(cs.configPath, cs.leveldbPath) |
389 | 378 | cli.log = cs.log | 427 | cli.log = cs.log |
391 | 379 | cli.session, _ = session.NewSession(string(cli.config.Addr), cli.pem, cli.config.ExchangeTimeout.Duration, cli.deviceId, levelmap.NewLevelMap, cs.log) | 428 | cli.session, _ = session.NewSession(cli.config.Addr, cli.deriveSessionConfig(), cli.deviceId, levelmap.NewLevelMap, cs.log) |
392 | 380 | cli.hasConnectivity = true | 429 | cli.hasConnectivity = true |
393 | 381 | 430 | ||
394 | 382 | cli.handleConnState(false) | 431 | cli.handleConnState(false) |
395 | 383 | 432 | ||
396 | === modified file 'client/gethosts/gethost_test.go' | |||
397 | --- client/gethosts/gethost_test.go 2014-03-24 15:32:29 +0000 | |||
398 | +++ client/gethosts/gethost_test.go 2014-03-31 16:43:44 +0000 | |||
399 | @@ -61,18 +61,16 @@ | |||
400 | 61 | } | 61 | } |
401 | 62 | 62 | ||
402 | 63 | func (s *getHostsSuite) TestGetTimeout(c *C) { | 63 | func (s *getHostsSuite) TestGetTimeout(c *C) { |
404 | 64 | finish := make(chan bool, 1) | 64 | started := make(chan bool, 1) |
405 | 65 | ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | 65 | ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
407 | 66 | <-finish | 66 | started <- true |
408 | 67 | time.Sleep(700 * time.Millisecond) | ||
409 | 67 | })) | 68 | })) |
410 | 68 | defer func() { | 69 | defer func() { |
412 | 69 | time.Sleep(100 * time.Millisecond) // work around -race issue | 70 | <-started |
413 | 70 | ts.Close() | 71 | ts.Close() |
414 | 71 | }() | 72 | }() |
419 | 72 | defer func() { | 73 | gh := New("foobar", ts.URL, 500*time.Millisecond) |
416 | 73 | finish <- true | ||
417 | 74 | }() | ||
418 | 75 | gh := New("foobar", ts.URL, 1*time.Second) | ||
420 | 76 | _, err := gh.Get() | 74 | _, err := gh.Get() |
421 | 77 | c.Check(err, ErrorMatches, ".*closed.*") | 75 | c.Check(err, ErrorMatches, ".*closed.*") |
422 | 78 | } | 76 | } |
423 | 79 | 77 | ||
424 | === modified file 'client/session/session.go' | |||
425 | --- client/session/session.go 2014-03-26 16:26:36 +0000 | |||
426 | +++ client/session/session.go 2014-03-31 16:43:44 +0000 | |||
427 | @@ -23,14 +23,18 @@ | |||
428 | 23 | "crypto/x509" | 23 | "crypto/x509" |
429 | 24 | "errors" | 24 | "errors" |
430 | 25 | "fmt" | 25 | "fmt" |
431 | 26 | "math/rand" | ||
432 | 27 | "net" | ||
433 | 28 | "strings" | ||
434 | 29 | "sync" | ||
435 | 30 | "sync/atomic" | ||
436 | 31 | "time" | ||
437 | 32 | |||
438 | 33 | "launchpad.net/ubuntu-push/client/gethosts" | ||
439 | 26 | "launchpad.net/ubuntu-push/client/session/levelmap" | 34 | "launchpad.net/ubuntu-push/client/session/levelmap" |
440 | 27 | "launchpad.net/ubuntu-push/logger" | 35 | "launchpad.net/ubuntu-push/logger" |
441 | 28 | "launchpad.net/ubuntu-push/protocol" | 36 | "launchpad.net/ubuntu-push/protocol" |
442 | 29 | "launchpad.net/ubuntu-push/util" | 37 | "launchpad.net/ubuntu-push/util" |
443 | 30 | "math/rand" | ||
444 | 31 | "net" | ||
445 | 32 | "sync/atomic" | ||
446 | 33 | "time" | ||
447 | 34 | ) | 38 | ) |
448 | 35 | 39 | ||
449 | 36 | var wireVersionBytes = []byte{protocol.ProtocolWireVersion} | 40 | var wireVersionBytes = []byte{protocol.ProtocolWireVersion} |
450 | @@ -45,6 +49,15 @@ | |||
451 | 45 | protocol.NotificationsMsg | 49 | protocol.NotificationsMsg |
452 | 46 | } | 50 | } |
453 | 47 | 51 | ||
454 | 52 | // parseServerAddrSpec recognizes whether spec is a HTTP URL to get | ||
455 | 53 | // hosts from or a |-separated list of host:port pairs. | ||
456 | 54 | func parseServerAddrSpec(spec string) (hostsEndpoint string, fallbackHosts []string) { | ||
457 | 55 | if strings.HasPrefix(spec, "http") { | ||
458 | 56 | return spec, nil | ||
459 | 57 | } | ||
460 | 58 | return "", strings.Split(spec, "|") | ||
461 | 59 | } | ||
462 | 60 | |||
463 | 48 | // ClientSessionState is a way to broadly track the progress of the session | 61 | // ClientSessionState is a way to broadly track the progress of the session |
464 | 49 | type ClientSessionState uint32 | 62 | type ClientSessionState uint32 |
465 | 50 | 63 | ||
466 | @@ -56,15 +69,38 @@ | |||
467 | 56 | Running | 69 | Running |
468 | 57 | ) | 70 | ) |
469 | 58 | 71 | ||
471 | 59 | // ClienSession holds a client<->server session and its configuration. | 72 | type hostGetter interface { |
472 | 73 | Get() ([]string, error) | ||
473 | 74 | } | ||
474 | 75 | |||
475 | 76 | // ClientSessionConfig groups the client session configuration. | ||
476 | 77 | type ClientSessionConfig struct { | ||
477 | 78 | ConnectTimeout time.Duration | ||
478 | 79 | ExchangeTimeout time.Duration | ||
479 | 80 | HostsCachingExpiryTime time.Duration | ||
480 | 81 | ExpectAllRepairedTime time.Duration | ||
481 | 82 | PEM []byte | ||
482 | 83 | } | ||
483 | 84 | |||
484 | 85 | // ClientSession holds a client<->server session and its configuration. | ||
485 | 60 | type ClientSession struct { | 86 | type ClientSession struct { |
486 | 61 | // configuration | 87 | // configuration |
492 | 62 | DeviceId string | 88 | DeviceId string |
493 | 63 | ServerAddr string | 89 | ClientSessionConfig |
494 | 64 | ExchangeTimeout time.Duration | 90 | Levels levelmap.LevelMap |
495 | 65 | Levels levelmap.LevelMap | 91 | Protocolator func(net.Conn) protocol.Protocol |
496 | 66 | Protocolator func(net.Conn) protocol.Protocol | 92 | // hosts |
497 | 93 | getHost hostGetter | ||
498 | 94 | fallbackHosts []string | ||
499 | 95 | deliveryHostsTimestamp time.Time | ||
500 | 96 | deliveryHosts []string | ||
501 | 97 | lastAttemptTimestamp time.Time | ||
502 | 98 | leftToTry int | ||
503 | 99 | tryHost int | ||
504 | 100 | // hook for testing | ||
505 | 101 | timeSince func(time.Time) time.Duration | ||
506 | 67 | // connection | 102 | // connection |
507 | 103 | connLock sync.RWMutex | ||
508 | 68 | Connection net.Conn | 104 | Connection net.Conn |
509 | 69 | Log logger.Logger | 105 | Log logger.Logger |
510 | 70 | TLS *tls.Config | 106 | TLS *tls.Config |
511 | @@ -77,7 +113,7 @@ | |||
512 | 77 | MsgCh chan *Notification | 113 | MsgCh chan *Notification |
513 | 78 | } | 114 | } |
514 | 79 | 115 | ||
516 | 80 | func NewSession(serverAddr string, pem []byte, exchangeTimeout time.Duration, | 116 | func NewSession(serverAddrSpec string, conf ClientSessionConfig, |
517 | 81 | deviceId string, levelmapFactory func() (levelmap.LevelMap, error), | 117 | deviceId string, levelmapFactory func() (levelmap.LevelMap, error), |
518 | 82 | log logger.Logger) (*ClientSession, error) { | 118 | log logger.Logger) (*ClientSession, error) { |
519 | 83 | state := uint32(Disconnected) | 119 | state := uint32(Disconnected) |
520 | @@ -85,19 +121,27 @@ | |||
521 | 85 | if err != nil { | 121 | if err != nil { |
522 | 86 | return nil, err | 122 | return nil, err |
523 | 87 | } | 123 | } |
524 | 124 | var getHost hostGetter | ||
525 | 125 | log.Infof("using addr: %v", serverAddrSpec) | ||
526 | 126 | hostsEndpoint, fallbackHosts := parseServerAddrSpec(serverAddrSpec) | ||
527 | 127 | if hostsEndpoint != "" { | ||
528 | 128 | getHost = gethosts.New(deviceId, hostsEndpoint, conf.ExchangeTimeout) | ||
529 | 129 | } | ||
530 | 88 | sess := &ClientSession{ | 130 | sess := &ClientSession{ |
539 | 89 | ExchangeTimeout: exchangeTimeout, | 131 | ClientSessionConfig: conf, |
540 | 90 | ServerAddr: serverAddr, | 132 | getHost: getHost, |
541 | 91 | DeviceId: deviceId, | 133 | fallbackHosts: fallbackHosts, |
542 | 92 | Log: log, | 134 | DeviceId: deviceId, |
543 | 93 | Protocolator: protocol.NewProtocol0, | 135 | Log: log, |
544 | 94 | Levels: levels, | 136 | Protocolator: protocol.NewProtocol0, |
545 | 95 | TLS: &tls.Config{InsecureSkipVerify: true}, // XXX | 137 | Levels: levels, |
546 | 96 | stateP: &state, | 138 | TLS: &tls.Config{InsecureSkipVerify: true}, // XXX |
547 | 139 | stateP: &state, | ||
548 | 140 | timeSince: time.Since, | ||
549 | 97 | } | 141 | } |
551 | 98 | if pem != nil { | 142 | if sess.PEM != nil { |
552 | 99 | cp := x509.NewCertPool() | 143 | cp := x509.NewCertPool() |
554 | 100 | ok := cp.AppendCertsFromPEM(pem) | 144 | ok := cp.AppendCertsFromPEM(sess.PEM) |
555 | 101 | if !ok { | 145 | if !ok { |
556 | 102 | return nil, errors.New("could not parse certificate") | 146 | return nil, errors.New("could not parse certificate") |
557 | 103 | } | 147 | } |
558 | @@ -114,15 +158,90 @@ | |||
559 | 114 | atomic.StoreUint32(sess.stateP, uint32(state)) | 158 | atomic.StoreUint32(sess.stateP, uint32(state)) |
560 | 115 | } | 159 | } |
561 | 116 | 160 | ||
562 | 161 | func (sess *ClientSession) setConnection(conn net.Conn) { | ||
563 | 162 | sess.connLock.Lock() | ||
564 | 163 | defer sess.connLock.Unlock() | ||
565 | 164 | sess.Connection = conn | ||
566 | 165 | } | ||
567 | 166 | |||
568 | 167 | func (sess *ClientSession) getConnection() net.Conn { | ||
569 | 168 | sess.connLock.RLock() | ||
570 | 169 | defer sess.connLock.RUnlock() | ||
571 | 170 | return sess.Connection | ||
572 | 171 | } | ||
573 | 172 | |||
574 | 173 | // getHosts sets deliveryHosts possibly querying a remote endpoint | ||
575 | 174 | func (sess *ClientSession) getHosts() error { | ||
576 | 175 | if sess.getHost != nil { | ||
577 | 176 | if sess.timeSince(sess.deliveryHostsTimestamp) < sess.HostsCachingExpiryTime { | ||
578 | 177 | return nil | ||
579 | 178 | } | ||
580 | 179 | hosts, err := sess.getHost.Get() | ||
581 | 180 | if err != nil { | ||
582 | 181 | sess.Log.Errorf("getHosts: %v", err) | ||
583 | 182 | sess.setState(Error) | ||
584 | 183 | return err | ||
585 | 184 | } | ||
586 | 185 | sess.deliveryHostsTimestamp = time.Now() | ||
587 | 186 | sess.deliveryHosts = hosts | ||
588 | 187 | } else { | ||
589 | 188 | sess.deliveryHosts = sess.fallbackHosts | ||
590 | 189 | } | ||
591 | 190 | return nil | ||
592 | 191 | } | ||
593 | 192 | |||
594 | 193 | // startConnectionAttempt/nextHostToTry help connect iterating over candidate hosts | ||
595 | 194 | |||
596 | 195 | func (sess *ClientSession) startConnectionAttempt() { | ||
597 | 196 | if sess.timeSince(sess.lastAttemptTimestamp) > sess.ExpectAllRepairedTime { | ||
598 | 197 | sess.tryHost = 0 | ||
599 | 198 | } | ||
600 | 199 | sess.leftToTry = len(sess.deliveryHosts) | ||
601 | 200 | if sess.leftToTry == 0 { | ||
602 | 201 | panic("should have got hosts from config or remote at this point") | ||
603 | 202 | } | ||
604 | 203 | sess.lastAttemptTimestamp = time.Now() | ||
605 | 204 | } | ||
606 | 205 | |||
607 | 206 | func (sess *ClientSession) nextHostToTry() string { | ||
608 | 207 | if sess.leftToTry == 0 { | ||
609 | 208 | return "" | ||
610 | 209 | } | ||
611 | 210 | res := sess.deliveryHosts[sess.tryHost] | ||
612 | 211 | sess.tryHost = (sess.tryHost + 1) % len(sess.deliveryHosts) | ||
613 | 212 | sess.leftToTry-- | ||
614 | 213 | return res | ||
615 | 214 | } | ||
616 | 215 | |||
617 | 216 | // we reached the Started state, we can retry with the same host if we | ||
618 | 217 | // have to retry again | ||
619 | 218 | func (sess *ClientSession) started() { | ||
620 | 219 | sess.tryHost-- | ||
621 | 220 | if sess.tryHost == -1 { | ||
622 | 221 | sess.tryHost = len(sess.deliveryHosts) - 1 | ||
623 | 222 | } | ||
624 | 223 | sess.setState(Started) | ||
625 | 224 | } | ||
626 | 225 | |||
627 | 117 | // connect to a server using the configuration in the ClientSession | 226 | // connect to a server using the configuration in the ClientSession |
628 | 118 | // and set up the connection. | 227 | // and set up the connection. |
629 | 119 | func (sess *ClientSession) connect() error { | 228 | func (sess *ClientSession) connect() error { |
634 | 120 | conn, err := net.DialTimeout("tcp", sess.ServerAddr, sess.ExchangeTimeout) | 229 | sess.startConnectionAttempt() |
635 | 121 | if err != nil { | 230 | var err error |
636 | 122 | sess.setState(Error) | 231 | var conn net.Conn |
637 | 123 | return fmt.Errorf("connect: %s", err) | 232 | for { |
638 | 233 | host := sess.nextHostToTry() | ||
639 | 234 | if host == "" { | ||
640 | 235 | sess.setState(Error) | ||
641 | 236 | return fmt.Errorf("connect: %s", err) | ||
642 | 237 | } | ||
643 | 238 | sess.Log.Debugf("trying to connect to: %v", host) | ||
644 | 239 | conn, err = net.DialTimeout("tcp", host, sess.ConnectTimeout) | ||
645 | 240 | if err == nil { | ||
646 | 241 | break | ||
647 | 242 | } | ||
648 | 124 | } | 243 | } |
650 | 125 | sess.Connection = tls.Client(conn, sess.TLS) | 244 | sess.setConnection(tls.Client(conn, sess.TLS)) |
651 | 126 | sess.setState(Connected) | 245 | sess.setState(Connected) |
652 | 127 | return nil | 246 | return nil |
653 | 128 | } | 247 | } |
654 | @@ -145,6 +264,8 @@ | |||
655 | 145 | sess.doClose() | 264 | sess.doClose() |
656 | 146 | } | 265 | } |
657 | 147 | func (sess *ClientSession) doClose() { | 266 | func (sess *ClientSession) doClose() { |
658 | 267 | sess.connLock.Lock() | ||
659 | 268 | defer sess.connLock.Unlock() | ||
660 | 148 | if sess.Connection != nil { | 269 | if sess.Connection != nil { |
661 | 149 | sess.Connection.Close() | 270 | sess.Connection.Close() |
662 | 150 | // we ignore Close errors, on purpose (the thinking being that | 271 | // we ignore Close errors, on purpose (the thinking being that |
663 | @@ -224,7 +345,7 @@ | |||
664 | 224 | 345 | ||
665 | 225 | // Call this when you've connected and want to start looping. | 346 | // Call this when you've connected and want to start looping. |
666 | 226 | func (sess *ClientSession) start() error { | 347 | func (sess *ClientSession) start() error { |
668 | 227 | conn := sess.Connection | 348 | conn := sess.getConnection() |
669 | 228 | err := conn.SetDeadline(time.Now().Add(sess.ExchangeTimeout)) | 349 | err := conn.SetDeadline(time.Now().Add(sess.ExchangeTimeout)) |
670 | 229 | if err != nil { | 350 | if err != nil { |
671 | 230 | sess.setState(Error) | 351 | sess.setState(Error) |
672 | @@ -279,15 +400,19 @@ | |||
673 | 279 | sess.proto = proto | 400 | sess.proto = proto |
674 | 280 | sess.pingInterval = pingInterval | 401 | sess.pingInterval = pingInterval |
675 | 281 | sess.Log.Debugf("Connected %v.", conn.LocalAddr()) | 402 | sess.Log.Debugf("Connected %v.", conn.LocalAddr()) |
677 | 282 | sess.setState(Started) | 403 | sess.started() // deals with choosing which host to retry with as well |
678 | 283 | return nil | 404 | return nil |
679 | 284 | } | 405 | } |
680 | 285 | 406 | ||
681 | 286 | // run calls connect, and if it works it calls start, and if it works | 407 | // run calls connect, and if it works it calls start, and if it works |
682 | 287 | // it runs loop in a goroutine, and ships its return value over ErrCh. | 408 | // it runs loop in a goroutine, and ships its return value over ErrCh. |
684 | 288 | func (sess *ClientSession) run(closer func(), connecter, starter, looper func() error) error { | 409 | func (sess *ClientSession) run(closer func(), hostGetter, connecter, starter, looper func() error) error { |
685 | 289 | closer() | 410 | closer() |
687 | 290 | err := connecter() | 411 | err := hostGetter() |
688 | 412 | if err != nil { | ||
689 | 413 | return err | ||
690 | 414 | } | ||
691 | 415 | err = connecter() | ||
692 | 291 | if err == nil { | 416 | if err == nil { |
693 | 292 | err = starter() | 417 | err = starter() |
694 | 293 | if err == nil { | 418 | if err == nil { |
695 | @@ -317,7 +442,7 @@ | |||
696 | 317 | // keep on trying. | 442 | // keep on trying. |
697 | 318 | panic("can't Dial() without a protocol constructor.") | 443 | panic("can't Dial() without a protocol constructor.") |
698 | 319 | } | 444 | } |
700 | 320 | return sess.run(sess.doClose, sess.connect, sess.start, sess.loop) | 445 | return sess.run(sess.doClose, sess.getHosts, sess.connect, sess.start, sess.loop) |
701 | 321 | } | 446 | } |
702 | 322 | 447 | ||
703 | 323 | func init() { | 448 | func init() { |
704 | 324 | 449 | ||
705 | === modified file 'client/session/session_test.go' | |||
706 | --- client/session/session_test.go 2014-03-27 13:26:10 +0000 | |||
707 | +++ client/session/session_test.go 2014-03-31 16:43:44 +0000 | |||
708 | @@ -23,16 +23,21 @@ | |||
709 | 23 | "fmt" | 23 | "fmt" |
710 | 24 | "io" | 24 | "io" |
711 | 25 | "io/ioutil" | 25 | "io/ioutil" |
712 | 26 | "net" | ||
713 | 27 | "net/http" | ||
714 | 28 | "net/http/httptest" | ||
715 | 29 | "reflect" | ||
716 | 30 | "testing" | ||
717 | 31 | "time" | ||
718 | 32 | |||
719 | 26 | . "launchpad.net/gocheck" | 33 | . "launchpad.net/gocheck" |
720 | 34 | |||
721 | 27 | "launchpad.net/ubuntu-push/client/session/levelmap" | 35 | "launchpad.net/ubuntu-push/client/session/levelmap" |
722 | 36 | //"launchpad.net/ubuntu-push/client/gethosts" | ||
723 | 28 | "launchpad.net/ubuntu-push/logger" | 37 | "launchpad.net/ubuntu-push/logger" |
724 | 29 | "launchpad.net/ubuntu-push/protocol" | 38 | "launchpad.net/ubuntu-push/protocol" |
725 | 30 | helpers "launchpad.net/ubuntu-push/testing" | 39 | helpers "launchpad.net/ubuntu-push/testing" |
726 | 31 | "launchpad.net/ubuntu-push/testing/condition" | 40 | "launchpad.net/ubuntu-push/testing/condition" |
727 | 32 | "net" | ||
728 | 33 | "reflect" | ||
729 | 34 | "testing" | ||
730 | 35 | "time" | ||
731 | 36 | ) | 41 | ) |
732 | 37 | 42 | ||
733 | 38 | func TestSession(t *testing.T) { TestingT(t) } | 43 | func TestSession(t *testing.T) { TestingT(t) } |
734 | @@ -181,23 +186,51 @@ | |||
735 | 181 | } | 186 | } |
736 | 182 | 187 | ||
737 | 183 | /**************************************************************** | 188 | /**************************************************************** |
738 | 189 | parseServerAddrSpec() tests | ||
739 | 190 | ****************************************************************/ | ||
740 | 191 | |||
741 | 192 | func (cs *clientSessionSuite) TestParseServerAddrSpec(c *C) { | ||
742 | 193 | hEp, fallbackHosts := parseServerAddrSpec("http://foo/hosts") | ||
743 | 194 | c.Check(hEp, Equals, "http://foo/hosts") | ||
744 | 195 | c.Check(fallbackHosts, IsNil) | ||
745 | 196 | |||
746 | 197 | hEp, fallbackHosts = parseServerAddrSpec("foo:443") | ||
747 | 198 | c.Check(hEp, Equals, "") | ||
748 | 199 | c.Check(fallbackHosts, DeepEquals, []string{"foo:443"}) | ||
749 | 200 | |||
750 | 201 | hEp, fallbackHosts = parseServerAddrSpec("foo:443|bar:443") | ||
751 | 202 | c.Check(hEp, Equals, "") | ||
752 | 203 | c.Check(fallbackHosts, DeepEquals, []string{"foo:443", "bar:443"}) | ||
753 | 204 | } | ||
754 | 205 | |||
755 | 206 | /**************************************************************** | ||
756 | 184 | NewSession() tests | 207 | NewSession() tests |
757 | 185 | ****************************************************************/ | 208 | ****************************************************************/ |
758 | 186 | 209 | ||
759 | 210 | var dummyConf = ClientSessionConfig{} | ||
760 | 211 | |||
761 | 187 | func (cs *clientSessionSuite) TestNewSessionPlainWorks(c *C) { | 212 | func (cs *clientSessionSuite) TestNewSessionPlainWorks(c *C) { |
763 | 188 | sess, err := NewSession("", nil, 0, "", cs.lvls, cs.log) | 213 | sess, err := NewSession("foo:443", dummyConf, "", cs.lvls, cs.log) |
764 | 189 | c.Check(sess, NotNil) | 214 | c.Check(sess, NotNil) |
765 | 190 | c.Check(err, IsNil) | 215 | c.Check(err, IsNil) |
766 | 216 | c.Check(sess.fallbackHosts, DeepEquals, []string{"foo:443"}) | ||
767 | 191 | // but no root CAs set | 217 | // but no root CAs set |
768 | 192 | c.Check(sess.TLS.RootCAs, IsNil) | 218 | c.Check(sess.TLS.RootCAs, IsNil) |
769 | 193 | c.Check(sess.State(), Equals, Disconnected) | 219 | c.Check(sess.State(), Equals, Disconnected) |
770 | 194 | } | 220 | } |
771 | 195 | 221 | ||
773 | 196 | var certfile string = helpers.SourceRelative("../../server/acceptance/config/testing.cert") | 222 | func (cs *clientSessionSuite) TestNewSessionHostEndpointWorks(c *C) { |
774 | 223 | sess, err := NewSession("http://foo/hosts", dummyConf, "wah", cs.lvls, cs.log) | ||
775 | 224 | c.Assert(err, IsNil) | ||
776 | 225 | c.Check(sess.getHost, NotNil) | ||
777 | 226 | } | ||
778 | 227 | |||
779 | 228 | var certfile string = helpers.SourceRelative("../../server/acceptance/ssl/testing.cert") | ||
780 | 197 | var pem, _ = ioutil.ReadFile(certfile) | 229 | var pem, _ = ioutil.ReadFile(certfile) |
781 | 198 | 230 | ||
782 | 199 | func (cs *clientSessionSuite) TestNewSessionPEMWorks(c *C) { | 231 | func (cs *clientSessionSuite) TestNewSessionPEMWorks(c *C) { |
784 | 200 | sess, err := NewSession("", pem, 0, "wah", cs.lvls, cs.log) | 232 | conf := ClientSessionConfig{PEM: pem} |
785 | 233 | sess, err := NewSession("", conf, "wah", cs.lvls, cs.log) | ||
786 | 201 | c.Check(sess, NotNil) | 234 | c.Check(sess, NotNil) |
787 | 202 | c.Assert(err, IsNil) | 235 | c.Assert(err, IsNil) |
788 | 203 | c.Check(sess.TLS.RootCAs, NotNil) | 236 | c.Check(sess.TLS.RootCAs, NotNil) |
789 | @@ -205,25 +238,172 @@ | |||
790 | 205 | 238 | ||
791 | 206 | func (cs *clientSessionSuite) TestNewSessionBadPEMFileContentFails(c *C) { | 239 | func (cs *clientSessionSuite) TestNewSessionBadPEMFileContentFails(c *C) { |
792 | 207 | badpem := []byte("This is not the PEM you're looking for.") | 240 | badpem := []byte("This is not the PEM you're looking for.") |
794 | 208 | sess, err := NewSession("", badpem, 0, "wah", cs.lvls, cs.log) | 241 | conf := ClientSessionConfig{PEM: badpem} |
795 | 242 | sess, err := NewSession("", conf, "wah", cs.lvls, cs.log) | ||
796 | 209 | c.Check(sess, IsNil) | 243 | c.Check(sess, IsNil) |
797 | 210 | c.Check(err, NotNil) | 244 | c.Check(err, NotNil) |
798 | 211 | } | 245 | } |
799 | 212 | 246 | ||
800 | 213 | func (cs *clientSessionSuite) TestNewSessionBadLevelMapFails(c *C) { | 247 | func (cs *clientSessionSuite) TestNewSessionBadLevelMapFails(c *C) { |
801 | 214 | ferr := func() (levelmap.LevelMap, error) { return nil, errors.New("Busted.") } | 248 | ferr := func() (levelmap.LevelMap, error) { return nil, errors.New("Busted.") } |
803 | 215 | sess, err := NewSession("", nil, 0, "wah", ferr, cs.log) | 249 | sess, err := NewSession("", dummyConf, "wah", ferr, cs.log) |
804 | 216 | c.Check(sess, IsNil) | 250 | c.Check(sess, IsNil) |
805 | 217 | c.Assert(err, NotNil) | 251 | c.Assert(err, NotNil) |
806 | 218 | } | 252 | } |
807 | 219 | 253 | ||
808 | 220 | /**************************************************************** | 254 | /**************************************************************** |
809 | 255 | getHosts() tests | ||
810 | 256 | ****************************************************************/ | ||
811 | 257 | |||
812 | 258 | func (cs *clientSessionSuite) TestGetHostsFallback(c *C) { | ||
813 | 259 | fallback := []string{"foo:443", "bar:443"} | ||
814 | 260 | sess := &ClientSession{fallbackHosts: fallback} | ||
815 | 261 | err := sess.getHosts() | ||
816 | 262 | c.Assert(err, IsNil) | ||
817 | 263 | c.Check(sess.deliveryHosts, DeepEquals, fallback) | ||
818 | 264 | } | ||
819 | 265 | |||
820 | 266 | type testHostGetter struct { | ||
821 | 267 | hosts []string | ||
822 | 268 | err error | ||
823 | 269 | } | ||
824 | 270 | |||
825 | 271 | func (thg *testHostGetter) Get() ([]string, error) { | ||
826 | 272 | return thg.hosts, thg.err | ||
827 | 273 | } | ||
828 | 274 | |||
829 | 275 | func (cs *clientSessionSuite) TestGetHostsRemote(c *C) { | ||
830 | 276 | hostGetter := &testHostGetter{[]string{"foo:443", "bar:443"}, nil} | ||
831 | 277 | sess := &ClientSession{getHost: hostGetter, timeSince: time.Since} | ||
832 | 278 | err := sess.getHosts() | ||
833 | 279 | c.Assert(err, IsNil) | ||
834 | 280 | c.Check(sess.deliveryHosts, DeepEquals, []string{"foo:443", "bar:443"}) | ||
835 | 281 | } | ||
836 | 282 | |||
837 | 283 | func (cs *clientSessionSuite) TestGetHostsRemoteError(c *C) { | ||
838 | 284 | sess, err := NewSession("", dummyConf, "", cs.lvls, cs.log) | ||
839 | 285 | c.Assert(err, IsNil) | ||
840 | 286 | hostsErr := errors.New("failed") | ||
841 | 287 | hostGetter := &testHostGetter{nil, hostsErr} | ||
842 | 288 | sess.getHost = hostGetter | ||
843 | 289 | err = sess.getHosts() | ||
844 | 290 | c.Assert(err, Equals, hostsErr) | ||
845 | 291 | c.Check(sess.deliveryHosts, IsNil) | ||
846 | 292 | c.Check(sess.State(), Equals, Error) | ||
847 | 293 | } | ||
848 | 294 | |||
849 | 295 | func (cs *clientSessionSuite) TestGetHostsRemoteCaching(c *C) { | ||
850 | 296 | hostGetter := &testHostGetter{[]string{"foo:443", "bar:443"}, nil} | ||
851 | 297 | sess := &ClientSession{ | ||
852 | 298 | getHost: hostGetter, | ||
853 | 299 | ClientSessionConfig: ClientSessionConfig{ | ||
854 | 300 | HostsCachingExpiryTime: 2 * time.Hour, | ||
855 | 301 | }, | ||
856 | 302 | timeSince: time.Since, | ||
857 | 303 | } | ||
858 | 304 | err := sess.getHosts() | ||
859 | 305 | c.Assert(err, IsNil) | ||
860 | 306 | hostGetter.hosts = []string{"baz:443"} | ||
861 | 307 | // cached | ||
862 | 308 | err = sess.getHosts() | ||
863 | 309 | c.Assert(err, IsNil) | ||
864 | 310 | c.Check(sess.deliveryHosts, DeepEquals, []string{"foo:443", "bar:443"}) | ||
865 | 311 | // expired | ||
866 | 312 | sess.timeSince = func(ts time.Time) time.Duration { | ||
867 | 313 | return 3 * time.Hour | ||
868 | 314 | } | ||
869 | 315 | err = sess.getHosts() | ||
870 | 316 | c.Assert(err, IsNil) | ||
871 | 317 | c.Check(sess.deliveryHosts, DeepEquals, []string{"baz:443"}) | ||
872 | 318 | } | ||
873 | 319 | |||
874 | 320 | /**************************************************************** | ||
875 | 321 | startConnectionAttempt()/nextHostToTry()/started tests | ||
876 | 322 | ****************************************************************/ | ||
877 | 323 | |||
878 | 324 | func (cs *clientSessionSuite) TestStartConnectionAttempt(c *C) { | ||
879 | 325 | since := time.Since(time.Time{}) | ||
880 | 326 | sess := &ClientSession{ | ||
881 | 327 | ClientSessionConfig: ClientSessionConfig{ | ||
882 | 328 | ExpectAllRepairedTime: 10 * time.Second, | ||
883 | 329 | }, | ||
884 | 330 | timeSince: func(ts time.Time) time.Duration { | ||
885 | 331 | return since | ||
886 | 332 | }, | ||
887 | 333 | deliveryHosts: []string{"foo:443", "bar:443"}, | ||
888 | 334 | } | ||
889 | 335 | // start from first host | ||
890 | 336 | sess.startConnectionAttempt() | ||
891 | 337 | c.Check(sess.lastAttemptTimestamp, Not(Equals), 0) | ||
892 | 338 | c.Check(sess.tryHost, Equals, 0) | ||
893 | 339 | c.Check(sess.leftToTry, Equals, 2) | ||
894 | 340 | since = 1 * time.Second | ||
895 | 341 | sess.tryHost = 1 | ||
896 | 342 | // just continue | ||
897 | 343 | sess.startConnectionAttempt() | ||
898 | 344 | c.Check(sess.tryHost, Equals, 1) | ||
899 | 345 | sess.tryHost = 2 | ||
900 | 346 | } | ||
901 | 347 | |||
902 | 348 | func (cs *clientSessionSuite) TestStartConnectionAttemptNoHostsPanic(c *C) { | ||
903 | 349 | since := time.Since(time.Time{}) | ||
904 | 350 | sess := &ClientSession{ | ||
905 | 351 | ClientSessionConfig: ClientSessionConfig{ | ||
906 | 352 | ExpectAllRepairedTime: 10 * time.Second, | ||
907 | 353 | }, | ||
908 | 354 | timeSince: func(ts time.Time) time.Duration { | ||
909 | 355 | return since | ||
910 | 356 | }, | ||
911 | 357 | } | ||
912 | 358 | c.Check(sess.startConnectionAttempt, PanicMatches, "should have got hosts from config or remote at this point") | ||
913 | 359 | } | ||
914 | 360 | |||
915 | 361 | func (cs *clientSessionSuite) TestNextHostToTry(c *C) { | ||
916 | 362 | sess := &ClientSession{ | ||
917 | 363 | deliveryHosts: []string{"foo:443", "bar:443", "baz:443"}, | ||
918 | 364 | tryHost: 0, | ||
919 | 365 | leftToTry: 3, | ||
920 | 366 | } | ||
921 | 367 | c.Check(sess.nextHostToTry(), Equals, "foo:443") | ||
922 | 368 | c.Check(sess.nextHostToTry(), Equals, "bar:443") | ||
923 | 369 | c.Check(sess.nextHostToTry(), Equals, "baz:443") | ||
924 | 370 | c.Check(sess.nextHostToTry(), Equals, "") | ||
925 | 371 | c.Check(sess.nextHostToTry(), Equals, "") | ||
926 | 372 | c.Check(sess.tryHost, Equals, 0) | ||
927 | 373 | |||
928 | 374 | sess.leftToTry = 3 | ||
929 | 375 | sess.tryHost = 1 | ||
930 | 376 | c.Check(sess.nextHostToTry(), Equals, "bar:443") | ||
931 | 377 | c.Check(sess.nextHostToTry(), Equals, "baz:443") | ||
932 | 378 | c.Check(sess.nextHostToTry(), Equals, "foo:443") | ||
933 | 379 | c.Check(sess.nextHostToTry(), Equals, "") | ||
934 | 380 | c.Check(sess.nextHostToTry(), Equals, "") | ||
935 | 381 | c.Check(sess.tryHost, Equals, 1) | ||
936 | 382 | } | ||
937 | 383 | |||
938 | 384 | func (cs *clientSessionSuite) TestStarted(c *C) { | ||
939 | 385 | sess, err := NewSession("", dummyConf, "", cs.lvls, cs.log) | ||
940 | 386 | c.Assert(err, IsNil) | ||
941 | 387 | |||
942 | 388 | sess.deliveryHosts = []string{"foo:443", "bar:443", "baz:443"} | ||
943 | 389 | sess.tryHost = 1 | ||
944 | 390 | |||
945 | 391 | sess.started() | ||
946 | 392 | c.Check(sess.tryHost, Equals, 0) | ||
947 | 393 | c.Check(sess.State(), Equals, Started) | ||
948 | 394 | |||
949 | 395 | sess.started() | ||
950 | 396 | c.Check(sess.tryHost, Equals, 2) | ||
951 | 397 | } | ||
952 | 398 | |||
953 | 399 | /**************************************************************** | ||
954 | 221 | connect() tests | 400 | connect() tests |
955 | 222 | ****************************************************************/ | 401 | ****************************************************************/ |
956 | 223 | 402 | ||
957 | 224 | func (cs *clientSessionSuite) TestConnectFailsWithNoAddress(c *C) { | 403 | func (cs *clientSessionSuite) TestConnectFailsWithNoAddress(c *C) { |
959 | 225 | sess, err := NewSession("", nil, 0, "wah", cs.lvls, cs.log) | 404 | sess, err := NewSession("", dummyConf, "wah", cs.lvls, cs.log) |
960 | 226 | c.Assert(err, IsNil) | 405 | c.Assert(err, IsNil) |
961 | 406 | sess.deliveryHosts = []string{"nowhere"} | ||
962 | 227 | err = sess.connect() | 407 | err = sess.connect() |
963 | 228 | c.Check(err, ErrorMatches, ".*connect.*address.*") | 408 | c.Check(err, ErrorMatches, ".*connect.*address.*") |
964 | 229 | c.Check(sess.State(), Equals, Error) | 409 | c.Check(sess.State(), Equals, Error) |
965 | @@ -233,20 +413,36 @@ | |||
966 | 233 | srv, err := net.Listen("tcp", "localhost:0") | 413 | srv, err := net.Listen("tcp", "localhost:0") |
967 | 234 | c.Assert(err, IsNil) | 414 | c.Assert(err, IsNil) |
968 | 235 | defer srv.Close() | 415 | defer srv.Close() |
975 | 236 | sess, err := NewSession(srv.Addr().String(), nil, 0, "wah", cs.lvls, cs.log) | 416 | sess, err := NewSession("", dummyConf, "wah", cs.lvls, cs.log) |
976 | 237 | c.Assert(err, IsNil) | 417 | c.Assert(err, IsNil) |
977 | 238 | err = sess.connect() | 418 | sess.deliveryHosts = []string{srv.Addr().String()} |
978 | 239 | c.Check(err, IsNil) | 419 | err = sess.connect() |
979 | 240 | c.Check(sess.Connection, NotNil) | 420 | c.Check(err, IsNil) |
980 | 241 | c.Check(sess.State(), Equals, Connected) | 421 | c.Check(sess.Connection, NotNil) |
981 | 422 | c.Check(sess.State(), Equals, Connected) | ||
982 | 423 | } | ||
983 | 424 | |||
984 | 425 | func (cs *clientSessionSuite) TestConnectSecondConnects(c *C) { | ||
985 | 426 | srv, err := net.Listen("tcp", "localhost:0") | ||
986 | 427 | c.Assert(err, IsNil) | ||
987 | 428 | defer srv.Close() | ||
988 | 429 | sess, err := NewSession("", dummyConf, "wah", cs.lvls, cs.log) | ||
989 | 430 | c.Assert(err, IsNil) | ||
990 | 431 | sess.deliveryHosts = []string{"nowhere", srv.Addr().String()} | ||
991 | 432 | err = sess.connect() | ||
992 | 433 | c.Check(err, IsNil) | ||
993 | 434 | c.Check(sess.Connection, NotNil) | ||
994 | 435 | c.Check(sess.State(), Equals, Connected) | ||
995 | 436 | c.Check(sess.tryHost, Equals, 0) | ||
996 | 242 | } | 437 | } |
997 | 243 | 438 | ||
998 | 244 | func (cs *clientSessionSuite) TestConnectConnectFail(c *C) { | 439 | func (cs *clientSessionSuite) TestConnectConnectFail(c *C) { |
999 | 245 | srv, err := net.Listen("tcp", "localhost:0") | 440 | srv, err := net.Listen("tcp", "localhost:0") |
1000 | 246 | c.Assert(err, IsNil) | 441 | c.Assert(err, IsNil) |
1002 | 247 | sess, err := NewSession(srv.Addr().String(), nil, 0, "wah", cs.lvls, cs.log) | 442 | sess, err := NewSession(srv.Addr().String(), dummyConf, "wah", cs.lvls, cs.log) |
1003 | 248 | srv.Close() | 443 | srv.Close() |
1004 | 249 | c.Assert(err, IsNil) | 444 | c.Assert(err, IsNil) |
1005 | 445 | sess.deliveryHosts = []string{srv.Addr().String()} | ||
1006 | 250 | err = sess.connect() | 446 | err = sess.connect() |
1007 | 251 | c.Check(err, ErrorMatches, ".*connection refused") | 447 | c.Check(err, ErrorMatches, ".*connection refused") |
1008 | 252 | c.Check(sess.State(), Equals, Error) | 448 | c.Check(sess.State(), Equals, Error) |
1009 | @@ -257,7 +453,7 @@ | |||
1010 | 257 | ****************************************************************/ | 453 | ****************************************************************/ |
1011 | 258 | 454 | ||
1012 | 259 | func (cs *clientSessionSuite) TestClose(c *C) { | 455 | func (cs *clientSessionSuite) TestClose(c *C) { |
1014 | 260 | sess, err := NewSession("", nil, 0, "wah", cs.lvls, cs.log) | 456 | sess, err := NewSession("", dummyConf, "wah", cs.lvls, cs.log) |
1015 | 261 | c.Assert(err, IsNil) | 457 | c.Assert(err, IsNil) |
1016 | 262 | sess.Connection = &testConn{Name: "TestClose"} | 458 | sess.Connection = &testConn{Name: "TestClose"} |
1017 | 263 | sess.Close() | 459 | sess.Close() |
1018 | @@ -266,7 +462,7 @@ | |||
1019 | 266 | } | 462 | } |
1020 | 267 | 463 | ||
1021 | 268 | func (cs *clientSessionSuite) TestCloseTwice(c *C) { | 464 | func (cs *clientSessionSuite) TestCloseTwice(c *C) { |
1023 | 269 | sess, err := NewSession("", nil, 0, "wah", cs.lvls, cs.log) | 465 | sess, err := NewSession("", dummyConf, "wah", cs.lvls, cs.log) |
1024 | 270 | c.Assert(err, IsNil) | 466 | c.Assert(err, IsNil) |
1025 | 271 | sess.Connection = &testConn{Name: "TestCloseTwice"} | 467 | sess.Connection = &testConn{Name: "TestCloseTwice"} |
1026 | 272 | sess.Close() | 468 | sess.Close() |
1027 | @@ -277,7 +473,7 @@ | |||
1028 | 277 | } | 473 | } |
1029 | 278 | 474 | ||
1030 | 279 | func (cs *clientSessionSuite) TestCloseFails(c *C) { | 475 | func (cs *clientSessionSuite) TestCloseFails(c *C) { |
1032 | 280 | sess, err := NewSession("", nil, 0, "wah", cs.lvls, cs.log) | 476 | sess, err := NewSession("", dummyConf, "wah", cs.lvls, cs.log) |
1033 | 281 | c.Assert(err, IsNil) | 477 | c.Assert(err, IsNil) |
1034 | 282 | sess.Connection = &testConn{Name: "TestCloseFails", CloseCondition: condition.Work(false)} | 478 | sess.Connection = &testConn{Name: "TestCloseFails", CloseCondition: condition.Work(false)} |
1035 | 283 | sess.Close() | 479 | sess.Close() |
1036 | @@ -291,7 +487,7 @@ | |||
1037 | 291 | func (d *derp) Stop() { d.stopped = true } | 487 | func (d *derp) Stop() { d.stopped = true } |
1038 | 292 | 488 | ||
1039 | 293 | func (cs *clientSessionSuite) TestCloseStopsRetrier(c *C) { | 489 | func (cs *clientSessionSuite) TestCloseStopsRetrier(c *C) { |
1041 | 294 | sess, err := NewSession("", nil, 0, "wah", cs.lvls, cs.log) | 490 | sess, err := NewSession("", dummyConf, "wah", cs.lvls, cs.log) |
1042 | 295 | c.Assert(err, IsNil) | 491 | c.Assert(err, IsNil) |
1043 | 296 | ar := new(derp) | 492 | ar := new(derp) |
1044 | 297 | sess.retrier = ar | 493 | sess.retrier = ar |
1045 | @@ -308,7 +504,7 @@ | |||
1046 | 308 | 504 | ||
1047 | 309 | func (cs *clientSessionSuite) TestAutoRedialWorks(c *C) { | 505 | func (cs *clientSessionSuite) TestAutoRedialWorks(c *C) { |
1048 | 310 | // checks that AutoRedial sets up a retrier and tries redialing it | 506 | // checks that AutoRedial sets up a retrier and tries redialing it |
1050 | 311 | sess, err := NewSession("", nil, 0, "wah", cs.lvls, cs.log) | 507 | sess, err := NewSession("", dummyConf, "wah", cs.lvls, cs.log) |
1051 | 312 | c.Assert(err, IsNil) | 508 | c.Assert(err, IsNil) |
1052 | 313 | ar := new(derp) | 509 | ar := new(derp) |
1053 | 314 | sess.retrier = ar | 510 | sess.retrier = ar |
1054 | @@ -319,7 +515,7 @@ | |||
1055 | 319 | 515 | ||
1056 | 320 | func (cs *clientSessionSuite) TestAutoRedialStopsRetrier(c *C) { | 516 | func (cs *clientSessionSuite) TestAutoRedialStopsRetrier(c *C) { |
1057 | 321 | // checks that AutoRedial stops the previous retrier | 517 | // checks that AutoRedial stops the previous retrier |
1059 | 322 | sess, err := NewSession("", nil, 0, "wah", cs.lvls, cs.log) | 518 | sess, err := NewSession("", dummyConf, "wah", cs.lvls, cs.log) |
1060 | 323 | c.Assert(err, IsNil) | 519 | c.Assert(err, IsNil) |
1061 | 324 | ch := make(chan uint32) | 520 | ch := make(chan uint32) |
1062 | 325 | c.Check(sess.retrier, IsNil) | 521 | c.Check(sess.retrier, IsNil) |
1063 | @@ -344,7 +540,10 @@ | |||
1064 | 344 | 540 | ||
1065 | 345 | func (s *msgSuite) SetUpTest(c *C) { | 541 | func (s *msgSuite) SetUpTest(c *C) { |
1066 | 346 | var err error | 542 | var err error |
1068 | 347 | s.sess, err = NewSession("", nil, time.Millisecond, "wah", levelmap.NewLevelMap, helpers.NewTestLogger(c, "debug")) | 543 | conf := ClientSessionConfig{ |
1069 | 544 | ExchangeTimeout: time.Millisecond, | ||
1070 | 545 | } | ||
1071 | 546 | s.sess, err = NewSession("", conf, "wah", levelmap.NewLevelMap, helpers.NewTestLogger(c, "debug")) | ||
1072 | 348 | c.Assert(err, IsNil) | 547 | c.Assert(err, IsNil) |
1073 | 349 | s.sess.Connection = &testConn{Name: "TestHandle*"} | 548 | s.sess.Connection = &testConn{Name: "TestHandle*"} |
1074 | 350 | s.errCh = make(chan error, 1) | 549 | s.errCh = make(chan error, 1) |
1075 | @@ -519,7 +718,7 @@ | |||
1076 | 519 | start() tests | 718 | start() tests |
1077 | 520 | ****************************************************************/ | 719 | ****************************************************************/ |
1078 | 521 | func (cs *clientSessionSuite) TestStartFailsIfSetDeadlineFails(c *C) { | 720 | func (cs *clientSessionSuite) TestStartFailsIfSetDeadlineFails(c *C) { |
1080 | 522 | sess, err := NewSession("", nil, 0, "wah", cs.lvls, cs.log) | 721 | sess, err := NewSession("", dummyConf, "wah", cs.lvls, cs.log) |
1081 | 523 | c.Assert(err, IsNil) | 722 | c.Assert(err, IsNil) |
1082 | 524 | sess.Connection = &testConn{Name: "TestStartFailsIfSetDeadlineFails", | 723 | sess.Connection = &testConn{Name: "TestStartFailsIfSetDeadlineFails", |
1083 | 525 | DeadlineCondition: condition.Work(false)} // setdeadline will fail | 724 | DeadlineCondition: condition.Work(false)} // setdeadline will fail |
1084 | @@ -529,7 +728,7 @@ | |||
1085 | 529 | } | 728 | } |
1086 | 530 | 729 | ||
1087 | 531 | func (cs *clientSessionSuite) TestStartFailsIfWriteFails(c *C) { | 730 | func (cs *clientSessionSuite) TestStartFailsIfWriteFails(c *C) { |
1089 | 532 | sess, err := NewSession("", nil, 0, "wah", cs.lvls, cs.log) | 731 | sess, err := NewSession("", dummyConf, "wah", cs.lvls, cs.log) |
1090 | 533 | c.Assert(err, IsNil) | 732 | c.Assert(err, IsNil) |
1091 | 534 | sess.Connection = &testConn{Name: "TestStartFailsIfWriteFails", | 733 | sess.Connection = &testConn{Name: "TestStartFailsIfWriteFails", |
1092 | 535 | WriteCondition: condition.Work(false)} // write will fail | 734 | WriteCondition: condition.Work(false)} // write will fail |
1093 | @@ -539,7 +738,7 @@ | |||
1094 | 539 | } | 738 | } |
1095 | 540 | 739 | ||
1096 | 541 | func (cs *clientSessionSuite) TestStartFailsIfGetLevelsFails(c *C) { | 740 | func (cs *clientSessionSuite) TestStartFailsIfGetLevelsFails(c *C) { |
1098 | 542 | sess, err := NewSession("", nil, 0, "wah", cs.lvls, cs.log) | 741 | sess, err := NewSession("", dummyConf, "wah", cs.lvls, cs.log) |
1099 | 543 | c.Assert(err, IsNil) | 742 | c.Assert(err, IsNil) |
1100 | 544 | sess.Levels = &brokenLevelMap{} | 743 | sess.Levels = &brokenLevelMap{} |
1101 | 545 | sess.Connection = &testConn{Name: "TestStartConnectMessageFails"} | 744 | sess.Connection = &testConn{Name: "TestStartConnectMessageFails"} |
1102 | @@ -559,7 +758,7 @@ | |||
1103 | 559 | } | 758 | } |
1104 | 560 | 759 | ||
1105 | 561 | func (cs *clientSessionSuite) TestStartConnectMessageFails(c *C) { | 760 | func (cs *clientSessionSuite) TestStartConnectMessageFails(c *C) { |
1107 | 562 | sess, err := NewSession("", nil, 0, "wah", cs.lvls, cs.log) | 761 | sess, err := NewSession("", dummyConf, "wah", cs.lvls, cs.log) |
1108 | 563 | c.Assert(err, IsNil) | 762 | c.Assert(err, IsNil) |
1109 | 564 | sess.Connection = &testConn{Name: "TestStartConnectMessageFails"} | 763 | sess.Connection = &testConn{Name: "TestStartConnectMessageFails"} |
1110 | 565 | errCh := make(chan error, 1) | 764 | errCh := make(chan error, 1) |
1111 | @@ -585,7 +784,7 @@ | |||
1112 | 585 | } | 784 | } |
1113 | 586 | 785 | ||
1114 | 587 | func (cs *clientSessionSuite) TestStartConnackReadError(c *C) { | 786 | func (cs *clientSessionSuite) TestStartConnackReadError(c *C) { |
1116 | 588 | sess, err := NewSession("", nil, 0, "wah", cs.lvls, cs.log) | 787 | sess, err := NewSession("", dummyConf, "wah", cs.lvls, cs.log) |
1117 | 589 | c.Assert(err, IsNil) | 788 | c.Assert(err, IsNil) |
1118 | 590 | sess.Connection = &testConn{Name: "TestStartConnackReadError"} | 789 | sess.Connection = &testConn{Name: "TestStartConnackReadError"} |
1119 | 591 | errCh := make(chan error, 1) | 790 | errCh := make(chan error, 1) |
1120 | @@ -609,7 +808,7 @@ | |||
1121 | 609 | } | 808 | } |
1122 | 610 | 809 | ||
1123 | 611 | func (cs *clientSessionSuite) TestStartBadConnack(c *C) { | 810 | func (cs *clientSessionSuite) TestStartBadConnack(c *C) { |
1125 | 612 | sess, err := NewSession("", nil, 0, "wah", cs.lvls, cs.log) | 811 | sess, err := NewSession("", dummyConf, "wah", cs.lvls, cs.log) |
1126 | 613 | c.Assert(err, IsNil) | 812 | c.Assert(err, IsNil) |
1127 | 614 | sess.Connection = &testConn{Name: "TestStartBadConnack"} | 813 | sess.Connection = &testConn{Name: "TestStartBadConnack"} |
1128 | 615 | errCh := make(chan error, 1) | 814 | errCh := make(chan error, 1) |
1129 | @@ -633,7 +832,7 @@ | |||
1130 | 633 | } | 832 | } |
1131 | 634 | 833 | ||
1132 | 635 | func (cs *clientSessionSuite) TestStartNotConnack(c *C) { | 834 | func (cs *clientSessionSuite) TestStartNotConnack(c *C) { |
1134 | 636 | sess, err := NewSession("", nil, 0, "wah", cs.lvls, cs.log) | 835 | sess, err := NewSession("", dummyConf, "wah", cs.lvls, cs.log) |
1135 | 637 | c.Assert(err, IsNil) | 836 | c.Assert(err, IsNil) |
1136 | 638 | sess.Connection = &testConn{Name: "TestStartBadConnack"} | 837 | sess.Connection = &testConn{Name: "TestStartBadConnack"} |
1137 | 639 | errCh := make(chan error, 1) | 838 | errCh := make(chan error, 1) |
1138 | @@ -657,7 +856,7 @@ | |||
1139 | 657 | } | 856 | } |
1140 | 658 | 857 | ||
1141 | 659 | func (cs *clientSessionSuite) TestStartWorks(c *C) { | 858 | func (cs *clientSessionSuite) TestStartWorks(c *C) { |
1143 | 660 | sess, err := NewSession("", nil, 0, "wah", cs.lvls, cs.log) | 859 | sess, err := NewSession("", dummyConf, "wah", cs.lvls, cs.log) |
1144 | 661 | c.Assert(err, IsNil) | 860 | c.Assert(err, IsNil) |
1145 | 662 | sess.Connection = &testConn{Name: "TestStartWorks"} | 861 | sess.Connection = &testConn{Name: "TestStartWorks"} |
1146 | 663 | errCh := make(chan error, 1) | 862 | errCh := make(chan error, 1) |
1147 | @@ -688,34 +887,49 @@ | |||
1148 | 688 | run() tests | 887 | run() tests |
1149 | 689 | ****************************************************************/ | 888 | ****************************************************************/ |
1150 | 690 | 889 | ||
1153 | 691 | func (cs *clientSessionSuite) TestRunBailsIfConnectFails(c *C) { | 890 | func (cs *clientSessionSuite) TestRunBailsIfHostGetterFails(c *C) { |
1154 | 692 | sess, err := NewSession("", nil, 0, "wah", cs.lvls, cs.log) | 891 | sess, err := NewSession("", dummyConf, "wah", cs.lvls, cs.log) |
1155 | 693 | c.Assert(err, IsNil) | 892 | c.Assert(err, IsNil) |
1157 | 694 | failure := errors.New("TestRunBailsIfConnectFails") | 893 | failure := errors.New("TestRunBailsIfHostGetterFails") |
1158 | 695 | has_closed := false | 894 | has_closed := false |
1159 | 696 | err = sess.run( | 895 | err = sess.run( |
1160 | 697 | func() { has_closed = true }, | 896 | func() { has_closed = true }, |
1161 | 698 | func() error { return failure }, | 897 | func() error { return failure }, |
1162 | 699 | nil, | 898 | nil, |
1163 | 899 | nil, | ||
1164 | 700 | nil) | 900 | nil) |
1165 | 701 | c.Check(err, Equals, failure) | 901 | c.Check(err, Equals, failure) |
1166 | 702 | c.Check(has_closed, Equals, true) | 902 | c.Check(has_closed, Equals, true) |
1167 | 703 | } | 903 | } |
1168 | 704 | 904 | ||
1169 | 905 | func (cs *clientSessionSuite) TestRunBailsIfConnectFails(c *C) { | ||
1170 | 906 | sess, err := NewSession("", dummyConf, "wah", cs.lvls, cs.log) | ||
1171 | 907 | c.Assert(err, IsNil) | ||
1172 | 908 | failure := errors.New("TestRunBailsIfConnectFails") | ||
1173 | 909 | err = sess.run( | ||
1174 | 910 | func() {}, | ||
1175 | 911 | func() error { return nil }, | ||
1176 | 912 | func() error { return failure }, | ||
1177 | 913 | nil, | ||
1178 | 914 | nil) | ||
1179 | 915 | c.Check(err, Equals, failure) | ||
1180 | 916 | } | ||
1181 | 917 | |||
1182 | 705 | func (cs *clientSessionSuite) TestRunBailsIfStartFails(c *C) { | 918 | func (cs *clientSessionSuite) TestRunBailsIfStartFails(c *C) { |
1184 | 706 | sess, err := NewSession("", nil, 0, "wah", cs.lvls, cs.log) | 919 | sess, err := NewSession("", dummyConf, "wah", cs.lvls, cs.log) |
1185 | 707 | c.Assert(err, IsNil) | 920 | c.Assert(err, IsNil) |
1186 | 708 | failure := errors.New("TestRunBailsIfStartFails") | 921 | failure := errors.New("TestRunBailsIfStartFails") |
1187 | 709 | err = sess.run( | 922 | err = sess.run( |
1188 | 710 | func() {}, | 923 | func() {}, |
1189 | 711 | func() error { return nil }, | 924 | func() error { return nil }, |
1190 | 925 | func() error { return nil }, | ||
1191 | 712 | func() error { return failure }, | 926 | func() error { return failure }, |
1192 | 713 | nil) | 927 | nil) |
1193 | 714 | c.Check(err, Equals, failure) | 928 | c.Check(err, Equals, failure) |
1194 | 715 | } | 929 | } |
1195 | 716 | 930 | ||
1196 | 717 | func (cs *clientSessionSuite) TestRunRunsEvenIfLoopFails(c *C) { | 931 | func (cs *clientSessionSuite) TestRunRunsEvenIfLoopFails(c *C) { |
1198 | 718 | sess, err := NewSession("", nil, 0, "wah", cs.lvls, cs.log) | 932 | sess, err := NewSession("", dummyConf, "wah", cs.lvls, cs.log) |
1199 | 719 | c.Assert(err, IsNil) | 933 | c.Assert(err, IsNil) |
1200 | 720 | // just to make a point: until here we haven't set ErrCh & MsgCh (no | 934 | // just to make a point: until here we haven't set ErrCh & MsgCh (no |
1201 | 721 | // biggie if this stops being true) | 935 | // biggie if this stops being true) |
1202 | @@ -727,6 +941,7 @@ | |||
1203 | 727 | func() {}, | 941 | func() {}, |
1204 | 728 | func() error { return nil }, | 942 | func() error { return nil }, |
1205 | 729 | func() error { return nil }, | 943 | func() error { return nil }, |
1206 | 944 | func() error { return nil }, | ||
1207 | 730 | func() error { sess.MsgCh <- notf; return <-failureCh }) | 945 | func() error { sess.MsgCh <- notf; return <-failureCh }) |
1208 | 731 | c.Check(err, Equals, nil) | 946 | c.Check(err, Equals, nil) |
1209 | 732 | // if run doesn't error it sets up the channels | 947 | // if run doesn't error it sets up the channels |
1210 | @@ -744,7 +959,7 @@ | |||
1211 | 744 | ****************************************************************/ | 959 | ****************************************************************/ |
1212 | 745 | 960 | ||
1213 | 746 | func (cs *clientSessionSuite) TestJitter(c *C) { | 961 | func (cs *clientSessionSuite) TestJitter(c *C) { |
1215 | 747 | sess, err := NewSession("", nil, 0, "wah", cs.lvls, cs.log) | 962 | sess, err := NewSession("", dummyConf, "wah", cs.lvls, cs.log) |
1216 | 748 | c.Assert(err, IsNil) | 963 | c.Assert(err, IsNil) |
1217 | 749 | num_tries := 20 // should do the math | 964 | num_tries := 20 // should do the math |
1218 | 750 | spread := time.Second // | 965 | spread := time.Second // |
1219 | @@ -776,12 +991,17 @@ | |||
1220 | 776 | 991 | ||
1221 | 777 | func (cs *clientSessionSuite) TestDialPanics(c *C) { | 992 | func (cs *clientSessionSuite) TestDialPanics(c *C) { |
1222 | 778 | // one last unhappy test | 993 | // one last unhappy test |
1224 | 779 | sess, err := NewSession("", nil, 0, "wah", cs.lvls, cs.log) | 994 | sess, err := NewSession("", dummyConf, "wah", cs.lvls, cs.log) |
1225 | 780 | c.Assert(err, IsNil) | 995 | c.Assert(err, IsNil) |
1226 | 781 | sess.Protocolator = nil | 996 | sess.Protocolator = nil |
1227 | 782 | c.Check(sess.Dial, PanicMatches, ".*protocol constructor.") | 997 | c.Check(sess.Dial, PanicMatches, ".*protocol constructor.") |
1228 | 783 | } | 998 | } |
1229 | 784 | 999 | ||
1230 | 1000 | var ( | ||
1231 | 1001 | dialTestTimeout = 100 * time.Millisecond | ||
1232 | 1002 | dialTestConf = ClientSessionConfig{ExchangeTimeout: dialTestTimeout} | ||
1233 | 1003 | ) | ||
1234 | 1004 | |||
1235 | 785 | func (cs *clientSessionSuite) TestDialWorks(c *C) { | 1005 | func (cs *clientSessionSuite) TestDialWorks(c *C) { |
1236 | 786 | // happy path thoughts | 1006 | // happy path thoughts |
1237 | 787 | cert, err := tls.X509KeyPair(helpers.TestCertPEMBlock, helpers.TestKeyPEMBlock) | 1007 | cert, err := tls.X509KeyPair(helpers.TestCertPEMBlock, helpers.TestKeyPEMBlock) |
1238 | @@ -791,10 +1011,22 @@ | |||
1239 | 791 | SessionTicketsDisabled: true, | 1011 | SessionTicketsDisabled: true, |
1240 | 792 | } | 1012 | } |
1241 | 793 | 1013 | ||
1242 | 794 | timeout := 100 * time.Millisecond | ||
1243 | 795 | lst, err := tls.Listen("tcp", "localhost:0", tlsCfg) | 1014 | lst, err := tls.Listen("tcp", "localhost:0", tlsCfg) |
1244 | 796 | c.Assert(err, IsNil) | 1015 | c.Assert(err, IsNil) |
1246 | 797 | sess, err := NewSession(lst.Addr().String(), nil, timeout, "wah", cs.lvls, cs.log) | 1016 | // advertise |
1247 | 1017 | ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
1248 | 1018 | b, err := json.Marshal(map[string]interface{}{ | ||
1249 | 1019 | "hosts": []string{"nowhere", lst.Addr().String()}, | ||
1250 | 1020 | }) | ||
1251 | 1021 | if err != nil { | ||
1252 | 1022 | panic(err) | ||
1253 | 1023 | } | ||
1254 | 1024 | w.Header().Set("Content-Type", "application/json") | ||
1255 | 1025 | w.Write(b) | ||
1256 | 1026 | })) | ||
1257 | 1027 | defer ts.Close() | ||
1258 | 1028 | |||
1259 | 1029 | sess, err := NewSession(ts.URL, dialTestConf, "wah", cs.lvls, cs.log) | ||
1260 | 798 | c.Assert(err, IsNil) | 1030 | c.Assert(err, IsNil) |
1261 | 799 | tconn := &testConn{CloseCondition: condition.Fail2Work(10)} | 1031 | tconn := &testConn{CloseCondition: condition.Fail2Work(10)} |
1262 | 800 | sess.Connection = tconn | 1032 | sess.Connection = tconn |
1263 | @@ -819,10 +1051,13 @@ | |||
1264 | 819 | c.Check(tconn.CloseCondition.String(), Matches, ".* 9 to go.") | 1051 | c.Check(tconn.CloseCondition.String(), Matches, ".* 9 to go.") |
1265 | 820 | 1052 | ||
1266 | 821 | // now, start: 1. protocol version | 1053 | // now, start: 1. protocol version |
1268 | 822 | v, err := protocol.ReadWireFormatVersion(srv, timeout) | 1054 | v, err := protocol.ReadWireFormatVersion(srv, dialTestTimeout) |
1269 | 823 | c.Assert(err, IsNil) | 1055 | c.Assert(err, IsNil) |
1270 | 824 | c.Assert(v, Equals, protocol.ProtocolWireVersion) | 1056 | c.Assert(v, Equals, protocol.ProtocolWireVersion) |
1271 | 825 | 1057 | ||
1272 | 1058 | // if something goes wrong session would try the first/other host | ||
1273 | 1059 | c.Check(sess.tryHost, Equals, 0) | ||
1274 | 1060 | |||
1275 | 826 | // 2. "connect" (but on the fake protcol above! woo) | 1061 | // 2. "connect" (but on the fake protcol above! woo) |
1276 | 827 | 1062 | ||
1277 | 828 | c.Check(takeNext(downCh), Equals, "deadline 100ms") | 1063 | c.Check(takeNext(downCh), Equals, "deadline 100ms") |
1278 | @@ -843,6 +1078,9 @@ | |||
1279 | 843 | c.Check(takeNext(downCh), Equals, protocol.PingPongMsg{Type: "pong"}) | 1078 | c.Check(takeNext(downCh), Equals, protocol.PingPongMsg{Type: "pong"}) |
1280 | 844 | upCh <- nil | 1079 | upCh <- nil |
1281 | 845 | 1080 | ||
1282 | 1081 | // session would retry the same host | ||
1283 | 1082 | c.Check(sess.tryHost, Equals, 1) | ||
1284 | 1083 | |||
1285 | 846 | // and broadcasts... | 1084 | // and broadcasts... |
1286 | 847 | b := &protocol.BroadcastMsg{ | 1085 | b := &protocol.BroadcastMsg{ |
1287 | 848 | Type: "broadcast", | 1086 | Type: "broadcast", |
1288 | @@ -870,3 +1108,30 @@ | |||
1289 | 870 | upCh <- failure | 1108 | upCh <- failure |
1290 | 871 | c.Check(<-sess.ErrCh, Equals, failure) | 1109 | c.Check(<-sess.ErrCh, Equals, failure) |
1291 | 872 | } | 1110 | } |
1292 | 1111 | |||
1293 | 1112 | func (cs *clientSessionSuite) TestDialWorksDirect(c *C) { | ||
1294 | 1113 | // happy path thoughts | ||
1295 | 1114 | cert, err := tls.X509KeyPair(helpers.TestCertPEMBlock, helpers.TestKeyPEMBlock) | ||
1296 | 1115 | c.Assert(err, IsNil) | ||
1297 | 1116 | tlsCfg := &tls.Config{ | ||
1298 | 1117 | Certificates: []tls.Certificate{cert}, | ||
1299 | 1118 | SessionTicketsDisabled: true, | ||
1300 | 1119 | } | ||
1301 | 1120 | |||
1302 | 1121 | lst, err := tls.Listen("tcp", "localhost:0", tlsCfg) | ||
1303 | 1122 | c.Assert(err, IsNil) | ||
1304 | 1123 | sess, err := NewSession(lst.Addr().String(), dialTestConf, "wah", cs.lvls, cs.log) | ||
1305 | 1124 | c.Assert(err, IsNil) | ||
1306 | 1125 | defer sess.Close() | ||
1307 | 1126 | |||
1308 | 1127 | upCh := make(chan interface{}, 5) | ||
1309 | 1128 | downCh := make(chan interface{}, 5) | ||
1310 | 1129 | proto := &testProtocol{up: upCh, down: downCh} | ||
1311 | 1130 | sess.Protocolator = func(net.Conn) protocol.Protocol { return proto } | ||
1312 | 1131 | |||
1313 | 1132 | go sess.Dial() | ||
1314 | 1133 | |||
1315 | 1134 | _, err = lst.Accept() | ||
1316 | 1135 | c.Assert(err, IsNil) | ||
1317 | 1136 | // connect done | ||
1318 | 1137 | } | ||
1319 | 873 | 1138 | ||
1320 | === modified file 'debian/config.json' | |||
1321 | --- debian/config.json 2014-03-20 12:17:40 +0000 | |||
1322 | +++ debian/config.json 2014-03-31 16:43:44 +0000 | |||
1323 | @@ -1,5 +1,8 @@ | |||
1324 | 1 | { | 1 | { |
1325 | 2 | "connect_timeout": "20s", | ||
1326 | 2 | "exchange_timeout": "30s", | 3 | "exchange_timeout": "30s", |
1327 | 4 | "hosts_cache_expiry": "12h", | ||
1328 | 5 | "expect_all_repaired": "40m", | ||
1329 | 3 | "addr": "push-delivery.ubuntu.com:443", | 6 | "addr": "push-delivery.ubuntu.com:443", |
1330 | 4 | "cert_pem_file": "", | 7 | "cert_pem_file": "", |
1331 | 5 | "stabilizing_timeout": "2s", | 8 | "stabilizing_timeout": "2s", |
1332 | 6 | 9 | ||
1333 | === added directory 'sampleconfigs' | |||
1334 | === renamed file 'server/acceptance/config/config.json' => 'sampleconfigs/dev.json' | |||
1335 | --- server/acceptance/config/config.json 2014-01-17 17:20:34 +0000 | |||
1336 | +++ sampleconfigs/dev.json 2014-03-31 16:43:44 +0000 | |||
1337 | @@ -4,8 +4,8 @@ | |||
1338 | 4 | "broker_queue_size": 10000, | 4 | "broker_queue_size": 10000, |
1339 | 5 | "session_queue_size": 10, | 5 | "session_queue_size": 10, |
1340 | 6 | "addr": "127.0.0.1:9090", | 6 | "addr": "127.0.0.1:9090", |
1343 | 7 | "key_pem_file": "testing.key", | 7 | "key_pem_file": "../server/acceptance/ssl/testing.key", |
1344 | 8 | "cert_pem_file": "testing.cert", | 8 | "cert_pem_file": "../server/acceptance/ssl/testing.cert", |
1345 | 9 | "http_addr": "127.0.0.1:8888", | 9 | "http_addr": "127.0.0.1:8888", |
1346 | 10 | "http_read_timeout": "5s", | 10 | "http_read_timeout": "5s", |
1347 | 11 | "http_write_timeout": "5s" | 11 | "http_write_timeout": "5s" |
1348 | 12 | 12 | ||
1349 | === renamed directory 'server/acceptance/config' => 'server/acceptance/ssl' | |||
1350 | === modified file 'server/acceptance/suites/helpers.go' | |||
1351 | --- server/acceptance/suites/helpers.go 2014-03-25 19:08:00 +0000 | |||
1352 | +++ server/acceptance/suites/helpers.go 2014-03-31 16:43:44 +0000 | |||
1353 | @@ -48,8 +48,8 @@ | |||
1354 | 48 | "session_queue_size": 10, | 48 | "session_queue_size": 10, |
1355 | 49 | "broker_queue_size": 100, | 49 | "broker_queue_size": 100, |
1356 | 50 | "addr": addr, | 50 | "addr": addr, |
1359 | 51 | "key_pem_file": helpers.SourceRelative("../config/testing.key"), | 51 | "key_pem_file": helpers.SourceRelative("../ssl/testing.key"), |
1360 | 52 | "cert_pem_file": helpers.SourceRelative("../config/testing.cert"), | 52 | "cert_pem_file": helpers.SourceRelative("../ssl/testing.cert"), |
1361 | 53 | }) | 53 | }) |
1362 | 54 | } | 54 | } |
1363 | 55 | 55 | ||
1364 | 56 | 56 | ||
1365 | === modified file 'server/acceptance/suites/suite.go' | |||
1366 | --- server/acceptance/suites/suite.go 2014-03-25 19:08:00 +0000 | |||
1367 | +++ server/acceptance/suites/suite.go 2014-03-31 16:43:44 +0000 | |||
1368 | @@ -128,9 +128,9 @@ | |||
1369 | 128 | } | 128 | } |
1370 | 129 | 129 | ||
1371 | 130 | func testClientSession(addr string, deviceId string, reportPings bool) *acceptance.ClientSession { | 130 | func testClientSession(addr string, deviceId string, reportPings bool) *acceptance.ClientSession { |
1373 | 131 | certPEMBlock, err := ioutil.ReadFile(helpers.SourceRelative("../config/testing.cert")) | 131 | certPEMBlock, err := ioutil.ReadFile(helpers.SourceRelative("../ssl/testing.cert")) |
1374 | 132 | if err != nil { | 132 | if err != nil { |
1376 | 133 | panic(fmt.Sprintf("could not read config/testing.cert: %v", err)) | 133 | panic(fmt.Sprintf("could not read ssl/testing.cert: %v", err)) |
1377 | 134 | } | 134 | } |
1378 | 135 | return &acceptance.ClientSession{ | 135 | return &acceptance.ClientSession{ |
1379 | 136 | ExchangeTimeout: 100 * time.Millisecond, | 136 | ExchangeTimeout: 100 * time.Millisecond, |