diff options
| author | Damian Johnson <atagar@torproject.org> | 2014-12-07 12:19:57 -0800 |
|---|---|---|
| committer | Damian Johnson <atagar@torproject.org> | 2014-12-07 12:36:12 -0800 |
| commit | f3406f8058e6183e5029e309d4b6ecba23e32b2a (patch) | |
| tree | 690518dbd59d1ff1420f1389a829419fd774e6dd | |
| parent | 500fd38a7d09e883257d84dd67bc7014f4f47085 (diff) | |
Testing each connection resolver separately
On Gentoo test_get_connections fails and, while that's all well and good, I
can't tell from this single failure if just proc is broken or all linux
connection resolvers. Testing each resolver separately so we'll be able to tell
in the future.
| -rw-r--r-- | test/integ/util/connection.py | 61 |
1 files changed, 50 insertions, 11 deletions
diff --git a/test/integ/util/connection.py b/test/integ/util/connection.py index 589026a8..9bc65914 100644 --- a/test/integ/util/connection.py +++ b/test/integ/util/connection.py @@ -7,27 +7,66 @@ import unittest import test.runner -from stem.util.connection import get_connections, system_resolvers +from stem.util.connection import Resolver, get_connections, system_resolvers class TestConnection(unittest.TestCase): - def test_get_connections(self): + def check_resolver(self, resolver): runner = test.runner.get_runner() if test.runner.Torrc.PORT not in runner.get_options(): test.runner.skip(self, '(no control port)') return - elif not test.runner.get_runner().is_ptraceable(): + elif not runner.is_ptraceable(): test.runner.skip(self, '(DisableDebuggerAttachment is set)') return + elif resolver not in system_resolvers(): + test.runner.skip(self, '(resolver unavailable on this platform)') + return + + with runner.get_tor_socket(): + connections = get_connections(resolver, process_pid = runner.get_pid()) + + for conn in connections: + if conn.local_address == '127.0.0.1' and conn.local_port == test.runner.CONTROL_PORT: + return + + self.fail('Unable to find localhost connection with %s:\n%s' % (resolver, '\n'.join(connections))) + + def test_get_connections_by_proc(self): + self.check_resolver(Resolver.PROC) + + def test_get_connections_by_netstat(self): + self.check_resolver(Resolver.NETSTAT) + + def test_get_connections_by_ss(self): + self.check_resolver(Resolver.SS) + + def test_get_connections_by_lsof(self): + self.check_resolver(Resolver.LSOF) + + def test_get_connections_by_sockstat(self): + self.check_resolver(Resolver.SOCKSTAT) + + def test_get_connections_by_bsd_sockstat(self): + self.check_resolver(Resolver.BSD_SOCKSTAT) + + def test_get_connections_by_bsd_procstat(self): + self.check_resolver(Resolver.BSD_PROCSTAT) - for resolver in system_resolvers(): - with runner.get_tor_socket(): - tor_pid = test.runner.get_runner().get_pid() - connections = get_connections(resolver, process_pid = tor_pid) + def test_that_we_are_checking_all_resolvers(self): + # Quick check to confirm that if we add a new Resolver, we include a test + # for it here. - for conn in connections: - if conn.local_address == '127.0.0.1' and conn.local_port == test.runner.CONTROL_PORT: - return + recognized_resolvers = ( + Resolver.PROC, + Resolver.NETSTAT, + Resolver.SS, + Resolver.LSOF, + Resolver.SOCKSTAT, + Resolver.BSD_SOCKSTAT, + Resolver.BSD_PROCSTAT, + ) - self.fail('Unable to find localhost connection with %s:\n%s' % (resolver, '\n'.join(connections))) + for resolver in Resolver: + self.assertTrue(resolver in recognized_resolvers) |
