aurora-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kevi...@apache.org
Subject incubator-aurora git commit: Fix clusters.patch contextmanager cleanup
Date Sat, 07 Mar 2015 01:06:44 GMT
Repository: incubator-aurora
Updated Branches:
  refs/heads/master 5aa130e17 -> 0913a9c66


Fix clusters.patch contextmanager cleanup

Otherwise one failing testcase can affect the entire suite.

Testing Done:
./pants test.pytest --no-fast src/test/python/apache/aurora/common::

Reviewed at https://reviews.apache.org/r/31350/


Project: http://git-wip-us.apache.org/repos/asf/incubator-aurora/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-aurora/commit/0913a9c6
Tree: http://git-wip-us.apache.org/repos/asf/incubator-aurora/tree/0913a9c6
Diff: http://git-wip-us.apache.org/repos/asf/incubator-aurora/diff/0913a9c6

Branch: refs/heads/master
Commit: 0913a9c663a126166bda65c54e6e65f8d2b72011
Parents: 5aa130e
Author: Stephan Erb <stephan@dev.static-void.de>
Authored: Fri Mar 6 17:06:28 2015 -0800
Committer: Kevin Sweeney <kevints@apache.org>
Committed: Fri Mar 6 17:06:28 2015 -0800

----------------------------------------------------------------------
 src/main/python/apache/aurora/common/clusters.py      |  8 +++++---
 src/test/python/apache/aurora/common/test_clusters.py | 12 ++++++++++++
 2 files changed, 17 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/0913a9c6/src/main/python/apache/aurora/common/clusters.py
----------------------------------------------------------------------
diff --git a/src/main/python/apache/aurora/common/clusters.py b/src/main/python/apache/aurora/common/clusters.py
index c4b7fef..88e9310 100644
--- a/src/main/python/apache/aurora/common/clusters.py
+++ b/src/main/python/apache/aurora/common/clusters.py
@@ -89,9 +89,11 @@ class Clusters(Mapping):
     """Patch this Clusters instance with a new list of clusters in a
        contextmanager.  Intended for testing purposes."""
     old_clusters = self._clusters.copy()
-    self.replace(cluster_list)
-    yield self
-    self._clusters = old_clusters
+    try:
+      self.replace(cluster_list)
+      yield self
+    finally:
+      self._clusters = old_clusters
 
   def __iter__(self):
     return iter(self._clusters)

http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/0913a9c6/src/test/python/apache/aurora/common/test_clusters.py
----------------------------------------------------------------------
diff --git a/src/test/python/apache/aurora/common/test_clusters.py b/src/test/python/apache/aurora/common/test_clusters.py
index 1bd696e..73b1b29 100644
--- a/src/test/python/apache/aurora/common/test_clusters.py
+++ b/src/test/python/apache/aurora/common/test_clusters.py
@@ -18,6 +18,7 @@ import os
 import pytest
 from twitter.common.contextutil import temporary_dir
 
+from apache.aurora.common.cluster import Cluster
 from apache.aurora.common.clusters import Clusters
 
 
@@ -75,3 +76,14 @@ def test_load_invalid_syntax():
       fp.write(json.dumps({'cluster1': ['not', 'cluster', 'values']}))
     with pytest.raises(Clusters.ParseError):
       Clusters.from_file(clusters_json)
+
+
+def test_patch_cleanup_on_error():
+  clusters = Clusters([Cluster(name='original')])
+
+  with pytest.raises(RuntimeError):
+    with clusters.patch([Cluster(name='replacement')]):
+      assert list(clusters) == ['replacement']
+      raise RuntimeError("exit contextmanager scope")
+
+  assert list(clusters) == ['original']


Mime
View raw message