Mercurial > hg
annotate tests/test-status-inprocess.py @ 39561:d06834e0f48e
wireprotov2peer: stream decoded responses
Previously, wire protocol version 2 would buffer all response data.
Only once all data was received did we CBOR decode it and resolve
the future associated with the command. This was obviously not
desirable. In future commits that introduce large response payloads,
this caused significant memory bloat and slowed down client
operations due to waiting on the server.
This commit refactors the response handling code so that response
data can be streamed.
Command response objects now contain a buffered CBOR decoder. As
new data arrives, it is fed into the decoder. Decoded objects are
made available to the generator as they are decoded.
Because there is a separate thread processing incoming frames and
feeding data into the response object, there is the potential for
race conditions when mutating response objects. So a lock has been
added to guard access to critical state variables.
Because the generator emitting decoded objects needs to wait on
those objects to become available, we've added an Event for the
generator to wait on so it doesn't busy loop. This does mean
there is the potential for deadlocks. And I'm pretty sure they can
occur in some scenarios. We already have a handful of TODOs around
this. But I've added some more. Fixing this will likely require
moving the background thread receiving frames into clienthandler.
We likely would have done this anyway when implementing the client
bits for the SSH transport.
Test output changes because the initial CBOR map holding the overall
response state is now always handled internally by the response
object.
Differential Revision: https://phab.mercurial-scm.org/D4474
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Wed, 29 Aug 2018 15:17:11 -0700 |
parents | 7ce9dea3a14a |
children | 2372284d9457 |
rev | line source |
---|---|
28824
9d31582dd636
tests: use /usr/bin/env python for test-status-inprocess.py
timeless <timeless@mozdev.org>
parents:
28766
diff
changeset
|
1 #!/usr/bin/env python |
28766
7f7cd44cd6d5
py3: use print_function in test-status-inprocess.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28765
diff
changeset
|
2 from __future__ import absolute_import, print_function |
28843
2c7e6f363138
tests: stop direct symbol import of mercurial modules in test-status-inprocess
Yuya Nishihara <yuya@tcha.org>
parents:
28824
diff
changeset
|
3 |
37901
bbff7170f665
tests: fix test-status-inprocess.py on Python 3
Augie Fackler <augie@google.com>
parents:
37660
diff
changeset
|
4 import sys |
bbff7170f665
tests: fix test-status-inprocess.py on Python 3
Augie Fackler <augie@google.com>
parents:
37660
diff
changeset
|
5 |
28843
2c7e6f363138
tests: stop direct symbol import of mercurial modules in test-status-inprocess
Yuya Nishihara <yuya@tcha.org>
parents:
28824
diff
changeset
|
6 from mercurial import ( |
2c7e6f363138
tests: stop direct symbol import of mercurial modules in test-status-inprocess
Yuya Nishihara <yuya@tcha.org>
parents:
28824
diff
changeset
|
7 commands, |
2c7e6f363138
tests: stop direct symbol import of mercurial modules in test-status-inprocess
Yuya Nishihara <yuya@tcha.org>
parents:
28824
diff
changeset
|
8 localrepo, |
2c7e6f363138
tests: stop direct symbol import of mercurial modules in test-status-inprocess
Yuya Nishihara <yuya@tcha.org>
parents:
28824
diff
changeset
|
9 ui as uimod, |
28765
7779f9dfd938
py3: use absolute_import in test-status-inprocess.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
10905
diff
changeset
|
10 ) |
10838
07dbafd3a0e2
add a test for the inprocess status dirstate race
Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
parents:
diff
changeset
|
11 |
37901
bbff7170f665
tests: fix test-status-inprocess.py on Python 3
Augie Fackler <augie@google.com>
parents:
37660
diff
changeset
|
12 print_ = print |
bbff7170f665
tests: fix test-status-inprocess.py on Python 3
Augie Fackler <augie@google.com>
parents:
37660
diff
changeset
|
13 def print(*args, **kwargs): |
bbff7170f665
tests: fix test-status-inprocess.py on Python 3
Augie Fackler <augie@google.com>
parents:
37660
diff
changeset
|
14 """print() wrapper that flushes stdout buffers to avoid py3 buffer issues |
bbff7170f665
tests: fix test-status-inprocess.py on Python 3
Augie Fackler <augie@google.com>
parents:
37660
diff
changeset
|
15 |
bbff7170f665
tests: fix test-status-inprocess.py on Python 3
Augie Fackler <augie@google.com>
parents:
37660
diff
changeset
|
16 We could also just write directly to sys.stdout.buffer the way the |
bbff7170f665
tests: fix test-status-inprocess.py on Python 3
Augie Fackler <augie@google.com>
parents:
37660
diff
changeset
|
17 ui object will, but this was easier for porting the test. |
bbff7170f665
tests: fix test-status-inprocess.py on Python 3
Augie Fackler <augie@google.com>
parents:
37660
diff
changeset
|
18 """ |
bbff7170f665
tests: fix test-status-inprocess.py on Python 3
Augie Fackler <augie@google.com>
parents:
37660
diff
changeset
|
19 print_(*args, **kwargs) |
bbff7170f665
tests: fix test-status-inprocess.py on Python 3
Augie Fackler <augie@google.com>
parents:
37660
diff
changeset
|
20 sys.stdout.flush() |
bbff7170f665
tests: fix test-status-inprocess.py on Python 3
Augie Fackler <augie@google.com>
parents:
37660
diff
changeset
|
21 |
30559
d83ca854fa21
ui: factor out ui.load() to create a ui without loading configs (API)
Yuya Nishihara <yuya@tcha.org>
parents:
28843
diff
changeset
|
22 u = uimod.ui.load() |
10838
07dbafd3a0e2
add a test for the inprocess status dirstate race
Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
parents:
diff
changeset
|
23 |
28766
7f7cd44cd6d5
py3: use print_function in test-status-inprocess.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28765
diff
changeset
|
24 print('% creating repo') |
39548
7ce9dea3a14a
localrepo: move repo creation logic out of localrepository.__init__ (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37901
diff
changeset
|
25 repo = localrepo.instance(u, b'.', create=True) |
10838
07dbafd3a0e2
add a test for the inprocess status dirstate race
Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
parents:
diff
changeset
|
26 |
07dbafd3a0e2
add a test for the inprocess status dirstate race
Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
parents:
diff
changeset
|
27 f = open('test.py', 'w') |
07dbafd3a0e2
add a test for the inprocess status dirstate race
Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
parents:
diff
changeset
|
28 try: |
07dbafd3a0e2
add a test for the inprocess status dirstate race
Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
parents:
diff
changeset
|
29 f.write('foo\n') |
07dbafd3a0e2
add a test for the inprocess status dirstate race
Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
parents:
diff
changeset
|
30 finally: |
07dbafd3a0e2
add a test for the inprocess status dirstate race
Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
parents:
diff
changeset
|
31 f.close |
07dbafd3a0e2
add a test for the inprocess status dirstate race
Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
parents:
diff
changeset
|
32 |
28766
7f7cd44cd6d5
py3: use print_function in test-status-inprocess.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28765
diff
changeset
|
33 print('% add and commit') |
37660
9dfa4e9ed45d
py3: add b'' prefixes to tests/test-status-inprocess.py
Pulkit Goyal <7895pulkit@gmail.com>
parents:
30559
diff
changeset
|
34 commands.add(u, repo, b'test.py') |
9dfa4e9ed45d
py3: add b'' prefixes to tests/test-status-inprocess.py
Pulkit Goyal <7895pulkit@gmail.com>
parents:
30559
diff
changeset
|
35 commands.commit(u, repo, message=b'*') |
28843
2c7e6f363138
tests: stop direct symbol import of mercurial modules in test-status-inprocess
Yuya Nishihara <yuya@tcha.org>
parents:
28824
diff
changeset
|
36 commands.status(u, repo, clean=True) |
10838
07dbafd3a0e2
add a test for the inprocess status dirstate race
Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
parents:
diff
changeset
|
37 |
07dbafd3a0e2
add a test for the inprocess status dirstate race
Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
parents:
diff
changeset
|
38 |
28766
7f7cd44cd6d5
py3: use print_function in test-status-inprocess.py
Robert Stanca <robert.stanca7@gmail.com>
parents:
28765
diff
changeset
|
39 print('% change') |
10838
07dbafd3a0e2
add a test for the inprocess status dirstate race
Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
parents:
diff
changeset
|
40 f = open('test.py', 'w') |
07dbafd3a0e2
add a test for the inprocess status dirstate race
Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
parents:
diff
changeset
|
41 try: |
07dbafd3a0e2
add a test for the inprocess status dirstate race
Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
parents:
diff
changeset
|
42 f.write('bar\n') |
07dbafd3a0e2
add a test for the inprocess status dirstate race
Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
parents:
diff
changeset
|
43 finally: |
07dbafd3a0e2
add a test for the inprocess status dirstate race
Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
parents:
diff
changeset
|
44 f.close() |
07dbafd3a0e2
add a test for the inprocess status dirstate race
Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
parents:
diff
changeset
|
45 |
07dbafd3a0e2
add a test for the inprocess status dirstate race
Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
parents:
diff
changeset
|
46 # this would return clean instead of changed before the fix |
28843
2c7e6f363138
tests: stop direct symbol import of mercurial modules in test-status-inprocess
Yuya Nishihara <yuya@tcha.org>
parents:
28824
diff
changeset
|
47 commands.status(u, repo, clean=True, modified=True) |