Mercurial > public > mercurial-scm > hg
comparison tests/sshprotoext.py @ 51569:13c004b54cbe stable
wireprotoserver: ensure that output stream gets flushed on exception
Previously flush was happening due to Python finalizer being run on
`BufferedWriter`. With upgrade to Python 3.11 this started randomly
failing.
My guess is that the finalizer on the raw `FileIO` object may
be running before the finalizer of `BufferedWriter` has a chance to run.
At any rate, since we're not relying on finalizers in the happy case
we should also not rely on them in case of exception.
author | Arseniy Alekseyev <aalekseyev@janestreet.com> |
---|---|
date | Thu, 04 Apr 2024 14:15:32 +0100 |
parents | 6000f5b25c9b |
children | 5cc8deb96b48 |
comparison
equal
deleted
inserted
replaced
51568:74230abb2504 | 51569:13c004b54cbe |
---|---|
28 class bannerserver(wireprotoserver.sshserver): | 28 class bannerserver(wireprotoserver.sshserver): |
29 """Server that sends a banner to stdout.""" | 29 """Server that sends a banner to stdout.""" |
30 | 30 |
31 def serve_forever(self): | 31 def serve_forever(self): |
32 for i in range(10): | 32 for i in range(10): |
33 self._fout.write(b'banner: line %d\n' % i) | 33 self._ui.fout.write(b'banner: line %d\n' % i) |
34 | 34 |
35 super(bannerserver, self).serve_forever() | 35 super(bannerserver, self).serve_forever() |
36 | 36 |
37 | 37 |
38 class prehelloserver(wireprotoserver.sshserver): | 38 class prehelloserver(wireprotoserver.sshserver): |
43 to SSH servers. This mock server tests behavior of the handshake | 43 to SSH servers. This mock server tests behavior of the handshake |
44 when ``hello`` is not supported. | 44 when ``hello`` is not supported. |
45 """ | 45 """ |
46 | 46 |
47 def serve_forever(self): | 47 def serve_forever(self): |
48 l = self._fin.readline() | 48 ui = self._ui |
49 l = ui.fin.readline() | |
49 assert l == b'hello\n' | 50 assert l == b'hello\n' |
50 # Respond to unknown commands with an empty reply. | 51 # Respond to unknown commands with an empty reply. |
51 wireprotoserver._sshv1respondbytes(self._fout, b'') | 52 wireprotoserver._sshv1respondbytes(ui.fout, b'') |
52 l = self._fin.readline() | 53 l = ui.fin.readline() |
53 assert l == b'between\n' | 54 assert l == b'between\n' |
54 proto = wireprotoserver.sshv1protocolhandler( | 55 proto = wireprotoserver.sshv1protocolhandler(ui, ui.fin, ui.fout) |
55 self._ui, self._fin, self._fout | |
56 ) | |
57 rsp = wireprotov1server.dispatch(self._repo, proto, b'between') | 56 rsp = wireprotov1server.dispatch(self._repo, proto, b'between') |
58 wireprotoserver._sshv1respondbytes(self._fout, rsp.data) | 57 wireprotoserver._sshv1respondbytes(ui.fout, rsp.data) |
59 | 58 |
60 super(prehelloserver, self).serve_forever() | 59 super(prehelloserver, self).serve_forever() |
61 | 60 |
62 | 61 |
63 def performhandshake(orig, ui, stdin, stdout, stderr): | 62 def performhandshake(orig, ui, stdin, stdout, stderr): |