Make timer tests less racy
Change-Id: I9f731608427ce90769e29e041f6cc5738c512836
diff --git a/tests/unit/test_executor.py b/tests/unit/test_executor.py
index 46f3b26..444d783 100755
--- a/tests/unit/test_executor.py
+++ b/tests/unit/test_executor.py
@@ -277,6 +277,11 @@
'layouts/repo-checkout-no-timer-override.yaml')
self.sched.reconfigure(self.config)
self.waitUntilSettled()
+ # If APScheduler is in mid-event when we remove the job, we
+ # can end up with one more event firing, so give it an extra
+ # second to settle.
+ time.sleep(1)
+ self.waitUntilSettled()
self.assertEquals(1, len(self.builds), "One build is running")
@@ -315,6 +320,11 @@
'layouts/repo-checkout-no-timer.yaml')
self.sched.reconfigure(self.config)
self.waitUntilSettled()
+ # If APScheduler is in mid-event when we remove the job, we
+ # can end up with one more event firing, so give it an extra
+ # second to settle.
+ time.sleep(1)
+ self.waitUntilSettled()
self.assertEquals(2, len(self.builds), "Two builds are running")
diff --git a/tests/unit/test_scheduler.py b/tests/unit/test_scheduler.py
index 2b1a30f..c168823 100755
--- a/tests/unit/test_scheduler.py
+++ b/tests/unit/test_scheduler.py
@@ -1892,6 +1892,11 @@
self.commitConfigUpdate('common-config', 'layouts/no-timer.yaml')
self.sched.reconfigure(self.config)
self.waitUntilSettled()
+ # If APScheduler is in mid-event when we remove the job, we
+ # can end up with one more event firing, so give it an extra
+ # second to settle.
+ time.sleep(1)
+ self.waitUntilSettled()
self.assertEqual(len(self.builds), 1, "One timer job")
@@ -2855,6 +2860,12 @@
# below don't race against more jobs being queued.
self.commitConfigUpdate('common-config', 'layouts/no-timer.yaml')
self.sched.reconfigure(self.config)
+ self.waitUntilSettled()
+ # If APScheduler is in mid-event when we remove the job, we
+ # can end up with one more event firing, so give it an extra
+ # second to settle.
+ time.sleep(1)
+ self.waitUntilSettled()
self.executor_server.release()
self.waitUntilSettled()
@@ -2902,6 +2913,11 @@
'layouts/no-timer.yaml')
self.sched.reconfigure(self.config)
self.waitUntilSettled()
+ # If APScheduler is in mid-event when we remove the job,
+ # we can end up with one more event firing, so give it an
+ # extra second to settle.
+ time.sleep(1)
+ self.waitUntilSettled()
self.assertEqual(len(self.builds), 1,
'Timer builds iteration #%d' % x)
self.executor_server.release('.*')
@@ -2980,6 +2996,11 @@
self.commitConfigUpdate('common-config', 'layouts/no-timer.yaml')
self.sched.reconfigure(self.config)
self.waitUntilSettled()
+ # If APScheduler is in mid-event when we remove the job, we
+ # can end up with one more event firing, so give it an extra
+ # second to settle.
+ time.sleep(1)
+ self.waitUntilSettled()
self.executor_server.release('.*')
self.waitUntilSettled()
@@ -3024,6 +3045,11 @@
self.sched.reconfigure(self.config)
self.registerJobs()
self.waitUntilSettled()
+ # If APScheduler is in mid-event when we remove the job, we
+ # can end up with one more event firing, so give it an extra
+ # second to settle.
+ time.sleep(1)
+ self.waitUntilSettled()
self.worker.release('.*')
self.waitUntilSettled()