Merge lp:~jonas-drange/ubuntu-push/vivid-fix-lp1469398 into lp:ubuntu-push/vivid-overlay

Proposed by Jonas G. Drange
Status: Merged
Approved by: Jonas G. Drange
Approved revision: 411
Merged at revision: 150
Proposed branch: lp:~jonas-drange/ubuntu-push/vivid-fix-lp1469398
Merge into: lp:ubuntu-push/vivid-overlay
Diff against target: 199 lines (+35/-48)
2 files modified
poller/poller.go (+24/-34)
poller/poller_test.go (+11/-14)
To merge this branch: bzr merge lp:~jonas-drange/ubuntu-push/vivid-fix-lp1469398
Reviewer Review Type Date Requested Status
Ubuntu Push Hackers Pending
Review via email: mp+272564@code.launchpad.net

Commit message

* Address bug 1469398 by checking NetworkManager.State

Description of the change

* Address bug 1469398 by checking NetworkManager.State

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'poller/poller.go'
--- poller/poller.go 2015-04-29 15:22:03 +0000
+++ poller/poller.go 2015-09-28 10:22:34 +0000
@@ -25,9 +25,9 @@
25 "time"25 "time"
2626
27 "launchpad.net/ubuntu-push/bus"27 "launchpad.net/ubuntu-push/bus"
28 "launchpad.net/ubuntu-push/bus/networkmanager"
28 "launchpad.net/ubuntu-push/bus/polld"29 "launchpad.net/ubuntu-push/bus/polld"
29 "launchpad.net/ubuntu-push/bus/powerd"30 "launchpad.net/ubuntu-push/bus/powerd"
30 "launchpad.net/ubuntu-push/bus/urfkill"
31 "launchpad.net/ubuntu-push/client/session"31 "launchpad.net/ubuntu-push/client/session"
32 "launchpad.net/ubuntu-push/logger"32 "launchpad.net/ubuntu-push/logger"
33 "launchpad.net/ubuntu-push/util"33 "launchpad.net/ubuntu-push/util"
@@ -69,7 +69,7 @@
69 log logger.Logger69 log logger.Logger
70 powerd powerd.Powerd70 powerd powerd.Powerd
71 polld polld.Polld71 polld polld.Polld
72 urfkill urfkill.URfkill72 nm networkmanager.NetworkManager
73 cookie string73 cookie string
74 sessionState stater74 sessionState stater
75 requestWakeupCh chan struct{}75 requestWakeupCh chan struct{}
@@ -101,12 +101,13 @@
101 if p.powerd != nil || p.polld != nil {101 if p.powerd != nil || p.polld != nil {
102 return ErrAlreadyStarted102 return ErrAlreadyStarted
103 }103 }
104
104 powerdEndp := bus.SystemBus.Endpoint(powerd.BusAddress, p.log)105 powerdEndp := bus.SystemBus.Endpoint(powerd.BusAddress, p.log)
105 polldEndp := bus.SessionBus.Endpoint(polld.BusAddress, p.log)106 polldEndp := bus.SessionBus.Endpoint(polld.BusAddress, p.log)
106 urEndp := bus.SystemBus.Endpoint(urfkill.BusAddress, p.log)107 nmEndp := bus.SystemBus.Endpoint(networkmanager.BusAddress, p.log)
107 urWLANKillswitchEndp := bus.SystemBus.Endpoint(urfkill.WLANKillswitchBusAddress, p.log)108
108 var wg sync.WaitGroup109 var wg sync.WaitGroup
109 wg.Add(4)110 wg.Add(3)
110 go func() {111 go func() {
111 n := util.NewAutoRedialer(powerdEndp).Redial()112 n := util.NewAutoRedialer(powerdEndp).Redial()
112 p.log.Debugf("powerd dialed on try %d", n)113 p.log.Debugf("powerd dialed on try %d", n)
@@ -118,20 +119,15 @@
118 wg.Done()119 wg.Done()
119 }()120 }()
120 go func() {121 go func() {
121 n := util.NewAutoRedialer(urEndp).Redial()122 n := util.NewAutoRedialer(nmEndp).Redial()
122 p.log.Debugf("URfkill dialed on try %d", n)123 p.log.Debugf("NetworkManager dialed on try %d", n)
123 wg.Done()
124 }()
125 go func() {
126 n := util.NewAutoRedialer(urWLANKillswitchEndp).Redial()
127 p.log.Debugf("URfkill (WLAN killswitch) dialed on try %d", n)
128 wg.Done()124 wg.Done()
129 }()125 }()
130 wg.Wait()126 wg.Wait()
131127
132 p.powerd = powerd.New(powerdEndp, p.log)128 p.powerd = powerd.New(powerdEndp, p.log)
133 p.polld = polld.New(polldEndp, p.log)129 p.polld = polld.New(polldEndp, p.log)
134 p.urfkill = urfkill.New(urEndp, urWLANKillswitchEndp, p.log)130 p.nm = networkmanager.New(nmEndp, p.log)
135131
136 // busy sleep loop to workaround go's timer/sleep132 // busy sleep loop to workaround go's timer/sleep
137 // not accounting for time when the system is suspended133 // not accounting for time when the system is suspended
@@ -154,7 +150,7 @@
154 if p.log == nil {150 if p.log == nil {
155 return ErrUnconfigured151 return ErrUnconfigured
156 }152 }
157 if p.powerd == nil || p.polld == nil || p.urfkill == nil {153 if p.powerd == nil || p.polld == nil || p.nm == nil {
158 return ErrNotStarted154 return ErrNotStarted
159 }155 }
160 wakeupCh, err := p.powerd.WatchWakeups()156 wakeupCh, err := p.powerd.WatchWakeups()
@@ -165,19 +161,13 @@
165 if err != nil {161 if err != nil {
166 return err162 return err
167 }163 }
168 flightMode := p.urfkill.IsFlightMode()164 nmState := p.nm.GetState()
169 wlanKillswitchState := p.urfkill.GetWLANKillswitchState()165 nmStateCh, _, err := p.nm.WatchState()
170 flightModeCh, _, err := p.urfkill.WatchFlightMode()166 if err != nil {
171 if err != nil {167 return err
172 return err168 }
173 }
174 wlanKillswitchStateCh, _, err := p.urfkill.WatchWLANKillswitchState()
175 if err != nil {
176 return err
177 }
178
179 filteredWakeUpCh := make(chan bool)169 filteredWakeUpCh := make(chan bool)
180 go p.control(wakeupCh, filteredWakeUpCh, flightMode, flightModeCh, wlanKillswitchState, wlanKillswitchStateCh)170 go p.control(wakeupCh, filteredWakeUpCh, nmState, nmStateCh)
181 go p.run(filteredWakeUpCh, doneCh)171 go p.run(filteredWakeUpCh, doneCh)
182 return nil172 return nil
183}173}
@@ -195,9 +185,10 @@
195 return t, cookie, err185 return t, cookie, err
196}186}
197187
198func (p *poller) control(wakeupCh <-chan bool, filteredWakeUpCh chan<- bool, flightMode bool, flightModeCh <-chan bool, wlanKillswitchState urfkill.KillswitchState, wlanKillswitchStateCh <-chan urfkill.KillswitchState) {188func (p *poller) control(wakeupCh <-chan bool, filteredWakeUpCh chan<- bool, nmState networkmanager.State, nmStateCh <-chan networkmanager.State) {
199 wirelessEnabled := wlanKillswitchState == urfkill.KillswitchStateUnblocked189 connected := nmState == networkmanager.ConnectedGlobal
200 dontPoll := flightMode && !wirelessEnabled190 dontPoll := !connected
191 p.log.Debugf("nmState: %v, networkmanager.ConnectedGlobal: %v", nmState, networkmanager.ConnectedGlobal)
201 var t time.Time192 var t time.Time
202 cookie := ""193 cookie := ""
203 holdsWakeLock := false194 holdsWakeLock := false
@@ -234,12 +225,11 @@
234 filteredWakeUpCh <- true225 filteredWakeUpCh <- true
235 }226 }
236 }227 }
237 case flightMode = <-flightModeCh:228 case nmState = <-nmStateCh:
238 case wlanKillswitchState = <-wlanKillswitchStateCh:229 connected = nmState == networkmanager.ConnectedGlobal
239 wirelessEnabled = wlanKillswitchState == urfkill.KillswitchStateUnblocked
240 }230 }
241 newDontPoll := flightMode && !wirelessEnabled231 newDontPoll := !connected
242 p.log.Debugf("control: flightMode:%v wirelessEnabled:%v prevDontPoll:%v dontPoll:%v wakeupReq:%v holdsWakeLock:%v", flightMode, wirelessEnabled, dontPoll, newDontPoll, !t.IsZero(), holdsWakeLock)232 p.log.Debugf("control: nmState:%v prevDontPoll:%v dontPoll:%v wakeupReq:%v holdsWakeLock:%v", nmState, dontPoll, newDontPoll, !t.IsZero(), holdsWakeLock)
243 if newDontPoll != dontPoll {233 if newDontPoll != dontPoll {
244 if dontPoll = newDontPoll; dontPoll {234 if dontPoll = newDontPoll; dontPoll {
245 if !t.IsZero() {235 if !t.IsZero() {
246236
=== modified file 'poller/poller_test.go'
--- poller/poller_test.go 2015-04-29 15:22:03 +0000
+++ poller/poller_test.go 2015-09-28 10:22:34 +0000
@@ -21,7 +21,7 @@
2121
22 . "launchpad.net/gocheck"22 . "launchpad.net/gocheck"
2323
24 "launchpad.net/ubuntu-push/bus/urfkill"24 "launchpad.net/ubuntu-push/bus/networkmanager"
25 "launchpad.net/ubuntu-push/client/session"25 "launchpad.net/ubuntu-push/client/session"
26 helpers "launchpad.net/ubuntu-push/testing"26 helpers "launchpad.net/ubuntu-push/testing"
27)27)
@@ -92,8 +92,8 @@
92}92}
9393
94const (94const (
95 wlanOn = urfkill.KillswitchStateUnblocked95 connectedGlobal = networkmanager.ConnectedGlobal
96 wlanOff = urfkill.KillswitchStateSoftBlocked96 disconnectedGlobal = networkmanager.Disconnected
97)97)
9898
99func (s *PrSuite) TestStep(c *C) {99func (s *PrSuite) TestStep(c *C) {
@@ -117,7 +117,7 @@
117 ch := make(chan string)117 ch := make(chan string)
118 // now, run118 // now, run
119 filteredWakeUpCh := make(chan bool)119 filteredWakeUpCh := make(chan bool)
120 go p.control(wakeupCh, filteredWakeUpCh, false, nil, wlanOn, nil)120 go p.control(wakeupCh, filteredWakeUpCh, connectedGlobal, nil)
121 go func() { ch <- p.step(filteredWakeUpCh, doneCh, "old cookie") }()121 go func() { ch <- p.step(filteredWakeUpCh, doneCh, "old cookie") }()
122 select {122 select {
123 case s := <-ch:123 case s := <-ch:
@@ -143,9 +143,8 @@
143 wakeUpCh := make(chan bool)143 wakeUpCh := make(chan bool)
144 filteredWakeUpCh := make(chan bool)144 filteredWakeUpCh := make(chan bool)
145 s.myd.watchWakeCh = make(chan bool, 1)145 s.myd.watchWakeCh = make(chan bool, 1)
146 flightModeCh := make(chan bool)146 nmStateCh := make(chan networkmanager.State)
147 wlanKillswitchStateCh := make(chan urfkill.KillswitchState)147 go p.control(wakeUpCh, filteredWakeUpCh, connectedGlobal, nmStateCh)
148 go p.control(wakeUpCh, filteredWakeUpCh, false, flightModeCh, wlanOn, wlanKillswitchStateCh)
149148
150 // works149 // works
151 err := p.requestWakeup()150 err := p.requestWakeup()
@@ -161,19 +160,17 @@
161 wakeUpCh <- true160 wakeUpCh <- true
162 <-filteredWakeUpCh161 <-filteredWakeUpCh
163162
164 // flight mode163 nmStateCh <- disconnectedGlobal
165 flightModeCh <- true
166 wlanKillswitchStateCh <- wlanOff
167 err = p.requestWakeup()164 err = p.requestWakeup()
168 c.Assert(err, IsNil)165 c.Assert(err, IsNil)
169 c.Check(s.myd.watchWakeCh, HasLen, 0)166 c.Check(s.myd.watchWakeCh, HasLen, 0)
170167
171 // wireless on168 // connected
172 wlanKillswitchStateCh <- wlanOn169 nmStateCh <- connectedGlobal
173 c.Check(<-s.myd.watchWakeCh, Equals, true)170 c.Check(<-s.myd.watchWakeCh, Equals, true)
174171
175 // wireless off172 // disconnected
176 wlanKillswitchStateCh <- wlanOff173 nmStateCh <- disconnectedGlobal
177 // pending wakeup was cleared174 // pending wakeup was cleared
178 c.Check(<-s.myd.watchWakeCh, Equals, false)175 c.Check(<-s.myd.watchWakeCh, Equals, false)
179176

Subscribers

People subscribed via source and target branches