summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMike Frysinger <vapier@google.com>2021-05-06 00:44:42 -0400
committerMike Frysinger <vapier@google.com>2021-05-10 21:16:06 +0000
commit339f2df1ddd741070e340ec01d6882dd1eee617c (patch)
treed16fe7c87ba966a400d545bef5a49c460b75dc57 /tests
parent19e409c81863878d5d313fdc40b3975b98602454 (diff)
downloadgit-repo-339f2df1ddd741070e340ec01d6882dd1eee617c.tar.gz
ssh: rewrite proxy management for multiprocessing usagev2.15
We changed sync to use multiprocessing for parallel work. This broke the ssh proxy code as it's all based on threads. Rewrite the logic to be multiprocessing safe. Now instead of the module acting as a stateful object, callers have to instantiate a new ProxyManager class that holds all the state, an pass that down to any users. Bug: https://crbug.com/gerrit/12389 Change-Id: I4b1af116f7306b91e825d3c56fb4274c9b033562 Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/305486 Tested-by: Mike Frysinger <vapier@google.com> Reviewed-by: Chris Mcdonald <cjmcdonald@google.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/test_ssh.py30
1 files changed, 26 insertions, 4 deletions
diff --git a/tests/test_ssh.py b/tests/test_ssh.py
index 5a4f27e4..ffb5cb94 100644
--- a/tests/test_ssh.py
+++ b/tests/test_ssh.py
@@ -14,6 +14,8 @@
14 14
15"""Unittests for the ssh.py module.""" 15"""Unittests for the ssh.py module."""
16 16
17import multiprocessing
18import subprocess
17import unittest 19import unittest
18from unittest import mock 20from unittest import mock
19 21
@@ -39,14 +41,34 @@ class SshTests(unittest.TestCase):
39 with mock.patch('ssh._run_ssh_version', return_value='OpenSSH_1.2\n'): 41 with mock.patch('ssh._run_ssh_version', return_value='OpenSSH_1.2\n'):
40 self.assertEqual(ssh.version(), (1, 2)) 42 self.assertEqual(ssh.version(), (1, 2))
41 43
44 def test_context_manager_empty(self):
45 """Verify context manager with no clients works correctly."""
46 with multiprocessing.Manager() as manager:
47 with ssh.ProxyManager(manager):
48 pass
49
50 def test_context_manager_child_cleanup(self):
51 """Verify orphaned clients & masters get cleaned up."""
52 with multiprocessing.Manager() as manager:
53 with ssh.ProxyManager(manager) as ssh_proxy:
54 client = subprocess.Popen(['sleep', '964853320'])
55 ssh_proxy.add_client(client)
56 master = subprocess.Popen(['sleep', '964853321'])
57 ssh_proxy.add_master(master)
58 # If the process still exists, these will throw timeout errors.
59 client.wait(0)
60 master.wait(0)
61
42 def test_ssh_sock(self): 62 def test_ssh_sock(self):
43 """Check sock() function.""" 63 """Check sock() function."""
64 manager = multiprocessing.Manager()
65 proxy = ssh.ProxyManager(manager)
44 with mock.patch('tempfile.mkdtemp', return_value='/tmp/foo'): 66 with mock.patch('tempfile.mkdtemp', return_value='/tmp/foo'):
45 # old ssh version uses port 67 # old ssh version uses port
46 with mock.patch('ssh.version', return_value=(6, 6)): 68 with mock.patch('ssh.version', return_value=(6, 6)):
47 self.assertTrue(ssh.sock().endswith('%p')) 69 self.assertTrue(proxy.sock().endswith('%p'))
48 ssh._ssh_sock_path = None 70
71 proxy._sock_path = None
49 # new ssh version uses hash 72 # new ssh version uses hash
50 with mock.patch('ssh.version', return_value=(6, 7)): 73 with mock.patch('ssh.version', return_value=(6, 7)):
51 self.assertTrue(ssh.sock().endswith('%C')) 74 self.assertTrue(proxy.sock().endswith('%C'))
52 ssh._ssh_sock_path = None