diff options
author | James E. Blair <jim@acmegating.com> | 2021-11-03 17:15:47 -0700 |
---|---|---|
committer | James E. Blair <jim@acmegating.com> | 2021-11-03 17:15:47 -0700 |
commit | a836575c60c30a864548744bcfe5b0f2d0484b65 (patch) | |
tree | 7220c3e0d7bc8e31931a89a1b995f65c42656443 /tests/unit/test_zk.py | |
parent | 0840a9dfc9a9f88fbe3788e7d5c367231edfe9c5 (diff) | |
download | zuul-a836575c60c30a864548744bcfe5b0f2d0484b65.tar.gz |
Store connection branch cache in ZK
This will allow us to sync the branch cache to other participants
via ZK.
Change-Id: I75b2436008e7bc44e086abe680d8b98cf73102f8
Diffstat (limited to 'tests/unit/test_zk.py')
-rw-r--r-- | tests/unit/test_zk.py | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/tests/unit/test_zk.py b/tests/unit/test_zk.py index a50334bd8..0fc27237d 100644 --- a/tests/unit/test_zk.py +++ b/tests/unit/test_zk.py @@ -22,6 +22,7 @@ import testtools from zuul import model from zuul.model import BuildRequest, HoldRequest, MergeRequest from zuul.zk import ZooKeeperClient +from zuul.zk.branch_cache import BranchCache from zuul.zk.change_cache import ( AbstractChangeCache, ChangeKey, @@ -1586,3 +1587,74 @@ class TestZKObject(ZooKeeperBaseTestCase): def test_sharded_zk_object_exception(self): self._test_zk_object_exception(DummyShardedZKObject) + + +class TestBranchCache(ZooKeeperBaseTestCase): + def test_branch_cache(self): + conn = DummyConnection() + cache = BranchCache(self.zk_client, conn) + + test_data = { + 'project1': { + 'all': ['protected1', 'protected2', + 'unprotected1', 'unprotected2'], + 'protected': ['protected1', 'protected2'], + }, + } + + # Test a protected-only query followed by all + cache.setProjectBranches('project1', True, + test_data['project1']['protected']) + self.assertEqual( + sorted(cache.getProjectBranches('project1', True)), + test_data['project1']['protected'] + ) + self.assertEqual( + cache.getProjectBranches('project1', False), + None, + ) + + cache.setProjectBranches('project1', False, + test_data['project1']['all']) + self.assertEqual( + sorted(cache.getProjectBranches('project1', True)), + test_data['project1']['protected'] + ) + self.assertEqual( + sorted(cache.getProjectBranches('project1', False)), + test_data['project1']['all'] + ) + + # Clear them to start over + cache.clearProjectCache('project1') + self.assertEqual( + cache.getProjectBranches('project1', True), + None + ) + self.assertEqual( + cache.getProjectBranches('project1', False), + None + ) + + # Test the other order; all followed by protected-only + cache.setProjectBranches('project1', False, + test_data['project1']['all']) + self.assertEqual( + cache.getProjectBranches('project1', True), + None + ) + self.assertEqual( + sorted(cache.getProjectBranches('project1', False)), + test_data['project1']['all'] + ) + + cache.setProjectBranches('project1', True, + test_data['project1']['protected']) + self.assertEqual( + sorted(cache.getProjectBranches('project1', True)), + test_data['project1']['protected'] + ) + self.assertEqual( + sorted(cache.getProjectBranches('project1', False)), + test_data['project1']['all'] + ) |