summary refs log tree commit diff
path: root/synapse/util/metrics.py
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2016-02-09 13:50:29 +0000
committerErik Johnston <erik@matrix.org>2016-02-09 13:50:37 +0000
commit82631c5f948cfb3cb133379e0e5ad10811d706a2 (patch)
tree1658266f7984753dd51675fbe5a63b6b201be921 /synapse/util/metrics.py
parentMerge pull request #560 from matrix-org/daniel/tox (diff)
downloadsynapse-82631c5f948cfb3cb133379e0e5ad10811d706a2.tar.xz
Fix unit tests
Diffstat (limited to '')
-rw-r--r--synapse/util/metrics.py9
1 files changed, 5 insertions, 4 deletions
diff --git a/synapse/util/metrics.py b/synapse/util/metrics.py
index 57ca3b4751..c51b641125 100644
--- a/synapse/util/metrics.py
+++ b/synapse/util/metrics.py
@@ -62,12 +62,13 @@ class Measure(object):
     def __enter__(self):
         self.start = self.clock.time_msec()
         self.start_context = LoggingContext.current_context()
-        self.ru_utime, self.ru_stime = self.start_context.get_resource_usage()
-        self.db_txn_count = self.start_context.db_txn_count
-        self.db_txn_duration = self.start_context.db_txn_duration
+        if self.start_context:
+            self.ru_utime, self.ru_stime = self.start_context.get_resource_usage()
+            self.db_txn_count = self.start_context.db_txn_count
+            self.db_txn_duration = self.start_context.db_txn_duration
 
     def __exit__(self, exc_type, exc_val, exc_tb):
-        if exc_type is not None:
+        if exc_type is not None or not self.start_context:
             return
 
         duration = self.clock.time_msec() - self.start