Merge lp:~pedronis/ubuntu-push/close-webchecker into lp:ubuntu-push/automatic

Proposed by Samuele Pedroni
Status: Merged
Approved by: Samuele Pedroni
Approved revision: 370
Merged at revision: 367
Proposed branch: lp:~pedronis/ubuntu-push/close-webchecker
Merge into: lp:ubuntu-push/automatic
Prerequisite: lp:~pedronis/ubuntu-push/cancel-cancel-cancel
Diff against target: 159 lines (+29/-8)
4 files modified
bus/connectivity/connectivity.go (+5/-4)
bus/connectivity/connectivity_test.go (+11/-2)
bus/connectivity/webchecker.go (+7/-1)
bus/connectivity/webchecker_test.go (+6/-1)
To merge this branch: bzr merge lp:~pedronis/ubuntu-push/close-webchecker
Reviewer Review Type Date Requested Status
John Lenton (community) Approve
Review via email: mp+251477@code.launchpad.net

Commit message

closing webchecker

Description of the change

closing webchecker

To post a comment you must log in.
Revision history for this message
John Lenton (chipaca) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'bus/connectivity/connectivity.go'
--- bus/connectivity/connectivity.go 2015-03-02 16:47:24 +0000
+++ bus/connectivity/connectivity.go 2015-03-02 16:47:24 +0000
@@ -1,5 +1,5 @@
1/*1/*
2 Copyright 2013-2014 Canonical Ltd.2 Copyright 2013-2015 Canonical Ltd.
33
4 This program is free software: you can redistribute it and/or modify it4 This program is free software: you can redistribute it and/or modify it
5 under the terms of the GNU General Public License version 3, as published5 under the terms of the GNU General Public License version 3, as published
@@ -55,7 +55,7 @@
55 log logger.Logger55 log logger.Logger
56 endp bus.Endpoint56 endp bus.Endpoint
57 connAttempts uint3257 connAttempts uint32
58 webget func(ch chan<- bool)58 webchk Webchecker
59 webgetCh chan bool59 webgetCh chan bool
60 currentState networkmanager.State60 currentState networkmanager.State
61 lastSent bool61 lastSent bool
@@ -77,7 +77,7 @@
77 config: config,77 config: config,
78 log: log,78 log: log,
79 endp: endp,79 endp: endp,
80 webget: wg.Webcheck,80 webchk: wg,
81 done: make(chan struct{}),81 done: make(chan struct{}),
82 }82 }
83}83}
@@ -201,7 +201,7 @@
201 // cleared webgetCh and wont receive201 // cleared webgetCh and wont receive
202 // on it202 // on it
203 cs.webgetCh = make(chan bool, 1)203 cs.webgetCh = make(chan bool, 1)
204 go cs.webget(cs.webgetCh)204 go cs.webchk.Webcheck(cs.webgetCh)
205 }205 }
206206
207 case connected := <-cs.webgetCh:207 case connected := <-cs.webgetCh:
@@ -261,5 +261,6 @@
261 if !cs.canceled {261 if !cs.canceled {
262 cs.canceled = true262 cs.canceled = true
263 close(cs.done)263 close(cs.done)
264 cs.webchk.Close()
264 }265 }
265}266}
266267
=== modified file 'bus/connectivity/connectivity_test.go'
--- bus/connectivity/connectivity_test.go 2015-03-02 16:47:24 +0000
+++ bus/connectivity/connectivity_test.go 2015-03-02 16:47:24 +0000
@@ -1,5 +1,5 @@
1/*1/*
2 Copyright 2013-2014 Canonical Ltd.2 Copyright 2013-2015 Canonical Ltd.
33
4 This program is free software: you can redistribute it and/or modify it4 This program is free software: you can redistribute it and/or modify it
5 under the terms of the GNU General Public License version 3, as published5 under the terms of the GNU General Public License version 3, as published
@@ -233,6 +233,15 @@
233 tests for step()233 tests for step()
234*/234*/
235235
236type testWebchk func(ch chan<- bool)
237
238func (x testWebchk) Webcheck(ch chan<- bool) {
239 x(ch)
240}
241
242func (x testWebchk) Close() {
243}
244
236func (s *ConnSuite) TestSteps(c *C) {245func (s *ConnSuite) TestSteps(c *C) {
237 var webget_p condition.Interface = condition.Work(true)246 var webget_p condition.Interface = condition.Work(true)
238 recheck_timeout := 50 * time.Millisecond247 recheck_timeout := 50 * time.Millisecond
@@ -246,7 +255,7 @@
246 networkStateCh: ch,255 networkStateCh: ch,
247 timer: time.NewTimer(time.Second),256 timer: time.NewTimer(time.Second),
248 log: s.log,257 log: s.log,
249 webget: func(ch chan<- bool) { ch <- webget_p.OK() },258 webchk: testWebchk(func(ch chan<- bool) { ch <- webget_p.OK() }),
250 lastSent: false,259 lastSent: false,
251 }260 }
252 ch <- networkmanager.ConnectedGlobal261 ch <- networkmanager.ConnectedGlobal
253262
=== modified file 'bus/connectivity/webchecker.go'
--- bus/connectivity/webchecker.go 2015-02-05 13:38:31 +0000
+++ bus/connectivity/webchecker.go 2015-03-02 16:47:24 +0000
@@ -1,5 +1,5 @@
1/*1/*
2 Copyright 2013-2014 Canonical Ltd.2 Copyright 2013-2015 Canonical Ltd.
33
4 This program is free software: you can redistribute it and/or modify it4 This program is free software: you can redistribute it and/or modify it
5 under the terms of the GNU General Public License version 3, as published5 under the terms of the GNU General Public License version 3, as published
@@ -40,6 +40,8 @@
40 // contents match the target. If so, then it sends true; if anything40 // contents match the target. If so, then it sends true; if anything
41 // fails, it sends false.41 // fails, it sends false.
42 Webcheck(chan<- bool)42 Webcheck(chan<- bool)
43 // Close idle connections.
44 Close()
43}45}
4446
45type webchecker struct {47type webchecker struct {
@@ -89,3 +91,7 @@
89 ch <- false91 ch <- false
90 }92 }
91}93}
94
95func (wb *webchecker) Close() {
96 wb.cli.Transport.(*http13.Transport).CloseIdleConnections()
97}
9298
=== modified file 'bus/connectivity/webchecker_test.go'
--- bus/connectivity/webchecker_test.go 2015-02-05 13:38:31 +0000
+++ bus/connectivity/webchecker_test.go 2015-03-02 16:47:24 +0000
@@ -1,5 +1,5 @@
1/*1/*
2 Copyright 2013-2014 Canonical Ltd.2 Copyright 2013-2015 Canonical Ltd.
33
4 This program is free software: you can redistribute it and/or modify it4 This program is free software: you can redistribute it and/or modify it
5 under the terms of the GNU General Public License version 3, as published5 under the terms of the GNU General Public License version 3, as published
@@ -81,6 +81,7 @@
81 defer ts.Close()81 defer ts.Close()
8282
83 ck := NewWebchecker(ts.URL, staticHash, 5*time.Second, s.log)83 ck := NewWebchecker(ts.URL, staticHash, 5*time.Second, s.log)
84 defer ck.Close()
84 ch := make(chan bool, 1)85 ch := make(chan bool, 1)
85 ck.Webcheck(ch)86 ck.Webcheck(ch)
86 c.Check(<-ch, Equals, true)87 c.Check(<-ch, Equals, true)
@@ -89,6 +90,7 @@
89// Webchecker sends false if the download fails.90// Webchecker sends false if the download fails.
90func (s *WebcheckerSuite) TestActualFails(c *C) {91func (s *WebcheckerSuite) TestActualFails(c *C) {
91 ck := NewWebchecker("garbage://", "", 5*time.Second, s.log)92 ck := NewWebchecker("garbage://", "", 5*time.Second, s.log)
93 defer ck.Close()
92 ch := make(chan bool, 1)94 ch := make(chan bool, 1)
93 ck.Webcheck(ch)95 ck.Webcheck(ch)
94 c.Check(<-ch, Equals, false)96 c.Check(<-ch, Equals, false)
@@ -100,6 +102,7 @@
100 defer ts.Close()102 defer ts.Close()
101103
102 ck := NewWebchecker(ts.URL, staticHash, 5*time.Second, s.log)104 ck := NewWebchecker(ts.URL, staticHash, 5*time.Second, s.log)
105 defer ck.Close()
103 ch := make(chan bool, 1)106 ch := make(chan bool, 1)
104 ck.Webcheck(ch)107 ck.Webcheck(ch)
105 c.Check(<-ch, Equals, false)108 c.Check(<-ch, Equals, false)
@@ -112,6 +115,7 @@
112 defer ts.Close()115 defer ts.Close()
113116
114 ck := NewWebchecker(ts.URL, bigHash, 5*time.Second, s.log)117 ck := NewWebchecker(ts.URL, bigHash, 5*time.Second, s.log)
118 defer ck.Close()
115 ch := make(chan bool, 1)119 ch := make(chan bool, 1)
116 ck.Webcheck(ch)120 ck.Webcheck(ch)
117 c.Check(<-ch, Equals, false)121 c.Check(<-ch, Equals, false)
@@ -131,6 +135,7 @@
131 }()135 }()
132136
133 ck := NewWebchecker(ts.URL, bigHash, time.Second, s.log)137 ck := NewWebchecker(ts.URL, bigHash, time.Second, s.log)
138 defer ck.Close()
134 ch := make(chan bool, 1)139 ch := make(chan bool, 1)
135 ck.Webcheck(ch)140 ck.Webcheck(ch)
136 c.Check(<-ch, Equals, false)141 c.Check(<-ch, Equals, false)

Subscribers

People subscribed via source and target branches