commit a55e9619fb23b8185f03a06e80930def882fc3d9 Author: Damian Johnson atagar@torproject.org Date: Fri Jan 6 10:50:13 2017 -0800
Speed up controller's test_reattaching_listeners integ test
Test was decent, but overly extensive for the simple thing it aimed to assert. This test is supposed to simply check that when we reattach to tor we resume getting events we were previously subscribed for.
Narrowing the test to be just about that and use events we can trigger rather than waiting for BW events to be emitted (which is the main cause of this test's long runtime). On my netbook this drops the test from 5.8s to 104 ms (98% faster). --- test/integ/control/controller.py | 51 ++++++---------------------------------- 1 file changed, 7 insertions(+), 44 deletions(-)
diff --git a/test/integ/control/controller.py b/test/integ/control/controller.py index 1c80ae2..f7b6555 100644 --- a/test/integ/control/controller.py +++ b/test/integ/control/controller.py @@ -208,66 +208,29 @@ class TestController(unittest.TestCase): runner = test.runner.get_runner()
with runner.get_tor_controller() as controller: - controller.add_event_listener(listener, EventType.BW) + controller.add_event_listener(listener, EventType.CONF_CHANGED)
- # Get a BW event or two. These should be emitted each second but under - # heavy system load that's not always the case. + # trigger an event
+ controller.set_conf('NodeFamily', random_fingerprint()) event_notice.wait(4) self.assertTrue(len(event_buffer) >= 1)
- # disconnect and check that we stop getting events + # disconnect, then reconnect and check that we get events again
controller.close() event_notice.clear() event_buffer = []
- event_notice.wait(2) - self.assertTrue(len(event_buffer) == 0) - - # reconnect and check that we get events again - controller.connect() controller.authenticate(password = test.runner.CONTROL_PASSWORD) + self.assertTrue(len(event_buffer) == 0) + controller.set_conf('NodeFamily', random_fingerprint())
event_notice.wait(4) self.assertTrue(len(event_buffer) >= 1)
- # disconnect - - controller.close() - event_notice.clear() - event_buffer = [] - - # reconnect and check that we get events again - - controller.connect() - stem.connection.authenticate(controller, password = test.runner.CONTROL_PASSWORD) - - event_notice.wait(4) - self.assertTrue(len(event_buffer) >= 1) - - # disconnect - - controller.close() - event_notice.clear() - event_buffer = [] - - # Reconnect and check that we get events again. This is being done by - # calling AUTHENTICATE manually so skipping cookie auth. - - tor_options = test.runner.get_runner().get_options() - - if test.runner.Torrc.COOKIE not in tor_options: - controller.connect() - - if test.runner.Torrc.PASSWORD in tor_options: - controller.msg('AUTHENTICATE "%s"' % test.runner.CONTROL_PASSWORD) - else: - controller.msg('AUTHENTICATE') - - event_notice.wait(4) - self.assertTrue(len(event_buffer) >= 1) + controller.reset_conf('NodeFamily')
@require_controller def test_getinfo(self):
tor-commits@lists.torproject.org