[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [sbws/maint-1.1] Use freeze_time() in other parts of our tests, too



commit 74ad2d91e38124e005fb3adc36ac38181ee155af
Author: Georg Koppen <gk@xxxxxxxxxxxxxx>
Date:   Thu Apr 2 07:48:22 2020 +0000

    Use freeze_time() in other parts of our tests, too
    
    When using `_relays_with_flags()` and similar methods it's possible
    that tests start to hang without time freezing. See bug 33748 for more
    details. We work around this by providing the necessary `freeze_time()`
    calls meanwhile.
---
 tests/conftest.py                | 4 +++-
 tests/unit/lib/test_relaylist.py | 5 ++---
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/tests/conftest.py b/tests/conftest.py
index 3ffa7bb..5d156f1 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -3,6 +3,7 @@ import pytest
 import os.path
 from unittest import mock
 
+from freezegun import freeze_time
 from stem import descriptor
 
 from sbws import settings
@@ -120,7 +121,8 @@ def router_status(server_descriptor, router_statuses):
 @pytest.fixture(scope='function')
 def relay_list(args, conf, controller):
     """Returns a RelayList containing the Relays in the controller"""
-    return relaylist.RelayList(args, conf, controller)
+    with freeze_time("2020-02-29 10:00:00"):
+        return relaylist.RelayList(args, conf, controller)
 
 
 @pytest.fixture(scope='function')
diff --git a/tests/unit/lib/test_relaylist.py b/tests/unit/lib/test_relaylist.py
index 5561d60..88f9db5 100644
--- a/tests/unit/lib/test_relaylist.py
+++ b/tests/unit/lib/test_relaylist.py
@@ -71,9 +71,8 @@ def test_increment_recent_measurement_attempt(args, conf, controller):
     It also tests that the state file is updated correctly.
     """
     state = State(conf['paths']['state_fpath'])
-    # For this test it does not matter that the consensus timestamps or relays
-    # are not correct.
-    relay_list = RelayList(args, conf, controller=controller, state=state)
+    with freeze_time("2020-02-29 10:00:00"):
+        relay_list = RelayList(args, conf, controller=controller, state=state)
     # The initial count is 0 and the state does not have that key.
     assert 0 == relay_list.recent_measurement_attempt_count
     assert not state.get("recent_measurement_attempt", None)



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits