~ps-jenkins/ubuntu-push/ubuntu-vivid-proposed

« back to all changes in this revision

Viewing changes to server/listener/listener_test.go

  • Committer: Roberto Alsina
  • Date: 2014-10-24 14:05:51 UTC
  • mfrom: (91.179.41 automatic)
  • mto: This revision was merged to the branch mainline in revision 136.
  • Revision ID: roberto.alsina@canonical.com-20141024140551-tsdz3xggo2rbwlqj
MergeĀ fromĀ automatic

Show diffs side-by-side

added added

removed removed

Lines of Context:
142
142
        c.Check(buf[0], Equals, byte(expected))
143
143
}
144
144
 
 
145
type testSessionResourceManager struct {
 
146
        event chan string
 
147
}
 
148
 
 
149
func (r *testSessionResourceManager) ConsumeConn() {
 
150
        r.event <- "consume"
 
151
}
 
152
 
 
153
// takeNext takes a string from given channel with a 5s timeout
 
154
func takeNext(ch <-chan string) string {
 
155
        select {
 
156
        case <-time.After(5 * time.Second):
 
157
                panic("test protocol exchange stuck: too long waiting")
 
158
        case v := <-ch:
 
159
                return v
 
160
        }
 
161
}
 
162
 
145
163
func (s *listenerSuite) TestDeviceAcceptLoop(c *C) {
146
164
        lst, err := DeviceListen(nil, &testDevListenerCfg{"127.0.0.1:0"})
147
165
        c.Check(err, IsNil)
148
166
        defer lst.Close()
149
167
        errCh := make(chan error)
 
168
        rEvent := make(chan string)
 
169
        resource := &testSessionResourceManager{rEvent}
150
170
        go func() {
151
 
                errCh <- lst.AcceptLoop(testSession, s.testlog)
 
171
                errCh <- lst.AcceptLoop(testSession, resource, s.testlog)
152
172
        }()
153
173
        listenerAddr := lst.Addr().String()
 
174
        c.Check(takeNext(rEvent), Equals, "consume")
154
175
        conn1, err := testTlsDial(listenerAddr)
155
176
        c.Assert(err, IsNil)
 
177
        c.Check(takeNext(rEvent), Equals, "consume")
156
178
        defer conn1.Close()
157
179
        testWriteByte(c, conn1, '1')
158
180
        conn2, err := testTlsDial(listenerAddr)
159
181
        c.Assert(err, IsNil)
 
182
        c.Check(takeNext(rEvent), Equals, "consume")
160
183
        defer conn2.Close()
161
184
        testWriteByte(c, conn2, '2')
162
185
        testReadByte(c, conn1, '1')
186
209
        c.Check(err, IsNil)
187
210
        defer lst.Close()
188
211
        errCh := make(chan error)
 
212
        resource := &NopSessionResourceManager{}
189
213
        go func() {
190
 
                errCh <- lst.AcceptLoop(testSession, s.testlog)
 
214
                errCh <- lst.AcceptLoop(testSession, resource, s.testlog)
191
215
        }()
192
216
        listenerAddr := lst.Addr().String()
193
217
        connectMany := helpers.ScriptAbsPath("connect-many.py")
210
234
        c.Check(err, IsNil)
211
235
        defer lst.Close()
212
236
        errCh := make(chan error)
 
237
        resource := &NopSessionResourceManager{}
213
238
        go func() {
214
239
                errCh <- lst.AcceptLoop(func(conn net.Conn) error {
215
240
                        defer conn.Close()
216
241
                        panic("session crash")
217
 
                }, s.testlog)
 
242
                }, resource, s.testlog)
218
243
        }()
219
244
        listenerAddr := lst.Addr().String()
220
245
        _, err = testTlsDial(listenerAddr)
231
256
        c.Check(err, IsNil)
232
257
        defer lst.Close()
233
258
        errCh := make(chan error)
 
259
        resource := &NopSessionResourceManager{}
234
260
        go func() {
235
 
                errCh <- lst.AcceptLoop(testSession, s.testlog)
 
261
                errCh <- lst.AcceptLoop(testSession, resource, s.testlog)
236
262
        }()
237
263
        listenerAddr := lst.Addr().String()
238
264
        c.Check(listenerAddr, Equals, foreignLst.Addr().String())