Mercurial > hg
annotate tests/test-cappedreader.py @ 42415:c767e655ffda
narrow: use narrow_widen wireproto command to widen in case of ellipses
Few releases ago, we introduce narrow_widen wireproto command to be used to widen
narrow repositories. Before this patch, that was used in non-ellipses cases
only. In ellipses cases, we still do exchange.pull() which can pull more data
than required.
After this patch, the client will first check whether server supports doing
ellipses widening using wireproto command or not by checking server's wireproto
capability. If the server is upto date and support latest ellipses capability,
we call the wireproto command. Otherwise we fallback to exchange.pull() like
before.
The compat code make sure that things works even if one of the client or server
is old. The initial version of this patch does not had this compat code. It's
added to help Google release things smoothly internally. I plan to drop the
compat code before the upcoming major release.
Due to change to wireproto command, the code looks a bit dirty, next patches
will clean that up.
Differential Revision: https://phab.mercurial-scm.org/D6436
author | Pulkit Goyal <7895pulkit@gmail.com> |
---|---|
date | Wed, 22 May 2019 02:59:48 +0530 |
parents | 01e29e885600 |
children | 2372284d9457 |
rev | line source |
---|---|
36362
01e29e885600
util: add a file object proxy that can read at most N bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1 from __future__ import absolute_import, print_function |
01e29e885600
util: add a file object proxy that can read at most N bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2 |
01e29e885600
util: add a file object proxy that can read at most N bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3 import io |
01e29e885600
util: add a file object proxy that can read at most N bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
4 import unittest |
01e29e885600
util: add a file object proxy that can read at most N bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
5 |
01e29e885600
util: add a file object proxy that can read at most N bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
6 from mercurial import ( |
01e29e885600
util: add a file object proxy that can read at most N bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
7 util, |
01e29e885600
util: add a file object proxy that can read at most N bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
8 ) |
01e29e885600
util: add a file object proxy that can read at most N bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
9 |
01e29e885600
util: add a file object proxy that can read at most N bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
10 class CappedReaderTests(unittest.TestCase): |
01e29e885600
util: add a file object proxy that can read at most N bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
11 def testreadfull(self): |
01e29e885600
util: add a file object proxy that can read at most N bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
12 source = io.BytesIO(b'x' * 100) |
01e29e885600
util: add a file object proxy that can read at most N bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
13 |
01e29e885600
util: add a file object proxy that can read at most N bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
14 reader = util.cappedreader(source, 10) |
01e29e885600
util: add a file object proxy that can read at most N bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
15 res = reader.read(10) |
01e29e885600
util: add a file object proxy that can read at most N bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
16 self.assertEqual(res, b'x' * 10) |
01e29e885600
util: add a file object proxy that can read at most N bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
17 self.assertEqual(source.tell(), 10) |
01e29e885600
util: add a file object proxy that can read at most N bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
18 source.seek(0) |
01e29e885600
util: add a file object proxy that can read at most N bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
19 |
01e29e885600
util: add a file object proxy that can read at most N bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
20 reader = util.cappedreader(source, 15) |
01e29e885600
util: add a file object proxy that can read at most N bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
21 res = reader.read(16) |
01e29e885600
util: add a file object proxy that can read at most N bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
22 self.assertEqual(res, b'x' * 15) |
01e29e885600
util: add a file object proxy that can read at most N bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
23 self.assertEqual(source.tell(), 15) |
01e29e885600
util: add a file object proxy that can read at most N bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
24 source.seek(0) |
01e29e885600
util: add a file object proxy that can read at most N bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
25 |
01e29e885600
util: add a file object proxy that can read at most N bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
26 reader = util.cappedreader(source, 100) |
01e29e885600
util: add a file object proxy that can read at most N bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
27 res = reader.read(100) |
01e29e885600
util: add a file object proxy that can read at most N bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
28 self.assertEqual(res, b'x' * 100) |
01e29e885600
util: add a file object proxy that can read at most N bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
29 self.assertEqual(source.tell(), 100) |
01e29e885600
util: add a file object proxy that can read at most N bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
30 source.seek(0) |
01e29e885600
util: add a file object proxy that can read at most N bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
31 |
01e29e885600
util: add a file object proxy that can read at most N bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
32 reader = util.cappedreader(source, 50) |
01e29e885600
util: add a file object proxy that can read at most N bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
33 res = reader.read() |
01e29e885600
util: add a file object proxy that can read at most N bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
34 self.assertEqual(res, b'x' * 50) |
01e29e885600
util: add a file object proxy that can read at most N bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
35 self.assertEqual(source.tell(), 50) |
01e29e885600
util: add a file object proxy that can read at most N bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
36 source.seek(0) |
01e29e885600
util: add a file object proxy that can read at most N bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
37 |
01e29e885600
util: add a file object proxy that can read at most N bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
38 def testreadnegative(self): |
01e29e885600
util: add a file object proxy that can read at most N bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
39 source = io.BytesIO(b'x' * 100) |
01e29e885600
util: add a file object proxy that can read at most N bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
40 |
01e29e885600
util: add a file object proxy that can read at most N bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
41 reader = util.cappedreader(source, 20) |
01e29e885600
util: add a file object proxy that can read at most N bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
42 res = reader.read(-1) |
01e29e885600
util: add a file object proxy that can read at most N bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
43 self.assertEqual(res, b'x' * 20) |
01e29e885600
util: add a file object proxy that can read at most N bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
44 self.assertEqual(source.tell(), 20) |
01e29e885600
util: add a file object proxy that can read at most N bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
45 source.seek(0) |
01e29e885600
util: add a file object proxy that can read at most N bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
46 |
01e29e885600
util: add a file object proxy that can read at most N bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
47 reader = util.cappedreader(source, 100) |
01e29e885600
util: add a file object proxy that can read at most N bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
48 res = reader.read(-1) |
01e29e885600
util: add a file object proxy that can read at most N bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
49 self.assertEqual(res, b'x' * 100) |
01e29e885600
util: add a file object proxy that can read at most N bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
50 self.assertEqual(source.tell(), 100) |
01e29e885600
util: add a file object proxy that can read at most N bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
51 source.seek(0) |
01e29e885600
util: add a file object proxy that can read at most N bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
52 |
01e29e885600
util: add a file object proxy that can read at most N bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
53 def testreadmultiple(self): |
01e29e885600
util: add a file object proxy that can read at most N bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
54 source = io.BytesIO(b'x' * 100) |
01e29e885600
util: add a file object proxy that can read at most N bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
55 |
01e29e885600
util: add a file object proxy that can read at most N bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
56 reader = util.cappedreader(source, 10) |
01e29e885600
util: add a file object proxy that can read at most N bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
57 for i in range(10): |
01e29e885600
util: add a file object proxy that can read at most N bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
58 res = reader.read(1) |
01e29e885600
util: add a file object proxy that can read at most N bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
59 self.assertEqual(res, b'x') |
01e29e885600
util: add a file object proxy that can read at most N bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
60 self.assertEqual(source.tell(), i + 1) |
01e29e885600
util: add a file object proxy that can read at most N bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
61 |
01e29e885600
util: add a file object proxy that can read at most N bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
62 self.assertEqual(source.tell(), 10) |
01e29e885600
util: add a file object proxy that can read at most N bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
63 res = reader.read(1) |
01e29e885600
util: add a file object proxy that can read at most N bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
64 self.assertEqual(res, b'') |
01e29e885600
util: add a file object proxy that can read at most N bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
65 self.assertEqual(source.tell(), 10) |
01e29e885600
util: add a file object proxy that can read at most N bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
66 source.seek(0) |
01e29e885600
util: add a file object proxy that can read at most N bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
67 |
01e29e885600
util: add a file object proxy that can read at most N bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
68 reader = util.cappedreader(source, 45) |
01e29e885600
util: add a file object proxy that can read at most N bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
69 for i in range(4): |
01e29e885600
util: add a file object proxy that can read at most N bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
70 res = reader.read(10) |
01e29e885600
util: add a file object proxy that can read at most N bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
71 self.assertEqual(res, b'x' * 10) |
01e29e885600
util: add a file object proxy that can read at most N bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
72 self.assertEqual(source.tell(), (i + 1) * 10) |
01e29e885600
util: add a file object proxy that can read at most N bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
73 |
01e29e885600
util: add a file object proxy that can read at most N bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
74 res = reader.read(10) |
01e29e885600
util: add a file object proxy that can read at most N bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
75 self.assertEqual(res, b'x' * 5) |
01e29e885600
util: add a file object proxy that can read at most N bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
76 self.assertEqual(source.tell(), 45) |
01e29e885600
util: add a file object proxy that can read at most N bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
77 |
01e29e885600
util: add a file object proxy that can read at most N bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
78 def readlimitpasteof(self): |
01e29e885600
util: add a file object proxy that can read at most N bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
79 source = io.BytesIO(b'x' * 100) |
01e29e885600
util: add a file object proxy that can read at most N bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
80 |
01e29e885600
util: add a file object proxy that can read at most N bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
81 reader = util.cappedreader(source, 1024) |
01e29e885600
util: add a file object proxy that can read at most N bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
82 res = reader.read(1000) |
01e29e885600
util: add a file object proxy that can read at most N bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
83 self.assertEqual(res, b'x' * 100) |
01e29e885600
util: add a file object proxy that can read at most N bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
84 self.assertEqual(source.tell(), 100) |
01e29e885600
util: add a file object proxy that can read at most N bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
85 res = reader.read(1000) |
01e29e885600
util: add a file object proxy that can read at most N bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
86 self.assertEqual(res, b'') |
01e29e885600
util: add a file object proxy that can read at most N bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
87 self.assertEqual(source.tell(), 100) |
01e29e885600
util: add a file object proxy that can read at most N bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
88 |
01e29e885600
util: add a file object proxy that can read at most N bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
89 if __name__ == '__main__': |
01e29e885600
util: add a file object proxy that can read at most N bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
90 import silenttestrunner |
01e29e885600
util: add a file object proxy that can read at most N bytes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
91 silenttestrunner.main(__name__) |