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
1=== modified file 'bus/connectivity/connectivity.go'
2--- bus/connectivity/connectivity.go 2015-03-02 16:47:24 +0000
3+++ bus/connectivity/connectivity.go 2015-03-02 16:47:24 +0000
4@@ -1,5 +1,5 @@
5 /*
6- Copyright 2013-2014 Canonical Ltd.
7+ Copyright 2013-2015 Canonical Ltd.
8
9 This program is free software: you can redistribute it and/or modify it
10 under the terms of the GNU General Public License version 3, as published
11@@ -55,7 +55,7 @@
12 log logger.Logger
13 endp bus.Endpoint
14 connAttempts uint32
15- webget func(ch chan<- bool)
16+ webchk Webchecker
17 webgetCh chan bool
18 currentState networkmanager.State
19 lastSent bool
20@@ -77,7 +77,7 @@
21 config: config,
22 log: log,
23 endp: endp,
24- webget: wg.Webcheck,
25+ webchk: wg,
26 done: make(chan struct{}),
27 }
28 }
29@@ -201,7 +201,7 @@
30 // cleared webgetCh and wont receive
31 // on it
32 cs.webgetCh = make(chan bool, 1)
33- go cs.webget(cs.webgetCh)
34+ go cs.webchk.Webcheck(cs.webgetCh)
35 }
36
37 case connected := <-cs.webgetCh:
38@@ -261,5 +261,6 @@
39 if !cs.canceled {
40 cs.canceled = true
41 close(cs.done)
42+ cs.webchk.Close()
43 }
44 }
45
46=== modified file 'bus/connectivity/connectivity_test.go'
47--- bus/connectivity/connectivity_test.go 2015-03-02 16:47:24 +0000
48+++ bus/connectivity/connectivity_test.go 2015-03-02 16:47:24 +0000
49@@ -1,5 +1,5 @@
50 /*
51- Copyright 2013-2014 Canonical Ltd.
52+ Copyright 2013-2015 Canonical Ltd.
53
54 This program is free software: you can redistribute it and/or modify it
55 under the terms of the GNU General Public License version 3, as published
56@@ -233,6 +233,15 @@
57 tests for step()
58 */
59
60+type testWebchk func(ch chan<- bool)
61+
62+func (x testWebchk) Webcheck(ch chan<- bool) {
63+ x(ch)
64+}
65+
66+func (x testWebchk) Close() {
67+}
68+
69 func (s *ConnSuite) TestSteps(c *C) {
70 var webget_p condition.Interface = condition.Work(true)
71 recheck_timeout := 50 * time.Millisecond
72@@ -246,7 +255,7 @@
73 networkStateCh: ch,
74 timer: time.NewTimer(time.Second),
75 log: s.log,
76- webget: func(ch chan<- bool) { ch <- webget_p.OK() },
77+ webchk: testWebchk(func(ch chan<- bool) { ch <- webget_p.OK() }),
78 lastSent: false,
79 }
80 ch <- networkmanager.ConnectedGlobal
81
82=== modified file 'bus/connectivity/webchecker.go'
83--- bus/connectivity/webchecker.go 2015-02-05 13:38:31 +0000
84+++ bus/connectivity/webchecker.go 2015-03-02 16:47:24 +0000
85@@ -1,5 +1,5 @@
86 /*
87- Copyright 2013-2014 Canonical Ltd.
88+ Copyright 2013-2015 Canonical Ltd.
89
90 This program is free software: you can redistribute it and/or modify it
91 under the terms of the GNU General Public License version 3, as published
92@@ -40,6 +40,8 @@
93 // contents match the target. If so, then it sends true; if anything
94 // fails, it sends false.
95 Webcheck(chan<- bool)
96+ // Close idle connections.
97+ Close()
98 }
99
100 type webchecker struct {
101@@ -89,3 +91,7 @@
102 ch <- false
103 }
104 }
105+
106+func (wb *webchecker) Close() {
107+ wb.cli.Transport.(*http13.Transport).CloseIdleConnections()
108+}
109
110=== modified file 'bus/connectivity/webchecker_test.go'
111--- bus/connectivity/webchecker_test.go 2015-02-05 13:38:31 +0000
112+++ bus/connectivity/webchecker_test.go 2015-03-02 16:47:24 +0000
113@@ -1,5 +1,5 @@
114 /*
115- Copyright 2013-2014 Canonical Ltd.
116+ Copyright 2013-2015 Canonical Ltd.
117
118 This program is free software: you can redistribute it and/or modify it
119 under the terms of the GNU General Public License version 3, as published
120@@ -81,6 +81,7 @@
121 defer ts.Close()
122
123 ck := NewWebchecker(ts.URL, staticHash, 5*time.Second, s.log)
124+ defer ck.Close()
125 ch := make(chan bool, 1)
126 ck.Webcheck(ch)
127 c.Check(<-ch, Equals, true)
128@@ -89,6 +90,7 @@
129 // Webchecker sends false if the download fails.
130 func (s *WebcheckerSuite) TestActualFails(c *C) {
131 ck := NewWebchecker("garbage://", "", 5*time.Second, s.log)
132+ defer ck.Close()
133 ch := make(chan bool, 1)
134 ck.Webcheck(ch)
135 c.Check(<-ch, Equals, false)
136@@ -100,6 +102,7 @@
137 defer ts.Close()
138
139 ck := NewWebchecker(ts.URL, staticHash, 5*time.Second, s.log)
140+ defer ck.Close()
141 ch := make(chan bool, 1)
142 ck.Webcheck(ch)
143 c.Check(<-ch, Equals, false)
144@@ -112,6 +115,7 @@
145 defer ts.Close()
146
147 ck := NewWebchecker(ts.URL, bigHash, 5*time.Second, s.log)
148+ defer ck.Close()
149 ch := make(chan bool, 1)
150 ck.Webcheck(ch)
151 c.Check(<-ch, Equals, false)
152@@ -131,6 +135,7 @@
153 }()
154
155 ck := NewWebchecker(ts.URL, bigHash, time.Second, s.log)
156+ defer ck.Close()
157 ch := make(chan bool, 1)
158 ck.Webcheck(ch)
159 c.Check(<-ch, Equals, false)

Subscribers

People subscribed via source and target branches