def test_begin_and_wait_start_jobs(self, patched_bigquery_QueryJob,
     patched_time_sleep):
   # NB: bypass the time.sleep wait, otherwise the test will take ages
   patched_time_sleep.side_effect = lambda delay: delay
   worker = workers.BQWorker({}, 1, 1)
   job0 = patched_bigquery_QueryJob()
   job0.begin.side_effect = lambda: True
   def _mark_as_done():
     job0.state = 'DONE'
   job0.reload.side_effect = _mark_as_done
   job0.error_result = None
   worker._begin_and_wait(job0)
   job0.begin.assert_called_once()
 def test_begin_and_wait_enqueue_bqwaiter_after_some_time(self,
     patched_BQWorker_enqueue, patched_bigquery_QueryJob, patched_time_sleep):
   # NB: bypass the time.sleep wait, otherwise the test will take ages
   patched_time_sleep.side_effect = lambda delay: delay
   def _fake_enqueue(*args, **kwargs):
     # Do Nothing
     return True
   patched_BQWorker_enqueue.side_effect = _fake_enqueue
   worker = workers.BQWorker({'bq_project_id': 'BQID'}, 1, 1)
   job0 = patched_bigquery_QueryJob()
   job0.error_result = None
   worker._begin_and_wait(job0)
   patched_BQWorker_enqueue.assert_called_once()
   self.assertEqual(patched_BQWorker_enqueue.call_args[0][0], 'BQWaiter')
   self.assertIsInstance(patched_BQWorker_enqueue.call_args[0][1], dict)