summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames E. Blair <jeblair@redhat.com>2018-01-17 07:57:54 -0800
committerJames E. Blair <jeblair@redhat.com>2018-01-17 09:53:18 -0800
commit185b970bad464037d68d19127b2b5ba076630b0b (patch)
tree62f149bee9e18a497c8b37c5dfb9c1ed9c26fef3
parent168a94117b30d9fbf79374c6f6c52be88bc5b8d7 (diff)
downloadzuul-185b970bad464037d68d19127b2b5ba076630b0b.tar.gz
Stabilize git driver tests
These tests relied on sleeps which can cause races when running the full test suite in parallel. Instead, wait for the events we know will happen to happen. Also remove the dependency on yarl now that aiohttp has made a release which works with yarl 1.0 (however, it does not work with <1.0 which is why this needs to be combined with this change to fix tests). Change-Id: Ib1c626cdd3f083dd1d23a3c6547bd7163b66567e
-rw-r--r--requirements.txt1
-rw-r--r--tests/unit/test_git_driver.py45
-rw-r--r--zuul/driver/git/gitconnection.py3
3 files changed, 33 insertions, 16 deletions
diff --git a/requirements.txt b/requirements.txt
index 193c64e71..39a2b0268 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -25,6 +25,5 @@ cryptography>=1.6
cachecontrol
pyjwt
iso8601
-yarl>=0.11,<1.0
aiohttp
uvloop;python_version>='3.5'
diff --git a/tests/unit/test_git_driver.py b/tests/unit/test_git_driver.py
index b9e6c6e92..e8762d0d2 100644
--- a/tests/unit/test_git_driver.py
+++ b/tests/unit/test_git_driver.py
@@ -24,6 +24,11 @@ class TestGitDriver(ZuulTestCase):
config_file = 'zuul-git-driver.conf'
tenant_config_file = 'config/git-driver/main.yaml'
+ def setUp(self):
+ super(TestGitDriver, self).setUp()
+ self.git_connection = self.sched.connections.getSource('git').\
+ connection
+
def setup_config(self):
super(TestGitDriver, self).setup_config()
self.config.set('connection git', 'baseurl', self.upstream_root)
@@ -70,8 +75,8 @@ class TestGitDriver(ZuulTestCase):
self.addCommitToRepo(
'common-config', 'Change zuul.yaml configuration', files)
- # Let some time for the tenant reconfiguration to happen
- time.sleep(2)
+ # Wait for the tenant reconfiguration to happen
+ count = self.waitForEvent()
self.waitUntilSettled()
A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
@@ -109,8 +114,8 @@ class TestGitDriver(ZuulTestCase):
# Restart the git watcher
self.sched.connections.getSource('git').connection.w_pause = False
- # Let some time for the tenant reconfiguration to happen
- time.sleep(2)
+ # Wait for the tenant reconfiguration to happen
+ self.waitForEvent(count)
self.waitUntilSettled()
A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
@@ -123,23 +128,33 @@ class TestGitDriver(ZuulTestCase):
def ensure_watcher_has_context(self):
# Make sure watcher have read initial refs shas
- cnx = self.sched.connections.getSource('git').connection
delay = 0.1
max_delay = 1
- while not cnx.projects_refs:
+ while not self.git_connection.projects_refs:
time.sleep(delay)
max_delay -= delay
if max_delay <= 0:
raise Exception("Timeout waiting for initial read")
+ return self.git_connection.watcher_thread._event_count
+
+ def waitForEvent(self, initial_count=0):
+ delay = 0.1
+ max_delay = 1
+ while self.git_connection.watcher_thread._event_count <= initial_count:
+ time.sleep(delay)
+ max_delay -= delay
+ if max_delay <= 0:
+ raise Exception("Timeout waiting for event")
+ return self.git_connection.watcher_thread._event_count
@simple_layout('layouts/basic-git.yaml', driver='git')
def test_ref_updated_event(self):
- self.ensure_watcher_has_context()
+ count = self.ensure_watcher_has_context()
# Add a commit to trigger a ref-updated event
self.addCommitToRepo(
'org/project', 'A change for ref-updated', {'f1': 'Content'})
- # Let some time for the git watcher to detect the ref-update event
- time.sleep(0.2)
+ # Wait for the git watcher to detect the ref-update event
+ self.waitForEvent(count)
self.waitUntilSettled()
self.assertEqual(len(self.history), 1)
self.assertEqual('SUCCESS',
@@ -147,12 +162,12 @@ class TestGitDriver(ZuulTestCase):
@simple_layout('layouts/basic-git.yaml', driver='git')
def test_ref_created(self):
- self.ensure_watcher_has_context()
+ count = self.ensure_watcher_has_context()
# Tag HEAD to trigger a ref-updated event
self.addTagToRepo(
'org/project', 'atag', 'HEAD')
- # Let some time for the git watcher to detect the ref-update event
- time.sleep(0.2)
+ # Wait for the git watcher to detect the ref-update event
+ self.waitForEvent(count)
self.waitUntilSettled()
self.assertEqual(len(self.history), 1)
self.assertEqual('SUCCESS',
@@ -160,12 +175,12 @@ class TestGitDriver(ZuulTestCase):
@simple_layout('layouts/basic-git.yaml', driver='git')
def test_ref_deleted(self):
- self.ensure_watcher_has_context()
+ count = self.ensure_watcher_has_context()
# Delete default tag init to trigger a ref-updated event
self.delTagFromRepo(
'org/project', 'init')
- # Let some time for the git watcher to detect the ref-update event
- time.sleep(0.2)
+ # Wait for the git watcher to detect the ref-update event
+ self.waitForEvent(count)
self.waitUntilSettled()
# Make sure no job as run as ignore-delete is True by default
self.assertEqual(len(self.history), 0)
diff --git a/zuul/driver/git/gitconnection.py b/zuul/driver/git/gitconnection.py
index 03b24cadc..1886cfcca 100644
--- a/zuul/driver/git/gitconnection.py
+++ b/zuul/driver/git/gitconnection.py
@@ -38,6 +38,8 @@ class GitWatcher(threading.Thread):
self.poll_delay = poll_delay
self._stopped = False
self.projects_refs = self.git_connection.projects_refs
+ # This is used by the test framework
+ self._event_count = 0
def compareRefs(self, project, refs):
partial_events = []
@@ -112,6 +114,7 @@ class GitWatcher(threading.Thread):
self.git_connection.logEvent(event)
# Pass the event to the scheduler
self.git_connection.sched.addEvent(event)
+ self._event_count += 1
except Exception as e:
self.log.debug("Unexpected issue in _run loop: %s" % str(e))