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

[tor-commits] [chutney/master] TorNet: Use wallclock elapsed time for bootstrap



commit ea611d7633d4aa87c725e9cb7133501c338df8ff
Author: teor <teor@xxxxxxxxxxxxxx>
Date:   Wed Feb 19 15:37:27 2020 +1000

    TorNet: Use wallclock elapsed time for bootstrap
    
    The previous code counted the number of sleeps.
    
    Using wallclock time is more accurate, and the code is simpler.
    
    Part of 33232.
---
 lib/chutney/TorNet.py | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/lib/chutney/TorNet.py b/lib/chutney/TorNet.py
index 6dbda36..0917fbf 100644
--- a/lib/chutney/TorNet.py
+++ b/lib/chutney/TorNet.py
@@ -1448,12 +1448,13 @@ class Network(object):
         print("Sending SIGHUP to nodes")
         return all([n.getController().hup() for n in self._nodes])
 
+    CHECK_NETWORK_STATUS_DELAY = 0.5
+
     def wait_for_bootstrap(self):
         print("Waiting for nodes to bootstrap...")
-        limit = getenv_int("CHUTNEY_START_TIME", 60)
-        delay = 0.5
+        start = time.time()
+        limit = start + getenv_int("CHUTNEY_START_TIME", 60)
         controllers = [n.getController() for n in self._nodes]
-        elapsed = 0.0
         most_recent_status = [ None ] * len(controllers)
         while True:
             all_bootstrapped = True
@@ -1464,13 +1465,15 @@ class Network(object):
                 if pct != 100:
                     all_bootstrapped = False
 
+            now = time.time()
             if all_bootstrapped:
-                print("Everything bootstrapped after %s sec"%elapsed)
+                elapsed = now - start
+                print("Everything bootstrapped after {} sec"
+                      .format(int(elapsed)))
                 return True
-            if elapsed >= limit:
+            if now >= limit:
                 break
-            time.sleep(delay)
-            elapsed += delay
+            time.sleep(Network.CHECK_NETWORK_STATUS_DELAY)
 
         print("Bootstrap failed. Node status:")
         for c, status in zip(controllers,most_recent_status):



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