Merge lp:~jonas-drange/ubuntu-push/control-poller into lp:ubuntu-push/automatic

Proposed by Jonas G. Drange
Status: Merged
Approved by: Jonas G. Drange
Approved revision: 413
Merged at revision: 411
Proposed branch: lp:~jonas-drange/ubuntu-push/control-poller
Merge into: lp:ubuntu-push/automatic
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/control-poller
Reviewer Review Type Date Requested Status
Samuele Pedroni Approve
Review via email: mp+272377@code.launchpad.net

This proposal supersedes a proposal from 2015-09-24.

Commit message

[ubuntu-push-client/poller] assert whether or not there's a connection using the same method as local connectivity package

Description of the change

[ubuntu-push-client/poller] assert whether or not there's a connection using the same method as local connectivity package [1].

[1] http://bazaar.launchpad.net/~ubuntu-push-hackers/ubuntu-push/trunk/view/150/bus/connectivity/connectivity.go#L197

To post a comment you must log in.
Revision history for this message
Bill Filler (bfiller) wrote : Posted in a previous version of this proposal

testing branch on arale, seems great. I've tried different combinations of wifi and cellular data on/off and get the expected results with polling not being attempted if no connection.

I am seeing a problem on my krillin with the following setup:
wifi off, cellular data on, I have a connection (Edge), but no data left on plan. It polls for 1 minute in this case and repeats every 30seconds (I changed poll_interval to 30s)

wonder if there is a way to detect if we can actually send recv/data, rather than detecting a connection only

Revision history for this message
Samuele Pedroni (pedronis) wrote :

bfiller:
> wonder if there is a way to detect if we can actually send recv/data, rather than detecting a
> connection only

we have code a bit like that in

bus/connectivity

it plays a role indirectly here not in control() but step(), IsConnected() invoked there ultimately depends on the state found out through connecivity, the issue there that you need to be awake and have a bit of time to check recv/data... unless there some low level way that doesn't involve actually hitting some remote service,

as I mentioning ideally there would be one service in the system that decided "really connected/not connected", and push client would just trust it (then we could simplify code here and code in/depending on bus/connectivity)

Revision history for this message
Samuele Pedroni (pedronis) wrote :

looks good code wise, don't know/cannot judge if this bit of NM works correctly across all devices (given my past troubles with fligh mode and it for example :) ), I let that be tested/opined on by other teams

review: Approve
Revision history for this message
Jonas G. Drange (jonas-drange) wrote :

Test plan (edited) completed, all pass.

Revision history for this message
Ubuntu One Auto Pilot (otto-pilot) wrote :
Download full text (14.6 KiB)

The attempt to merge lp:~jonas-drange/ubuntu-push/control-poller into lp:ubuntu-push/automatic failed. Below is the output from the failed tests.

