##// END OF EJS Templates
tests: add all missing b prefixes in reactor tests...
Augie Fackler -
r37700:cb71e0f9 default
parent child Browse files
Show More
@@ -1,441 +1,443 b''
1 1 test-abort-checkin.t
2 2 test-add.t
3 3 test-addremove-similar.t
4 4 test-addremove.t
5 5 test-amend-subrepo.t
6 6 test-amend.t
7 7 test-ancestor.py
8 8 test-annotate.py
9 9 test-annotate.t
10 10 test-archive-symlinks.t
11 11 test-atomictempfile.py
12 12 test-audit-path.t
13 13 test-audit-subrepo.t
14 14 test-automv.t
15 15 test-backout.t
16 16 test-backwards-remove.t
17 17 test-basic.t
18 18 test-bheads.t
19 19 test-bisect.t
20 20 test-bisect2.t
21 21 test-bisect3.t
22 22 test-blackbox.t
23 23 test-bookmarks-current.t
24 24 test-bookmarks-merge.t
25 25 test-bookmarks-rebase.t
26 26 test-bookmarks-strip.t
27 27 test-bookmarks.t
28 28 test-branch-change.t
29 29 test-branch-option.t
30 30 test-branch-tag-confict.t
31 31 test-branches.t
32 32 test-bundle-phases.t
33 33 test-bundle-type.t
34 34 test-bundle-vs-outgoing.t
35 35 test-bundle2-multiple-changegroups.t
36 36 test-cappedreader.py
37 37 test-casecollision.t
38 38 test-cat.t
39 39 test-censor.t
40 40 test-changelog-exec.t
41 41 test-check-commit.t
42 42 test-check-execute.t
43 43 test-check-module-imports.t
44 44 test-check-pyflakes.t
45 45 test-check-pylint.t
46 46 test-check-shbang.t
47 47 test-children.t
48 48 test-clone-pull-corruption.t
49 49 test-clone-r.t
50 50 test-clone-update-order.t
51 51 test-command-template.t
52 52 test-commit-amend.t
53 53 test-commit-interactive.t
54 54 test-commit-multiple.t
55 55 test-commit-unresolved.t
56 56 test-commit.t
57 57 test-committer.t
58 58 test-completion.t
59 59 test-config-env.py
60 60 test-config.t
61 61 test-conflict.t
62 62 test-confused-revert.t
63 63 test-contrib-check-code.t
64 64 test-contrib-check-commit.t
65 65 test-convert-authormap.t
66 66 test-convert-clonebranches.t
67 67 test-convert-datesort.t
68 68 test-convert-filemap.t
69 69 test-convert-hg-sink.t
70 70 test-convert-hg-source.t
71 71 test-convert-hg-startrev.t
72 72 test-convert-splicemap.t
73 73 test-convert-tagsbranch-topology.t
74 74 test-copy-move-merge.t
75 75 test-copy.t
76 76 test-copytrace-heuristics.t
77 77 test-debugbuilddag.t
78 78 test-debugbundle.t
79 79 test-debugextensions.t
80 80 test-debugindexdot.t
81 81 test-debugrename.t
82 82 test-default-push.t
83 83 test-diff-binary-file.t
84 84 test-diff-change.t
85 85 test-diff-copy-depth.t
86 86 test-diff-hashes.t
87 87 test-diff-ignore-whitespace.t
88 88 test-diff-indent-heuristic.t
89 89 test-diff-issue2761.t
90 90 test-diff-newlines.t
91 91 test-diff-reverse.t
92 92 test-diff-subdir.t
93 93 test-diff-unified.t
94 94 test-diff-upgrade.t
95 95 test-diffdir.t
96 96 test-diffstat.t
97 97 test-directaccess.t
98 98 test-dirstate-backup.t
99 99 test-dirstate-nonnormalset.t
100 100 test-dirstate.t
101 101 test-doctest.py
102 102 test-double-merge.t
103 103 test-drawdag.t
104 104 test-duplicateoptions.py
105 105 test-editor-filename.t
106 106 test-empty-dir.t
107 107 test-empty-file.t
108 108 test-empty-group.t
109 109 test-empty.t
110 110 test-encode.t
111 111 test-encoding-func.py
112 112 test-encoding.t
113 113 test-eol-add.t
114 114 test-eol-clone.t
115 115 test-eol-hook.t
116 116 test-eol-tag.t
117 117 test-eol-update.t
118 118 test-excessive-merge.t
119 119 test-exchange-obsmarkers-case-A1.t
120 120 test-exchange-obsmarkers-case-A2.t
121 121 test-exchange-obsmarkers-case-A3.t
122 122 test-exchange-obsmarkers-case-A4.t
123 123 test-exchange-obsmarkers-case-A5.t
124 124 test-exchange-obsmarkers-case-A6.t
125 125 test-exchange-obsmarkers-case-A7.t
126 126 test-exchange-obsmarkers-case-B1.t
127 127 test-exchange-obsmarkers-case-B2.t
128 128 test-exchange-obsmarkers-case-B3.t
129 129 test-exchange-obsmarkers-case-B4.t
130 130 test-exchange-obsmarkers-case-B5.t
131 131 test-exchange-obsmarkers-case-B6.t
132 132 test-exchange-obsmarkers-case-B7.t
133 133 test-exchange-obsmarkers-case-C1.t
134 134 test-exchange-obsmarkers-case-C2.t
135 135 test-exchange-obsmarkers-case-C3.t
136 136 test-exchange-obsmarkers-case-C4.t
137 137 test-exchange-obsmarkers-case-D1.t
138 138 test-exchange-obsmarkers-case-D2.t
139 139 test-exchange-obsmarkers-case-D3.t
140 140 test-exchange-obsmarkers-case-D4.t
141 141 test-execute-bit.t
142 142 test-export.t
143 143 test-extdiff.t
144 144 test-extra-filelog-entry.t
145 145 test-filebranch.t
146 146 test-fileset-generated.t
147 147 test-flags.t
148 148 test-generaldelta.t
149 149 test-getbundle.t
150 150 test-git-export.t
151 151 test-glog-topological.t
152 152 test-gpg.t
153 153 test-graft.t
154 154 test-hghave.t
155 155 test-hgignore.t
156 156 test-hgk.t
157 157 test-hgweb-bundle.t
158 158 test-hgweb-descend-empties.t
159 159 test-hgweb-empty.t
160 160 test-hgweb-removed.t
161 161 test-histedit-arguments.t
162 162 test-histedit-base.t
163 163 test-histedit-bookmark-motion.t
164 164 test-histedit-commute.t
165 165 test-histedit-drop.t
166 166 test-histedit-edit.t
167 167 test-histedit-fold-non-commute.t
168 168 test-histedit-fold.t
169 169 test-histedit-no-change.t
170 170 test-histedit-non-commute-abort.t
171 171 test-histedit-non-commute.t
172 172 test-histedit-obsolete.t
173 173 test-histedit-outgoing.t
174 174 test-histedit-templates.t
175 175 test-http-branchmap.t
176 176 test-http-bundle1.t
177 177 test-http-clone-r.t
178 178 test-identify.t
179 179 test-import-unknown.t
180 180 test-import.t
181 181 test-imports-checker.t
182 182 test-incoming-outgoing.t
183 183 test-inherit-mode.t
184 184 test-issue1089.t
185 185 test-issue1102.t
186 186 test-issue1175.t
187 187 test-issue1306.t
188 188 test-issue1438.t
189 189 test-issue1502.t
190 190 test-issue1802.t
191 191 test-issue1877.t
192 192 test-issue1993.t
193 193 test-issue2137.t
194 194 test-issue3084.t
195 195 test-issue4074.t
196 196 test-issue522.t
197 197 test-issue586.t
198 198 test-issue612.t
199 199 test-issue619.t
200 200 test-issue660.t
201 201 test-issue672.t
202 202 test-issue842.t
203 203 test-journal-exists.t
204 204 test-journal-share.t
205 205 test-journal.t
206 206 test-largefiles-cache.t
207 207 test-largefiles-misc.t
208 208 test-largefiles-small-disk.t
209 209 test-largefiles-update.t
210 210 test-lfs-largefiles.t
211 211 test-linerange.py
212 212 test-locate.t
213 213 test-lock-badness.t
214 214 test-log-linerange.t
215 215 test-log.t
216 216 test-logexchange.t
217 217 test-lrucachedict.py
218 218 test-mactext.t
219 219 test-mailmap.t
220 220 test-manifest-merging.t
221 221 test-manifest.py
222 222 test-manifest.t
223 223 test-match.py
224 224 test-mdiff.py
225 225 test-merge-changedelete.t
226 226 test-merge-closedheads.t
227 227 test-merge-commit.t
228 228 test-merge-criss-cross.t
229 229 test-merge-default.t
230 230 test-merge-force.t
231 231 test-merge-halt.t
232 232 test-merge-internal-tools-pattern.t
233 233 test-merge-local.t
234 234 test-merge-remove.t
235 235 test-merge-revert.t
236 236 test-merge-revert2.t
237 237 test-merge-subrepos.t
238 238 test-merge-symlinks.t
239 239 test-merge-tools.t
240 240 test-merge-types.t
241 241 test-merge1.t
242 242 test-merge10.t
243 243 test-merge2.t
244 244 test-merge4.t
245 245 test-merge5.t
246 246 test-merge6.t
247 247 test-merge7.t
248 248 test-merge8.t
249 249 test-merge9.t
250 250 test-mq-git.t
251 251 test-mq-header-date.t
252 252 test-mq-header-from.t
253 253 test-mq-merge.t
254 254 test-mq-pull-from-bundle.t
255 255 test-mq-qdelete.t
256 256 test-mq-qdiff.t
257 257 test-mq-qfold.t
258 258 test-mq-qgoto.t
259 259 test-mq-qimport-fail-cleanup.t
260 260 test-mq-qnew.t
261 261 test-mq-qpush-exact.t
262 262 test-mq-qqueue.t
263 263 test-mq-qrefresh-interactive.t
264 264 test-mq-qrefresh-replace-log-message.t
265 265 test-mq-qrefresh.t
266 266 test-mq-qrename.t
267 267 test-mq-qsave.t
268 268 test-mq-safety.t
269 269 test-mq-subrepo.t
270 270 test-mq-symlinks.t
271 271 test-mv-cp-st-diff.t
272 272 test-narrow-archive.t
273 273 test-narrow-clone-no-ellipsis.t
274 274 test-narrow-clone-non-narrow-server.t
275 275 test-narrow-clone-nonlinear.t
276 276 test-narrow-clone.t
277 277 test-narrow-commit.t
278 278 test-narrow-copies.t
279 279 test-narrow-debugcommands.t
280 280 test-narrow-debugrebuilddirstate.t
281 281 test-narrow-exchange-merges.t
282 282 test-narrow-exchange.t
283 283 test-narrow-expanddirstate.t
284 284 test-narrow-merge.t
285 285 test-narrow-patch.t
286 286 test-narrow-patterns.t
287 287 test-narrow-pull.t
288 288 test-narrow-rebase.t
289 289 test-narrow-shallow-merges.t
290 290 test-narrow-shallow.t
291 291 test-narrow-strip.t
292 292 test-narrow-update.t
293 293 test-nested-repo.t
294 294 test-newbranch.t
295 295 test-obshistory.t
296 296 test-obsmarker-template.t
297 297 test-obsmarkers-effectflag.t
298 298 test-obsolete-bundle-strip.t
299 299 test-obsolete-changeset-exchange.t
300 300 test-obsolete-checkheads.t
301 301 test-obsolete-distributed.t
302 302 test-obsolete-tag-cache.t
303 303 test-parents.t
304 304 test-pathconflicts-merge.t
305 305 test-pathconflicts-update.t
306 306 test-pending.t
307 307 test-permissions.t
308 308 test-phases.t
309 309 test-pull-branch.t
310 310 test-pull-http.t
311 311 test-pull-permission.t
312 312 test-pull-pull-corruption.t
313 313 test-pull-r.t
314 314 test-pull-update.t
315 315 test-purge.t
316 316 test-push-checkheads-partial-C1.t
317 317 test-push-checkheads-partial-C2.t
318 318 test-push-checkheads-partial-C3.t
319 319 test-push-checkheads-partial-C4.t
320 320 test-push-checkheads-pruned-B1.t
321 321 test-push-checkheads-pruned-B2.t
322 322 test-push-checkheads-pruned-B3.t
323 323 test-push-checkheads-pruned-B4.t
324 324 test-push-checkheads-pruned-B5.t
325 325 test-push-checkheads-pruned-B6.t
326 326 test-push-checkheads-pruned-B7.t
327 327 test-push-checkheads-pruned-B8.t
328 328 test-push-checkheads-superceed-A1.t
329 329 test-push-checkheads-superceed-A2.t
330 330 test-push-checkheads-superceed-A3.t
331 331 test-push-checkheads-superceed-A4.t
332 332 test-push-checkheads-superceed-A5.t
333 333 test-push-checkheads-superceed-A6.t
334 334 test-push-checkheads-superceed-A7.t
335 335 test-push-checkheads-superceed-A8.t
336 336 test-push-checkheads-unpushed-D1.t
337 337 test-push-checkheads-unpushed-D2.t
338 338 test-push-checkheads-unpushed-D3.t
339 339 test-push-checkheads-unpushed-D4.t
340 340 test-push-checkheads-unpushed-D5.t
341 341 test-push-checkheads-unpushed-D6.t
342 342 test-push-checkheads-unpushed-D7.t
343 343 test-push-http.t
344 344 test-push-warn.t
345 345 test-pushvars.t
346 346 test-rebase-abort.t
347 347 test-rebase-base-flag.t
348 348 test-rebase-bookmarks.t
349 349 test-rebase-brute-force.t
350 350 test-rebase-cache.t
351 351 test-rebase-check-restore.t
352 352 test-rebase-collapse.t
353 353 test-rebase-conflicts.t
354 354 test-rebase-dest.t
355 355 test-rebase-detach.t
356 356 test-rebase-emptycommit.t
357 357 test-rebase-inmemory.t
358 358 test-rebase-interruptions.t
359 359 test-rebase-issue-noparam-single-rev.t
360 360 test-rebase-legacy.t
361 361 test-rebase-mq-skip.t
362 362 test-rebase-mq.t
363 363 test-rebase-named-branches.t
364 364 test-rebase-newancestor.t
365 365 test-rebase-obsolete.t
366 366 test-rebase-parameters.t
367 367 test-rebase-partial.t
368 368 test-rebase-pull.t
369 369 test-rebase-rename.t
370 370 test-rebase-scenario-global.t
371 371 test-rebase-templates.t
372 372 test-rebase-transaction.t
373 373 test-record.t
374 374 test-relink.t
375 375 test-remove.t
376 376 test-rename-after-merge.t
377 377 test-rename-dir-merge.t
378 378 test-rename-merge1.t
379 379 test-rename.t
380 380 test-repair-strip.t
381 381 test-repo-compengines.t
382 382 test-resolve.t
383 383 test-revert-flags.t
384 384 test-revert-unknown.t
385 385 test-revlog-ancestry.py
386 386 test-revlog-group-emptyiter.t
387 387 test-revlog-mmapindex.t
388 388 test-revlog-packentry.t
389 389 test-revset-dirstate-parents.t
390 390 test-revset-outgoing.t
391 391 test-rollback.t
392 392 test-run-tests.py
393 393 test-schemes.t
394 394 test-serve.t
395 395 test-setdiscovery.t
396 396 test-share.t
397 397 test-show-stack.t
398 398 test-show-work.t
399 399 test-show.t
400 400 test-simple-update.t
401 401 test-single-head.t
402 402 test-sparse-clear.t
403 403 test-sparse-import.t
404 404 test-sparse-merges.t
405 405 test-sparse-profiles.t
406 406 test-sparse-requirement.t
407 407 test-sparse-verbose-json.t
408 408 test-ssh-clone-r.t
409 409 test-ssh-proto.t
410 410 test-sshserver.py
411 411 test-stack.t
412 412 test-status-rev.t
413 413 test-status-terse.t
414 414 test-strip-cross.t
415 415 test-strip.t
416 416 test-subrepo-deep-nested-change.t
417 417 test-subrepo-missing.t
418 418 test-subrepo.t
419 419 test-symlinks.t
420 420 test-tag.t
421 421 test-tags.t
422 422 test-template-engine.t
423 423 test-treemanifest.t
424 424 test-unamend.t
425 425 test-uncommit.t
426 426 test-unified-test.t
427 427 test-unrelated-pull.t
428 428 test-up-local-change.t
429 429 test-update-branches.t
430 430 test-update-dest.t
431 431 test-update-issue1456.t
432 432 test-update-names.t
433 433 test-update-reverse.t
434 434 test-upgrade-repo.t
435 435 test-url-rev.t
436 436 test-username-newline.t
437 437 test-verify.t
438 438 test-websub.t
439 439 test-win32text.t
440 test-wireproto-clientreactor.py
440 441 test-wireproto-framing.py
442 test-wireproto-serverreactor.py
441 443 test-xdg.t
@@ -1,130 +1,130 b''
1 1 from __future__ import absolute_import
2 2
3 3 import unittest
4 4
5 5 from mercurial import (
6 6 error,
7 7 wireprotoframing as framing,
8 8 )
9 9
10 10 ffs = framing.makeframefromhumanstring
11 11
12 12 def sendframe(reactor, frame):
13 13 """Send a frame bytearray to a reactor."""
14 14 header = framing.parseheader(frame)
15 15 payload = frame[framing.FRAME_HEADER_SIZE:]
16 16 assert len(payload) == header.length
17 17
18 18 return reactor.onframerecv(framing.frame(header.requestid,
19 19 header.streamid,
20 20 header.streamflags,
21 21 header.typeid,
22 22 header.flags,
23 23 payload))
24 24
25 25 class SingleSendTests(unittest.TestCase):
26 26 """A reactor that can only send once rejects subsequent sends."""
27 27 def testbasic(self):
28 28 reactor = framing.clientreactor(hasmultiplesend=False, buffersends=True)
29 29
30 30 request, action, meta = reactor.callcommand(b'foo', {})
31 self.assertEqual(request.state, 'pending')
32 self.assertEqual(action, 'noop')
31 self.assertEqual(request.state, b'pending')
32 self.assertEqual(action, b'noop')
33 33
34 34 action, meta = reactor.flushcommands()
35 self.assertEqual(action, 'sendframes')
35 self.assertEqual(action, b'sendframes')
36 36
37 for frame in meta['framegen']:
38 self.assertEqual(request.state, 'sending')
37 for frame in meta[b'framegen']:
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 42 with self.assertRaisesRegexp(error.ProgrammingError,
43 43 'cannot issue new commands'):
44 44 reactor.callcommand(b'foo', {})
45 45
46 46 with self.assertRaisesRegexp(error.ProgrammingError,
47 47 'cannot issue new commands'):
48 48 reactor.callcommand(b'foo', {})
49 49
50 50 class NoBufferTests(unittest.TestCase):
51 51 """A reactor without send buffering sends requests immediately."""
52 52 def testbasic(self):
53 53 reactor = framing.clientreactor(hasmultiplesend=True, buffersends=False)
54 54
55 55 request, action, meta = reactor.callcommand(b'command1', {})
56 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']:
62 self.assertEqual(request.state, 'sending')
61 for frame in meta[b'framegen']:
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 66 action, meta = reactor.flushcommands()
67 self.assertEqual(action, 'noop')
67 self.assertEqual(action, b'noop')
68 68
69 69 # And we can send another command.
70 70 request, action, meta = reactor.callcommand(b'command2', {})
71 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']:
75 self.assertEqual(request.state, 'sending')
74 for frame in meta[b'framegen']:
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 79 class BadFrameRecvTests(unittest.TestCase):
80 80 def testoddstream(self):
81 81 reactor = framing.clientreactor()
82 82
83 83 action, meta = sendframe(reactor, ffs(b'1 1 0 1 0 foo'))
84 self.assertEqual(action, 'error')
85 self.assertEqual(meta['message'],
86 'received frame with odd numbered stream ID: 1')
84 self.assertEqual(action, b'error')
85 self.assertEqual(meta[b'message'],
86 b'received frame with odd numbered stream ID: 1')
87 87
88 88 def testunknownstream(self):
89 89 reactor = framing.clientreactor()
90 90
91 91 action, meta = sendframe(reactor, ffs(b'1 0 0 1 0 foo'))
92 self.assertEqual(action, 'error')
93 self.assertEqual(meta['message'],
94 'received frame on unknown stream without beginning '
95 'of stream flag set')
92 self.assertEqual(action, b'error')
93 self.assertEqual(meta[b'message'],
94 b'received frame on unknown stream without beginning '
95 b'of stream flag set')
96 96
97 97 def testunhandledframetype(self):
98 98 reactor = framing.clientreactor(buffersends=False)
99 99
100 100 request, action, meta = reactor.callcommand(b'foo', {})
101 for frame in meta['framegen']:
101 for frame in meta[b'framegen']:
102 102 pass
103 103
104 104 with self.assertRaisesRegexp(error.ProgrammingError,
105 105 'unhandled frame type'):
106 106 sendframe(reactor, ffs(b'1 0 stream-begin text-output 0 foo'))
107 107
108 108 class StreamTests(unittest.TestCase):
109 109 def testmultipleresponseframes(self):
110 110 reactor = framing.clientreactor(buffersends=False)
111 111
112 112 request, action, meta = reactor.callcommand(b'foo', {})
113 113
114 self.assertEqual(action, 'sendframes')
115 for f in meta['framegen']:
114 self.assertEqual(action, b'sendframes')
115 for f in meta[b'framegen']:
116 116 pass
117 117
118 118 action, meta = sendframe(
119 119 reactor,
120 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 123 action, meta = sendframe(
124 124 reactor,
125 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 128 if __name__ == '__main__':
129 129 import silenttestrunner
130 130 silenttestrunner.main(__name__)
@@ -1,485 +1,485 b''
1 1 from __future__ import absolute_import, print_function
2 2
3 3 import unittest
4 4
5 5 from mercurial.thirdparty import (
6 6 cbor,
7 7 )
8 8 from mercurial import (
9 9 util,
10 10 wireprotoframing as framing,
11 11 )
12 12
13 13 ffs = framing.makeframefromhumanstring
14 14
15 15 def makereactor(deferoutput=False):
16 16 return framing.serverreactor(deferoutput=deferoutput)
17 17
18 18 def sendframes(reactor, gen):
19 19 """Send a generator of frame bytearray to a reactor.
20 20
21 21 Emits a generator of results from ``onframerecv()`` calls.
22 22 """
23 23 for frame in gen:
24 24 header = framing.parseheader(frame)
25 25 payload = frame[framing.FRAME_HEADER_SIZE:]
26 26 assert len(payload) == header.length
27 27
28 28 yield reactor.onframerecv(framing.frame(header.requestid,
29 29 header.streamid,
30 30 header.streamflags,
31 31 header.typeid,
32 32 header.flags,
33 33 payload))
34 34
35 35 def sendcommandframes(reactor, stream, rid, cmd, args, datafh=None):
36 36 """Generate frames to run a command and send them to a reactor."""
37 37 return sendframes(reactor,
38 38 framing.createcommandframes(stream, rid, cmd, args,
39 39 datafh))
40 40
41 41
42 42 class ServerReactorTests(unittest.TestCase):
43 43 def _sendsingleframe(self, reactor, f):
44 44 results = list(sendframes(reactor, [f]))
45 45 self.assertEqual(len(results), 1)
46 46
47 47 return results[0]
48 48
49 49 def assertaction(self, res, expected):
50 50 self.assertIsInstance(res, tuple)
51 51 self.assertEqual(len(res), 2)
52 52 self.assertIsInstance(res[1], dict)
53 53 self.assertEqual(res[0], expected)
54 54
55 55 def assertframesequal(self, frames, framestrings):
56 56 expected = [ffs(s) for s in framestrings]
57 57 self.assertEqual(list(frames), expected)
58 58
59 59 def test1framecommand(self):
60 60 """Receiving a command in a single frame yields request to run it."""
61 61 reactor = makereactor()
62 62 stream = framing.stream(1)
63 63 results = list(sendcommandframes(reactor, stream, 1, b'mycommand', {}))
64 64 self.assertEqual(len(results), 1)
65 self.assertaction(results[0], 'runcommand')
65 self.assertaction(results[0], b'runcommand')
66 66 self.assertEqual(results[0][1], {
67 'requestid': 1,
68 'command': b'mycommand',
69 'args': {},
70 'data': None,
67 b'requestid': 1,
68 b'command': b'mycommand',
69 b'args': {},
70 b'data': None,
71 71 })
72 72
73 73 result = reactor.oninputeof()
74 self.assertaction(result, 'noop')
74 self.assertaction(result, b'noop')
75 75
76 76 def test1argument(self):
77 77 reactor = makereactor()
78 78 stream = framing.stream(1)
79 79 results = list(sendcommandframes(reactor, stream, 41, b'mycommand',
80 80 {b'foo': b'bar'}))
81 81 self.assertEqual(len(results), 1)
82 self.assertaction(results[0], 'runcommand')
82 self.assertaction(results[0], b'runcommand')
83 83 self.assertEqual(results[0][1], {
84 'requestid': 41,
85 'command': b'mycommand',
86 'args': {b'foo': b'bar'},
87 'data': None,
84 b'requestid': 41,
85 b'command': b'mycommand',
86 b'args': {b'foo': b'bar'},
87 b'data': None,
88 88 })
89 89
90 90 def testmultiarguments(self):
91 91 reactor = makereactor()
92 92 stream = framing.stream(1)
93 93 results = list(sendcommandframes(reactor, stream, 1, b'mycommand',
94 94 {b'foo': b'bar', b'biz': b'baz'}))
95 95 self.assertEqual(len(results), 1)
96 self.assertaction(results[0], 'runcommand')
96 self.assertaction(results[0], b'runcommand')
97 97 self.assertEqual(results[0][1], {
98 'requestid': 1,
99 'command': b'mycommand',
100 'args': {b'foo': b'bar', b'biz': b'baz'},
101 'data': None,
98 b'requestid': 1,
99 b'command': b'mycommand',
100 b'args': {b'foo': b'bar', b'biz': b'baz'},
101 b'data': None,
102 102 })
103 103
104 104 def testsimplecommanddata(self):
105 105 reactor = makereactor()
106 106 stream = framing.stream(1)
107 107 results = list(sendcommandframes(reactor, stream, 1, b'mycommand', {},
108 108 util.bytesio(b'data!')))
109 109 self.assertEqual(len(results), 2)
110 self.assertaction(results[0], 'wantframe')
111 self.assertaction(results[1], 'runcommand')
110 self.assertaction(results[0], b'wantframe')
111 self.assertaction(results[1], b'runcommand')
112 112 self.assertEqual(results[1][1], {
113 'requestid': 1,
114 'command': b'mycommand',
115 'args': {},
116 'data': b'data!',
113 b'requestid': 1,
114 b'command': b'mycommand',
115 b'args': {},
116 b'data': b'data!',
117 117 })
118 118
119 119 def testmultipledataframes(self):
120 120 frames = [
121 121 ffs(b'1 1 stream-begin command-request new|have-data '
122 122 b"cbor:{b'name': b'mycommand'}"),
123 123 ffs(b'1 1 0 command-data continuation data1'),
124 124 ffs(b'1 1 0 command-data continuation data2'),
125 125 ffs(b'1 1 0 command-data eos data3'),
126 126 ]
127 127
128 128 reactor = makereactor()
129 129 results = list(sendframes(reactor, frames))
130 130 self.assertEqual(len(results), 4)
131 131 for i in range(3):
132 self.assertaction(results[i], 'wantframe')
133 self.assertaction(results[3], 'runcommand')
132 self.assertaction(results[i], b'wantframe')
133 self.assertaction(results[3], b'runcommand')
134 134 self.assertEqual(results[3][1], {
135 'requestid': 1,
136 'command': b'mycommand',
137 'args': {},
138 'data': b'data1data2data3',
135 b'requestid': 1,
136 b'command': b'mycommand',
137 b'args': {},
138 b'data': b'data1data2data3',
139 139 })
140 140
141 141 def testargumentanddata(self):
142 142 frames = [
143 143 ffs(b'1 1 stream-begin command-request new|have-data '
144 144 b"cbor:{b'name': b'command', b'args': {b'key': b'val',"
145 145 b"b'foo': b'bar'}}"),
146 146 ffs(b'1 1 0 command-data continuation value1'),
147 147 ffs(b'1 1 0 command-data eos value2'),
148 148 ]
149 149
150 150 reactor = makereactor()
151 151 results = list(sendframes(reactor, frames))
152 152
153 self.assertaction(results[-1], 'runcommand')
153 self.assertaction(results[-1], b'runcommand')
154 154 self.assertEqual(results[-1][1], {
155 'requestid': 1,
156 'command': b'command',
157 'args': {
155 b'requestid': 1,
156 b'command': b'command',
157 b'args': {
158 158 b'key': b'val',
159 159 b'foo': b'bar',
160 160 },
161 'data': b'value1value2',
161 b'data': b'value1value2',
162 162 })
163 163
164 164 def testnewandcontinuation(self):
165 165 result = self._sendsingleframe(makereactor(),
166 166 ffs(b'1 1 stream-begin command-request new|continuation '))
167 self.assertaction(result, 'error')
167 self.assertaction(result, b'error')
168 168 self.assertEqual(result[1], {
169 'message': b'received command request frame with both new and '
169 b'message': b'received command request frame with both new and '
170 170 b'continuation flags set',
171 171 })
172 172
173 173 def testneithernewnorcontinuation(self):
174 174 result = self._sendsingleframe(makereactor(),
175 175 ffs(b'1 1 stream-begin command-request 0 '))
176 self.assertaction(result, 'error')
176 self.assertaction(result, b'error')
177 177 self.assertEqual(result[1], {
178 'message': b'received command request frame with neither new nor '
178 b'message': b'received command request frame with neither new nor '
179 179 b'continuation flags set',
180 180 })
181 181
182 182 def testunexpectedcommanddata(self):
183 183 """Command data frame when not running a command is an error."""
184 184 result = self._sendsingleframe(makereactor(),
185 185 ffs(b'1 1 stream-begin command-data 0 ignored'))
186 self.assertaction(result, 'error')
186 self.assertaction(result, b'error')
187 187 self.assertEqual(result[1], {
188 'message': b'expected command request frame; got 3',
188 b'message': b'expected command request frame; got 3',
189 189 })
190 190
191 191 def testunexpectedcommanddatareceiving(self):
192 192 """Same as above except the command is receiving."""
193 193 results = list(sendframes(makereactor(), [
194 194 ffs(b'1 1 stream-begin command-request new|more '
195 195 b"cbor:{b'name': b'ignored'}"),
196 196 ffs(b'1 1 0 command-data eos ignored'),
197 197 ]))
198 198
199 self.assertaction(results[0], 'wantframe')
200 self.assertaction(results[1], 'error')
199 self.assertaction(results[0], b'wantframe')
200 self.assertaction(results[1], b'error')
201 201 self.assertEqual(results[1][1], {
202 'message': b'received command data frame for request that is not '
202 b'message': b'received command data frame for request that is not '
203 203 b'expecting data: 1',
204 204 })
205 205
206 206 def testconflictingrequestidallowed(self):
207 207 """Multiple fully serviced commands with same request ID is allowed."""
208 208 reactor = makereactor()
209 209 results = []
210 210 outstream = reactor.makeoutputstream()
211 211 results.append(self._sendsingleframe(
212 212 reactor, ffs(b'1 1 stream-begin command-request new '
213 213 b"cbor:{b'name': b'command'}")))
214 214 result = reactor.onbytesresponseready(outstream, 1, b'response1')
215 self.assertaction(result, 'sendframes')
216 list(result[1]['framegen'])
215 self.assertaction(result, b'sendframes')
216 list(result[1][b'framegen'])
217 217 results.append(self._sendsingleframe(
218 218 reactor, ffs(b'1 1 stream-begin command-request new '
219 219 b"cbor:{b'name': b'command'}")))
220 220 result = reactor.onbytesresponseready(outstream, 1, b'response2')
221 self.assertaction(result, 'sendframes')
222 list(result[1]['framegen'])
221 self.assertaction(result, b'sendframes')
222 list(result[1][b'framegen'])
223 223 results.append(self._sendsingleframe(
224 224 reactor, ffs(b'1 1 stream-begin command-request new '
225 225 b"cbor:{b'name': b'command'}")))
226 226 result = reactor.onbytesresponseready(outstream, 1, b'response3')
227 self.assertaction(result, 'sendframes')
228 list(result[1]['framegen'])
227 self.assertaction(result, b'sendframes')
228 list(result[1][b'framegen'])
229 229
230 230 for i in range(3):
231 self.assertaction(results[i], 'runcommand')
231 self.assertaction(results[i], b'runcommand')
232 232 self.assertEqual(results[i][1], {
233 'requestid': 1,
234 'command': b'command',
235 'args': {},
236 'data': None,
233 b'requestid': 1,
234 b'command': b'command',
235 b'args': {},
236 b'data': None,
237 237 })
238 238
239 239 def testconflictingrequestid(self):
240 240 """Request ID for new command matching in-flight command is illegal."""
241 241 results = list(sendframes(makereactor(), [
242 242 ffs(b'1 1 stream-begin command-request new|more '
243 243 b"cbor:{b'name': b'command'}"),
244 244 ffs(b'1 1 0 command-request new '
245 245 b"cbor:{b'name': b'command1'}"),
246 246 ]))
247 247
248 self.assertaction(results[0], 'wantframe')
249 self.assertaction(results[1], 'error')
248 self.assertaction(results[0], b'wantframe')
249 self.assertaction(results[1], b'error')
250 250 self.assertEqual(results[1][1], {
251 'message': b'request with ID 1 already received',
251 b'message': b'request with ID 1 already received',
252 252 })
253 253
254 254 def testinterleavedcommands(self):
255 255 cbor1 = cbor.dumps({
256 256 b'name': b'command1',
257 257 b'args': {
258 258 b'foo': b'bar',
259 259 b'key1': b'val',
260 260 }
261 261 }, canonical=True)
262 262 cbor3 = cbor.dumps({
263 263 b'name': b'command3',
264 264 b'args': {
265 265 b'biz': b'baz',
266 266 b'key': b'val',
267 267 },
268 268 }, canonical=True)
269 269
270 270 results = list(sendframes(makereactor(), [
271 271 ffs(b'1 1 stream-begin command-request new|more %s' % cbor1[0:6]),
272 272 ffs(b'3 1 0 command-request new|more %s' % cbor3[0:10]),
273 273 ffs(b'1 1 0 command-request continuation|more %s' % cbor1[6:9]),
274 274 ffs(b'3 1 0 command-request continuation|more %s' % cbor3[10:13]),
275 275 ffs(b'3 1 0 command-request continuation %s' % cbor3[13:]),
276 276 ffs(b'1 1 0 command-request continuation %s' % cbor1[9:]),
277 277 ]))
278 278
279 279 self.assertEqual([t[0] for t in results], [
280 'wantframe',
281 'wantframe',
282 'wantframe',
283 'wantframe',
284 'runcommand',
285 'runcommand',
280 b'wantframe',
281 b'wantframe',
282 b'wantframe',
283 b'wantframe',
284 b'runcommand',
285 b'runcommand',
286 286 ])
287 287
288 288 self.assertEqual(results[4][1], {
289 'requestid': 3,
290 'command': 'command3',
291 'args': {b'biz': b'baz', b'key': b'val'},
292 'data': None,
289 b'requestid': 3,
290 b'command': b'command3',
291 b'args': {b'biz': b'baz', b'key': b'val'},
292 b'data': None,
293 293 })
294 294 self.assertEqual(results[5][1], {
295 'requestid': 1,
296 'command': 'command1',
297 'args': {b'foo': b'bar', b'key1': b'val'},
298 'data': None,
295 b'requestid': 1,
296 b'command': b'command1',
297 b'args': {b'foo': b'bar', b'key1': b'val'},
298 b'data': None,
299 299 })
300 300
301 301 def testmissingcommanddataframe(self):
302 302 # The reactor doesn't currently handle partially received commands.
303 303 # So this test is failing to do anything with request 1.
304 304 frames = [
305 305 ffs(b'1 1 stream-begin command-request new|have-data '
306 306 b"cbor:{b'name': b'command1'}"),
307 307 ffs(b'3 1 0 command-request new '
308 308 b"cbor:{b'name': b'command2'}"),
309 309 ]
310 310 results = list(sendframes(makereactor(), frames))
311 311 self.assertEqual(len(results), 2)
312 self.assertaction(results[0], 'wantframe')
313 self.assertaction(results[1], 'runcommand')
312 self.assertaction(results[0], b'wantframe')
313 self.assertaction(results[1], b'runcommand')
314 314
315 315 def testmissingcommanddataframeflags(self):
316 316 frames = [
317 317 ffs(b'1 1 stream-begin command-request new|have-data '
318 318 b"cbor:{b'name': b'command1'}"),
319 319 ffs(b'1 1 0 command-data 0 data'),
320 320 ]
321 321 results = list(sendframes(makereactor(), frames))
322 322 self.assertEqual(len(results), 2)
323 self.assertaction(results[0], 'wantframe')
324 self.assertaction(results[1], 'error')
323 self.assertaction(results[0], b'wantframe')
324 self.assertaction(results[1], b'error')
325 325 self.assertEqual(results[1][1], {
326 'message': b'command data frame without flags',
326 b'message': b'command data frame without flags',
327 327 })
328 328
329 329 def testframefornonreceivingrequest(self):
330 330 """Receiving a frame for a command that is not receiving is illegal."""
331 331 results = list(sendframes(makereactor(), [
332 332 ffs(b'1 1 stream-begin command-request new '
333 333 b"cbor:{b'name': b'command1'}"),
334 334 ffs(b'3 1 0 command-request new|have-data '
335 335 b"cbor:{b'name': b'command3'}"),
336 336 ffs(b'5 1 0 command-data eos ignored'),
337 337 ]))
338 self.assertaction(results[2], 'error')
338 self.assertaction(results[2], b'error')
339 339 self.assertEqual(results[2][1], {
340 'message': b'received frame for request that is not receiving: 5',
340 b'message': b'received frame for request that is not receiving: 5',
341 341 })
342 342
343 343 def testsimpleresponse(self):
344 344 """Bytes response to command sends result frames."""
345 345 reactor = makereactor()
346 346 instream = framing.stream(1)
347 347 list(sendcommandframes(reactor, instream, 1, b'mycommand', {}))
348 348
349 349 outstream = reactor.makeoutputstream()
350 350 result = reactor.onbytesresponseready(outstream, 1, b'response')
351 self.assertaction(result, 'sendframes')
352 self.assertframesequal(result[1]['framegen'], [
351 self.assertaction(result, b'sendframes')
352 self.assertframesequal(result[1][b'framegen'], [
353 353 b'1 2 stream-begin bytes-response eos response',
354 354 ])
355 355
356 356 def testmultiframeresponse(self):
357 357 """Bytes response spanning multiple frames is handled."""
358 358 first = b'x' * framing.DEFAULT_MAX_FRAME_SIZE
359 359 second = b'y' * 100
360 360
361 361 reactor = makereactor()
362 362 instream = framing.stream(1)
363 363 list(sendcommandframes(reactor, instream, 1, b'mycommand', {}))
364 364
365 365 outstream = reactor.makeoutputstream()
366 366 result = reactor.onbytesresponseready(outstream, 1, first + second)
367 self.assertaction(result, 'sendframes')
368 self.assertframesequal(result[1]['framegen'], [
367 self.assertaction(result, b'sendframes')
368 self.assertframesequal(result[1][b'framegen'], [
369 369 b'1 2 stream-begin bytes-response continuation %s' % first,
370 370 b'1 2 0 bytes-response eos %s' % second,
371 371 ])
372 372
373 373 def testapplicationerror(self):
374 374 reactor = makereactor()
375 375 instream = framing.stream(1)
376 376 list(sendcommandframes(reactor, instream, 1, b'mycommand', {}))
377 377
378 378 outstream = reactor.makeoutputstream()
379 379 result = reactor.onapplicationerror(outstream, 1, b'some message')
380 self.assertaction(result, 'sendframes')
381 self.assertframesequal(result[1]['framegen'], [
380 self.assertaction(result, b'sendframes')
381 self.assertframesequal(result[1][b'framegen'], [
382 382 b'1 2 stream-begin error-response application some message',
383 383 ])
384 384
385 385 def test1commanddeferresponse(self):
386 386 """Responses when in deferred output mode are delayed until EOF."""
387 387 reactor = makereactor(deferoutput=True)
388 388 instream = framing.stream(1)
389 389 results = list(sendcommandframes(reactor, instream, 1, b'mycommand',
390 390 {}))
391 391 self.assertEqual(len(results), 1)
392 self.assertaction(results[0], 'runcommand')
392 self.assertaction(results[0], b'runcommand')
393 393
394 394 outstream = reactor.makeoutputstream()
395 395 result = reactor.onbytesresponseready(outstream, 1, b'response')
396 self.assertaction(result, 'noop')
396 self.assertaction(result, b'noop')
397 397 result = reactor.oninputeof()
398 self.assertaction(result, 'sendframes')
399 self.assertframesequal(result[1]['framegen'], [
398 self.assertaction(result, b'sendframes')
399 self.assertframesequal(result[1][b'framegen'], [
400 400 b'1 2 stream-begin bytes-response eos response',
401 401 ])
402 402
403 403 def testmultiplecommanddeferresponse(self):
404 404 reactor = makereactor(deferoutput=True)
405 405 instream = framing.stream(1)
406 406 list(sendcommandframes(reactor, instream, 1, b'command1', {}))
407 407 list(sendcommandframes(reactor, instream, 3, b'command2', {}))
408 408
409 409 outstream = reactor.makeoutputstream()
410 410 result = reactor.onbytesresponseready(outstream, 1, b'response1')
411 self.assertaction(result, 'noop')
411 self.assertaction(result, b'noop')
412 412 result = reactor.onbytesresponseready(outstream, 3, b'response2')
413 self.assertaction(result, 'noop')
413 self.assertaction(result, b'noop')
414 414 result = reactor.oninputeof()
415 self.assertaction(result, 'sendframes')
416 self.assertframesequal(result[1]['framegen'], [
415 self.assertaction(result, b'sendframes')
416 self.assertframesequal(result[1][b'framegen'], [
417 417 b'1 2 stream-begin bytes-response eos response1',
418 418 b'3 2 0 bytes-response eos response2'
419 419 ])
420 420
421 421 def testrequestidtracking(self):
422 422 reactor = makereactor(deferoutput=True)
423 423 instream = framing.stream(1)
424 424 list(sendcommandframes(reactor, instream, 1, b'command1', {}))
425 425 list(sendcommandframes(reactor, instream, 3, b'command2', {}))
426 426 list(sendcommandframes(reactor, instream, 5, b'command3', {}))
427 427
428 428 # Register results for commands out of order.
429 429 outstream = reactor.makeoutputstream()
430 430 reactor.onbytesresponseready(outstream, 3, b'response3')
431 431 reactor.onbytesresponseready(outstream, 1, b'response1')
432 432 reactor.onbytesresponseready(outstream, 5, b'response5')
433 433
434 434 result = reactor.oninputeof()
435 self.assertaction(result, 'sendframes')
436 self.assertframesequal(result[1]['framegen'], [
435 self.assertaction(result, b'sendframes')
436 self.assertframesequal(result[1][b'framegen'], [
437 437 b'3 2 stream-begin bytes-response eos response3',
438 438 b'1 2 0 bytes-response eos response1',
439 439 b'5 2 0 bytes-response eos response5',
440 440 ])
441 441
442 442 def testduplicaterequestonactivecommand(self):
443 443 """Receiving a request ID that matches a request that isn't finished."""
444 444 reactor = makereactor()
445 445 stream = framing.stream(1)
446 446 list(sendcommandframes(reactor, stream, 1, b'command1', {}))
447 447 results = list(sendcommandframes(reactor, stream, 1, b'command1', {}))
448 448
449 self.assertaction(results[0], 'error')
449 self.assertaction(results[0], b'error')
450 450 self.assertEqual(results[0][1], {
451 'message': b'request with ID 1 is already active',
451 b'message': b'request with ID 1 is already active',
452 452 })
453 453
454 454 def testduplicaterequestonactivecommandnosend(self):
455 455 """Same as above but we've registered a response but haven't sent it."""
456 456 reactor = makereactor()
457 457 instream = framing.stream(1)
458 458 list(sendcommandframes(reactor, instream, 1, b'command1', {}))
459 459 outstream = reactor.makeoutputstream()
460 460 reactor.onbytesresponseready(outstream, 1, b'response')
461 461
462 462 # We've registered the response but haven't sent it. From the
463 463 # perspective of the reactor, the command is still active.
464 464
465 465 results = list(sendcommandframes(reactor, instream, 1, b'command1', {}))
466 self.assertaction(results[0], 'error')
466 self.assertaction(results[0], b'error')
467 467 self.assertEqual(results[0][1], {
468 'message': b'request with ID 1 is already active',
468 b'message': b'request with ID 1 is already active',
469 469 })
470 470
471 471 def testduplicaterequestaftersend(self):
472 472 """We can use a duplicate request ID after we've sent the response."""
473 473 reactor = makereactor()
474 474 instream = framing.stream(1)
475 475 list(sendcommandframes(reactor, instream, 1, b'command1', {}))
476 476 outstream = reactor.makeoutputstream()
477 477 res = reactor.onbytesresponseready(outstream, 1, b'response')
478 list(res[1]['framegen'])
478 list(res[1][b'framegen'])
479 479
480 480 results = list(sendcommandframes(reactor, instream, 1, b'command1', {}))
481 self.assertaction(results[0], 'runcommand')
481 self.assertaction(results[0], b'runcommand')
482 482
483 483 if __name__ == '__main__':
484 484 import silenttestrunner
485 485 silenttestrunner.main(__name__)
General Comments 0
You need to be logged in to leave comments. Login now