26 """A reactor that can only send once rejects subsequent sends.""" |
26 """A reactor that can only send once rejects subsequent sends.""" |
27 def testbasic(self): |
27 def testbasic(self): |
28 reactor = framing.clientreactor(hasmultiplesend=False, buffersends=True) |
28 reactor = framing.clientreactor(hasmultiplesend=False, buffersends=True) |
29 |
29 |
30 request, action, meta = reactor.callcommand(b'foo', {}) |
30 request, action, meta = reactor.callcommand(b'foo', {}) |
31 self.assertEqual(request.state, 'pending') |
31 self.assertEqual(request.state, b'pending') |
32 self.assertEqual(action, 'noop') |
32 self.assertEqual(action, b'noop') |
33 |
33 |
34 action, meta = reactor.flushcommands() |
34 action, meta = reactor.flushcommands() |
35 self.assertEqual(action, 'sendframes') |
35 self.assertEqual(action, b'sendframes') |
36 |
36 |
37 for frame in meta['framegen']: |
37 for frame in meta[b'framegen']: |
38 self.assertEqual(request.state, 'sending') |
38 self.assertEqual(request.state, b'sending') |
39 |
39 |
40 self.assertEqual(request.state, 'sent') |
40 self.assertEqual(request.state, b'sent') |
41 |
41 |
42 with self.assertRaisesRegexp(error.ProgrammingError, |
42 with self.assertRaisesRegexp(error.ProgrammingError, |
43 'cannot issue new commands'): |
43 'cannot issue new commands'): |
44 reactor.callcommand(b'foo', {}) |
44 reactor.callcommand(b'foo', {}) |
45 |
45 |
52 def testbasic(self): |
52 def testbasic(self): |
53 reactor = framing.clientreactor(hasmultiplesend=True, buffersends=False) |
53 reactor = framing.clientreactor(hasmultiplesend=True, buffersends=False) |
54 |
54 |
55 request, action, meta = reactor.callcommand(b'command1', {}) |
55 request, action, meta = reactor.callcommand(b'command1', {}) |
56 self.assertEqual(request.requestid, 1) |
56 self.assertEqual(request.requestid, 1) |
57 self.assertEqual(action, 'sendframes') |
57 self.assertEqual(action, b'sendframes') |
58 |
58 |
59 self.assertEqual(request.state, 'pending') |
59 self.assertEqual(request.state, b'pending') |
60 |
60 |
61 for frame in meta['framegen']: |
61 for frame in meta[b'framegen']: |
62 self.assertEqual(request.state, 'sending') |
62 self.assertEqual(request.state, b'sending') |
63 |
63 |
64 self.assertEqual(request.state, 'sent') |
64 self.assertEqual(request.state, b'sent') |
65 |
65 |
66 action, meta = reactor.flushcommands() |
66 action, meta = reactor.flushcommands() |
67 self.assertEqual(action, 'noop') |
67 self.assertEqual(action, b'noop') |
68 |
68 |
69 # And we can send another command. |
69 # And we can send another command. |
70 request, action, meta = reactor.callcommand(b'command2', {}) |
70 request, action, meta = reactor.callcommand(b'command2', {}) |
71 self.assertEqual(request.requestid, 3) |
71 self.assertEqual(request.requestid, 3) |
72 self.assertEqual(action, 'sendframes') |
72 self.assertEqual(action, b'sendframes') |
73 |
73 |
74 for frame in meta['framegen']: |
74 for frame in meta[b'framegen']: |
75 self.assertEqual(request.state, 'sending') |
75 self.assertEqual(request.state, b'sending') |
76 |
76 |
77 self.assertEqual(request.state, 'sent') |
77 self.assertEqual(request.state, b'sent') |
78 |
78 |
79 class BadFrameRecvTests(unittest.TestCase): |
79 class BadFrameRecvTests(unittest.TestCase): |
80 def testoddstream(self): |
80 def testoddstream(self): |
81 reactor = framing.clientreactor() |
81 reactor = framing.clientreactor() |
82 |
82 |
83 action, meta = sendframe(reactor, ffs(b'1 1 0 1 0 foo')) |
83 action, meta = sendframe(reactor, ffs(b'1 1 0 1 0 foo')) |
84 self.assertEqual(action, 'error') |
84 self.assertEqual(action, b'error') |
85 self.assertEqual(meta['message'], |
85 self.assertEqual(meta[b'message'], |
86 'received frame with odd numbered stream ID: 1') |
86 b'received frame with odd numbered stream ID: 1') |
87 |
87 |
88 def testunknownstream(self): |
88 def testunknownstream(self): |
89 reactor = framing.clientreactor() |
89 reactor = framing.clientreactor() |
90 |
90 |
91 action, meta = sendframe(reactor, ffs(b'1 0 0 1 0 foo')) |
91 action, meta = sendframe(reactor, ffs(b'1 0 0 1 0 foo')) |
92 self.assertEqual(action, 'error') |
92 self.assertEqual(action, b'error') |
93 self.assertEqual(meta['message'], |
93 self.assertEqual(meta[b'message'], |
94 'received frame on unknown stream without beginning ' |
94 b'received frame on unknown stream without beginning ' |
95 'of stream flag set') |
95 b'of stream flag set') |
96 |
96 |
97 def testunhandledframetype(self): |
97 def testunhandledframetype(self): |
98 reactor = framing.clientreactor(buffersends=False) |
98 reactor = framing.clientreactor(buffersends=False) |
99 |
99 |
100 request, action, meta = reactor.callcommand(b'foo', {}) |
100 request, action, meta = reactor.callcommand(b'foo', {}) |
101 for frame in meta['framegen']: |
101 for frame in meta[b'framegen']: |
102 pass |
102 pass |
103 |
103 |
104 with self.assertRaisesRegexp(error.ProgrammingError, |
104 with self.assertRaisesRegexp(error.ProgrammingError, |
105 'unhandled frame type'): |
105 'unhandled frame type'): |
106 sendframe(reactor, ffs(b'1 0 stream-begin text-output 0 foo')) |
106 sendframe(reactor, ffs(b'1 0 stream-begin text-output 0 foo')) |
109 def testmultipleresponseframes(self): |
109 def testmultipleresponseframes(self): |
110 reactor = framing.clientreactor(buffersends=False) |
110 reactor = framing.clientreactor(buffersends=False) |
111 |
111 |
112 request, action, meta = reactor.callcommand(b'foo', {}) |
112 request, action, meta = reactor.callcommand(b'foo', {}) |
113 |
113 |
114 self.assertEqual(action, 'sendframes') |
114 self.assertEqual(action, b'sendframes') |
115 for f in meta['framegen']: |
115 for f in meta[b'framegen']: |
116 pass |
116 pass |
117 |
117 |
118 action, meta = sendframe( |
118 action, meta = sendframe( |
119 reactor, |
119 reactor, |
120 ffs(b'%d 0 stream-begin 4 0 foo' % request.requestid)) |
120 ffs(b'%d 0 stream-begin 4 0 foo' % request.requestid)) |
121 self.assertEqual(action, 'responsedata') |
121 self.assertEqual(action, b'responsedata') |
122 |
122 |
123 action, meta = sendframe( |
123 action, meta = sendframe( |
124 reactor, |
124 reactor, |
125 ffs(b'%d 0 0 4 eos bar' % request.requestid)) |
125 ffs(b'%d 0 0 4 eos bar' % request.requestid)) |
126 self.assertEqual(action, 'responsedata') |
126 self.assertEqual(action, b'responsedata') |
127 |
127 |
128 if __name__ == '__main__': |
128 if __name__ == '__main__': |
129 import silenttestrunner |
129 import silenttestrunner |
130 silenttestrunner.main(__name__) |
130 silenttestrunner.main(__name__) |