scripts/deps.sh server/dev/server.go
scripts/deps.sh server/acceptance/cmd/acceptanceclient.go
scripts/deps.sh ubuntu-push-client.go
/mnt/tarmac/cache/ubuntu-push-automatic/go-ws/bin/godeps -t launchpad.net/ubuntu-push launchpad.net/ubuntu-push/accounts launchpad.net/ubuntu-push/bus launchpad.net/ubuntu-push/bus/accounts launchpad.net/ubuntu-push/bus/connectivity launchpad.net/ubuntu-push/bus/emblemcounter launchpad.net/ubuntu-push/bus/haptic launchpad.net/ubuntu-push/bus/networkmanager launchpad.net/ubuntu-push/bus/notifications launchpad.net/ubuntu-push/bus/polld launchpad.net/ubuntu-push/bus/powerd launchpad.net/ubuntu-push/bus/systemimage launchpad.net/ubuntu-push/bus/testing launchpad.net/ubuntu-push/bus/unitygreeter launchpad.net/ubuntu-push/bus/urfkill launchpad.net/ubuntu-push/bus/windowstack launchpad.net/ubuntu-push/click launchpad.net/ubuntu-push/click/cappinfo launchpad.net/ubuntu-push/click/cblacklist launchpad.net/ubuntu-push/click/cclick launchpad.net/ubuntu-push/click/testing launchpad.net/ubuntu-push/client launchpad.net/ubuntu-push/client/gethosts launchpad.net/ubuntu-push/client/service launchpad.net/ubuntu-push/client/session launchpad.net/ubuntu-push/client/session/seenstate launchpad.net/ubuntu-push/config launchpad.net/ubuntu-push/external/murmur3 launchpad.net/ubuntu-push/identifier launchpad.net/ubuntu-push/identifier/testing launchpad.net/ubuntu-push/launch_helper launchpad.net/ubuntu-push/launch_helper/cual launchpad.net/ubuntu-push/launch_helper/helper_finder launchpad.net/ubuntu-push/launch_helper/legacy launchpad.net/ubuntu-push/logger launchpad.net/ubuntu-push/messaging launchpad.net/ubuntu-push/messaging/cmessaging launchpad.net/ubuntu-push/messaging/reply launchpad.net/ubuntu-push/nih launchpad.net/ubuntu-push/nih/cnih launchpad.net/ubuntu-push/poller launchpad.net/ubuntu-push/protocol launchpad.net/ubuntu-push/server launchpad.net/ubuntu-push/server/api launchpad.net/ubuntu-push/server/broker launchpad.net/ubuntu-push/server/broker/simple launchpad.net/ubuntu-push/server/broker/testing launchpad.net/ubuntu-push/server/broker/testsuite launchpad.net/ubuntu-push/server/dev launchpad.net/ubuntu-push/server/listener launchpad.net/ubuntu-push/server/session launchpad.net/ubuntu-push/server/store launchpad.net/ubuntu-push/sounds launchpad.net/ubuntu-push/testing launchpad.net/ubuntu-push/testing/condition launchpad.net/ubuntu-push/urldispatcher launchpad.net/ubuntu-push/urldispatcher/curldispatcher launchpad.net/ubuntu-push/util launchpad.net/ubuntu-push/ launchpad.net/ubuntu-push/server/acceptance/cmd/ launchpad.net/ubuntu-push/server/dev/ 2>/dev/null | cat > dependencies.tsv
rm -f -r /mnt/tarmac/cache/ubuntu-push-automatic/go-ws/pkg
mkdir -p /mnt/tarmac/cache/ubuntu-push-automatic/go-ws/bin
mkdir -p /mnt/tarmac/cache/ubuntu-push-automatic/go-ws/pkg
go get -u launchpad.net/godeps
go get -d -u launchpad.net/gocheck launchpad.net/go-dbus/v1 launchpad.net/go-xdg/v0 code.google.com/p/gosqlite/sqlite3 code.google.com/p/go-uuid/uuid
/mnt/tarmac/cache/ubuntu-push-automatic/go-...

413. By Jonas G. Drange

