summaryrefslogtreecommitdiff
path: root/tests/unit/test_zk.py
diff options
context:
space:
mode:
authorJames E. Blair <jim@acmegating.com>2021-11-04 15:57:00 -0700
committerJames E. Blair <jim@acmegating.com>2021-11-05 09:20:00 -0700
commit15f0965dab1ca86ec17f6602948ae33af932dba3 (patch)
tree0deefaa89925a49d25d7d19953acfce99fed15b4 /tests/unit/test_zk.py
parent9cf8b6f7d056eb927a70608e818c26c78a412791 (diff)
downloadzuul-15f0965dab1ca86ec17f6602948ae33af932dba3.tar.gz
Don't clear branch cache
This keeps the branch cache continuously populated. When part of the cache is invalidated by a branch creation/deletion event, instead of clearing the cache, this updates the data. That can be slightly more efficient in that it may reduce the number of ZK transactions, and it may also help us when adding layout loading to zuul-web, in that those connections will not need to make any remote calls to the code review system. Change-Id: I0ad3ea0ecab50ae5261f9510e34ffb27ca83ac1e
Diffstat (limited to 'tests/unit/test_zk.py')
-rw-r--r--tests/unit/test_zk.py69
1 files changed, 66 insertions, 3 deletions
diff --git a/tests/unit/test_zk.py b/tests/unit/test_zk.py
index 9ed950282..e74117ac6 100644
--- a/tests/unit/test_zk.py
+++ b/tests/unit/test_zk.py
@@ -1599,7 +1599,7 @@ class TestZKObject(ZooKeeperBaseTestCase):
class TestBranchCache(ZooKeeperBaseTestCase):
- def test_branch_cache(self):
+ def test_branch_cache_protected_then_all(self):
conn = DummyConnection()
cache = BranchCache(self.zk_client, conn)
@@ -1634,8 +1634,18 @@ class TestBranchCache(ZooKeeperBaseTestCase):
test_data['project1']['all']
)
- # Clear them to start over
- cache.clearProjectCache('project1')
+ def test_branch_cache_all_then_protected(self):
+ conn = DummyConnection()
+ cache = BranchCache(self.zk_client, conn)
+
+ test_data = {
+ 'project1': {
+ 'all': ['protected1', 'protected2',
+ 'unprotected1', 'unprotected2'],
+ 'protected': ['protected1', 'protected2'],
+ },
+ }
+
self.assertEqual(
cache.getProjectBranches('project1', True),
None
@@ -1667,3 +1677,56 @@ class TestBranchCache(ZooKeeperBaseTestCase):
sorted(cache.getProjectBranches('project1', False)),
test_data['project1']['all']
)
+
+ def test_branch_cache_change_protected(self):
+ conn = DummyConnection()
+ cache = BranchCache(self.zk_client, conn)
+
+ data1 = {
+ 'project1': {
+ 'all': ['newbranch', 'protected'],
+ 'protected': ['protected'],
+ },
+ }
+ data2 = {
+ 'project1': {
+ 'all': ['newbranch', 'protected'],
+ 'protected': ['newbranch', 'protected'],
+ },
+ }
+
+ # Create a new unprotected branch
+ cache.setProjectBranches('project1', False,
+ data1['project1']['all'])
+ cache.setProjectBranches('project1', True,
+ data1['project1']['protected'])
+ self.assertEqual(
+ cache.getProjectBranches('project1', True),
+ data1['project1']['protected']
+ )
+ self.assertEqual(
+ sorted(cache.getProjectBranches('project1', False)),
+ data1['project1']['all']
+ )
+
+ # Change it to protected
+ cache.setProtected('project1', 'newbranch', True)
+ self.assertEqual(
+ sorted(cache.getProjectBranches('project1', True)),
+ data2['project1']['protected']
+ )
+ self.assertEqual(
+ sorted(cache.getProjectBranches('project1', False)),
+ data2['project1']['all']
+ )
+
+ # Change it back
+ cache.setProtected('project1', 'newbranch', False)
+ self.assertEqual(
+ sorted(cache.getProjectBranches('project1', True)),
+ data1['project1']['protected']
+ )
+ self.assertEqual(
+ sorted(cache.getProjectBranches('project1', False)),
+ data1['project1']['all']
+ )