2
Copyright 2014 Canonical Ltd.
4
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 published
6
by the Free Software Foundation.
8
This program is distributed in the hope that it will be useful, but
9
WITHOUT ANY WARRANTY; without even the implied warranties of
10
MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11
PURPOSE. See the GNU General Public License for more details.
13
You should have received a copy of the GNU General Public License along
14
with this program. If not, see <http://www.gnu.org/licenses/>.
22
. "launchpad.net/gocheck"
24
"launchpad.net/ubuntu-push/client/session"
25
helpers "launchpad.net/ubuntu-push/testing"
29
func TestPoller(t *testing.T) { TestingT(t) }
32
log *helpers.TestLogger
36
var _ = Suite(&PrSuite{})
39
// in/out for RequestWakeup
45
watchWakeCh <-chan bool
52
clearLockCookie string
57
watchDonesCh <-chan bool
60
stateState session.ClientSessionState
63
func (m *myD) RequestWakeup(name string, wakeupTime time.Time) (string, error) {
65
m.reqWakeTime = wakeupTime
66
return m.reqWakeCookie, m.reqWakeErr
68
func (m *myD) RequestWakelock(name string) (string, error) {
70
return m.reqLockCookie, m.reqLockErr
72
func (m *myD) ClearWakelock(cookie string) error {
73
m.clearLockCookie = cookie
76
func (m *myD) ClearWakeup(cookie string) error { panic("clearwakeup called??") }
77
func (m *myD) WatchWakeups() (<-chan bool, error) { return m.watchWakeCh, m.watchWakeErr }
78
func (m *myD) Poll() error { return m.pollErr }
79
func (m *myD) WatchDones() (<-chan bool, error) { return m.watchDonesCh, m.watchDonesErr }
80
func (m *myD) State() session.ClientSessionState { return m.stateState }
82
func (s *PrSuite) SetUpTest(c *C) {
83
s.log = helpers.NewTestLogger(c, "debug")
87
func (s *PrSuite) TestStep(c *C) {
95
s.myd.reqLockCookie = "wakelock cookie"
96
s.myd.stateState = session.Running
97
// we'll get the wakeup right away
98
wakeupCh := make(chan bool, 1)
100
// we won't get the "done" signal in time ;)
101
doneCh := make(chan bool)
102
// and a channel to get the return value from a goroutine
103
ch := make(chan string)
105
go func() { ch <- p.step(wakeupCh, doneCh, "old cookie") }()
108
c.Check(s, Equals, "wakelock cookie")
109
case <-time.After(time.Second):
110
c.Fatal("timeout waiting for step")