make format

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'poller/poller.go'
2--- poller/poller.go 2015-04-29 15:22:03 +0000
3+++ poller/poller.go 2015-09-28 08:25:01 +0000
4@@ -25,9 +25,9 @@
5 "time"
6
7 "launchpad.net/ubuntu-push/bus"
8+ "launchpad.net/ubuntu-push/bus/networkmanager"
9 "launchpad.net/ubuntu-push/bus/polld"
10 "launchpad.net/ubuntu-push/bus/powerd"
11- "launchpad.net/ubuntu-push/bus/urfkill"
12 "launchpad.net/ubuntu-push/client/session"
13 "launchpad.net/ubuntu-push/logger"
14 "launchpad.net/ubuntu-push/util"
15@@ -69,7 +69,7 @@
16 log logger.Logger
17 powerd powerd.Powerd
18 polld polld.Polld
19- urfkill urfkill.URfkill
20+ nm networkmanager.NetworkManager
21 cookie string
22 sessionState stater
23 requestWakeupCh chan struct{}
24@@ -101,12 +101,13 @@
25 if p.powerd != nil || p.polld != nil {
26 return ErrAlreadyStarted
27 }
28+
29 powerdEndp := bus.SystemBus.Endpoint(powerd.BusAddress, p.log)
30 polldEndp := bus.SessionBus.Endpoint(polld.BusAddress, p.log)
31- urEndp := bus.SystemBus.Endpoint(urfkill.BusAddress, p.log)
32- urWLANKillswitchEndp := bus.SystemBus.Endpoint(urfkill.WLANKillswitchBusAddress, p.log)
33+ nmEndp := bus.SystemBus.Endpoint(networkmanager.BusAddress, p.log)
34+
35 var wg sync.WaitGroup
36- wg.Add(4)
37+ wg.Add(3)
38 go func() {
39 n := util.NewAutoRedialer(powerdEndp).Redial()
40 p.log.Debugf("powerd dialed on try %d", n)
41@@ -118,20 +119,15 @@
42 wg.Done()
43 }()
44 go func() {
45- n := util.NewAutoRedialer(urEndp).Redial()
46- p.log.Debugf("URfkill dialed on try %d", n)
47- wg.Done()
48- }()
49- go func() {
50- n := util.NewAutoRedialer(urWLANKillswitchEndp).Redial()
51- p.log.Debugf("URfkill (WLAN killswitch) dialed on try %d", n)
52+ n := util.NewAutoRedialer(nmEndp).Redial()
53+ p.log.Debugf("NetworkManager dialed on try %d", n)
54 wg.Done()
55 }()
56 wg.Wait()
57
58 p.powerd = powerd.New(powerdEndp, p.log)
59 p.polld = polld.New(polldEndp, p.log)
60- p.urfkill = urfkill.New(urEndp, urWLANKillswitchEndp, p.log)
61+ p.nm = networkmanager.New(nmEndp, p.log)
62
63 // busy sleep loop to workaround go's timer/sleep
64 // not accounting for time when the system is suspended
65@@ -154,7 +150,7 @@
66 if p.log == nil {
67 return ErrUnconfigured
68 }
69- if p.powerd == nil || p.polld == nil || p.urfkill == nil {
70+ if p.powerd == nil || p.polld == nil || p.nm == nil {
71 return ErrNotStarted
72 }
73 wakeupCh, err := p.powerd.WatchWakeups()
74@@ -165,19 +161,13 @@
75 if err != nil {
76 return err
77 }
78- flightMode := p.urfkill.IsFlightMode()
79- wlanKillswitchState := p.urfkill.GetWLANKillswitchState()
80- flightModeCh, _, err := p.urfkill.WatchFlightMode()
81- if err != nil {
82- return err
83- }
84- wlanKillswitchStateCh, _, err := p.urfkill.WatchWLANKillswitchState()
85- if err != nil {
86- return err
87- }
88-
89+ nmState := p.nm.GetState()
90+ nmStateCh, _, err := p.nm.WatchState()
91+ if err != nil {
92+ return err
93+ }
94 filteredWakeUpCh := make(chan bool)
95- go p.control(wakeupCh, filteredWakeUpCh, flightMode, flightModeCh, wlanKillswitchState, wlanKillswitchStateCh)
96+ go p.control(wakeupCh, filteredWakeUpCh, nmState, nmStateCh)
97 go p.run(filteredWakeUpCh, doneCh)
98 return nil
99 }
100@@ -195,9 +185,10 @@
101 return t, cookie, err
102 }
103
104-func (p *poller) control(wakeupCh <-chan bool, filteredWakeUpCh chan<- bool, flightMode bool, flightModeCh <-chan bool, wlanKillswitchState urfkill.KillswitchState, wlanKillswitchStateCh <-chan urfkill.KillswitchState) {
105- wirelessEnabled := wlanKillswitchState == urfkill.KillswitchStateUnblocked
106- dontPoll := flightMode && !wirelessEnabled
107+func (p *poller) control(wakeupCh <-chan bool, filteredWakeUpCh chan<- bool, nmState networkmanager.State, nmStateCh <-chan networkmanager.State) {
108+ connected := nmState == networkmanager.ConnectedGlobal
109+ dontPoll := !connected
110+ p.log.Debugf("nmState: %v, networkmanager.ConnectedGlobal: %v", nmState, networkmanager.ConnectedGlobal)
111 var t time.Time
112 cookie := ""
113 holdsWakeLock := false
114@@ -234,12 +225,11 @@
115 filteredWakeUpCh <- true
116 }
117 }
118- case flightMode = <-flightModeCh:
119- case wlanKillswitchState = <-wlanKillswitchStateCh:
120- wirelessEnabled = wlanKillswitchState == urfkill.KillswitchStateUnblocked
121+ case nmState = <-nmStateCh:
122+ connected = nmState == networkmanager.ConnectedGlobal
123 }
124- newDontPoll := flightMode && !wirelessEnabled
125- p.log.Debugf("control: flightMode:%v wirelessEnabled:%v prevDontPoll:%v dontPoll:%v wakeupReq:%v holdsWakeLock:%v", flightMode, wirelessEnabled, dontPoll, newDontPoll, !t.IsZero(), holdsWakeLock)
126+ newDontPoll := !connected
127+ p.log.Debugf("control: nmState:%v prevDontPoll:%v dontPoll:%v wakeupReq:%v holdsWakeLock:%v", nmState, dontPoll, newDontPoll, !t.IsZero(), holdsWakeLock)
128 if newDontPoll != dontPoll {
129 if dontPoll = newDontPoll; dontPoll {
130 if !t.IsZero() {
131
132=== modified file 'poller/poller_test.go'
133--- poller/poller_test.go 2015-04-29 15:22:03 +0000
134+++ poller/poller_test.go 2015-09-28 08:25:01 +0000
135@@ -21,7 +21,7 @@
136
137 . "launchpad.net/gocheck"
138
139- "launchpad.net/ubuntu-push/bus/urfkill"
140+ "launchpad.net/ubuntu-push/bus/networkmanager"
141 "launchpad.net/ubuntu-push/client/session"
142 helpers "launchpad.net/ubuntu-push/testing"
143 )
144@@ -92,8 +92,8 @@
145 }
146
147 const (
148- wlanOn = urfkill.KillswitchStateUnblocked
149- wlanOff = urfkill.KillswitchStateSoftBlocked
150+ connectedGlobal = networkmanager.ConnectedGlobal
151+ disconnectedGlobal = networkmanager.Disconnected
152 )
153
154 func (s *PrSuite) TestStep(c *C) {
155@@ -117,7 +117,7 @@
156 ch := make(chan string)
157 // now, run
158 filteredWakeUpCh := make(chan bool)
159- go p.control(wakeupCh, filteredWakeUpCh, false, nil, wlanOn, nil)
160+ go p.control(wakeupCh, filteredWakeUpCh, connectedGlobal, nil)
161 go func() { ch <- p.step(filteredWakeUpCh, doneCh, "old cookie") }()
162 select {
163 case s := <-ch:
164@@ -143,9 +143,8 @@
165 wakeUpCh := make(chan bool)
166 filteredWakeUpCh := make(chan bool)
167 s.myd.watchWakeCh = make(chan bool, 1)
168- flightModeCh := make(chan bool)
169- wlanKillswitchStateCh := make(chan urfkill.KillswitchState)
170- go p.control(wakeUpCh, filteredWakeUpCh, false, flightModeCh, wlanOn, wlanKillswitchStateCh)
171+ nmStateCh := make(chan networkmanager.State)
172+ go p.control(wakeUpCh, filteredWakeUpCh, connectedGlobal, nmStateCh)
173
174 // works
175 err := p.requestWakeup()
176@@ -161,19 +160,17 @@
177 wakeUpCh <- true
178 <-filteredWakeUpCh
179
180- // flight mode
181- flightModeCh <- true
182- wlanKillswitchStateCh <- wlanOff
183+ nmStateCh <- disconnectedGlobal
184 err = p.requestWakeup()
185 c.Assert(err, IsNil)
186 c.Check(s.myd.watchWakeCh, HasLen, 0)
187
188- // wireless on
189- wlanKillswitchStateCh <- wlanOn
190+ // connected
191+ nmStateCh <- connectedGlobal
192 c.Check(<-s.myd.watchWakeCh, Equals, true)
193
194- // wireless off
195- wlanKillswitchStateCh <- wlanOff
196+ // disconnected
197+ nmStateCh <- disconnectedGlobal
198 // pending wakeup was cleared
199 c.Check(<-s.myd.watchWakeCh, Equals, false)
200

Subscribers

People subscribed via source and target branches