Mercurial > public > mercurial-scm > hg
comparison tests/test-sshserver.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 | 642e31cb55f0 |
children |
comparison
equal
deleted
inserted
replaced
51568:74230abb2504 | 51569:13c004b54cbe |
---|---|
23 for input, expected in tests: | 23 for input, expected in tests: |
24 self.assertparse(b'known', input, expected) | 24 self.assertparse(b'known', input, expected) |
25 | 25 |
26 def assertparse(self, cmd, input, expected): | 26 def assertparse(self, cmd, input, expected): |
27 server = mockserver(input) | 27 server = mockserver(input) |
28 proto = wireprotoserver.sshv1protocolhandler( | 28 ui = server._ui |
29 server._ui, server._fin, server._fout | 29 proto = wireprotoserver.sshv1protocolhandler(ui, ui.fin, ui.fout) |
30 ) | |
31 _func, spec = wireprotov1server.commands[cmd] | 30 _func, spec = wireprotov1server.commands[cmd] |
32 self.assertEqual(proto.getargs(spec), expected) | 31 self.assertEqual(proto.getargs(spec), expected) |
33 | 32 |
34 | 33 |
35 def mockserver(inbytes): | 34 def mockserver(inbytes): |
36 ui = mockui(inbytes) | 35 ui = mockui(inbytes) |
37 repo = mockrepo(ui) | 36 repo = mockrepo(ui) |
37 # note: this test unfortunately doesn't really test anything about | |
38 # `sshserver` class anymore: the entirety of logic of that class lives | |
39 # in `serveuntil`, and that function is not even called by this test. | |
38 return wireprotoserver.sshserver(ui, repo) | 40 return wireprotoserver.sshserver(ui, repo) |
39 | 41 |
40 | 42 |
41 class mockrepo: | 43 class mockrepo: |
42 def __init__(self, ui): | 44 def __init__(self, ui): |