def test_simulate_multiple_sync_threads_at_sametime(self): # Simulate a syncthread was created and hasn't finished yet key = SyncRHICServeThread.__name__ # Skipping lock on identity.JOBS dummy_job = SyncRHICServeThread() identity.JOBS[key] = dummy_job # This thread is not in a finished state, therefore next job we try to create should return None # and do nothing, letting this job finish sync_thread = sync_from_rhic_serve() self.assertIsNone(sync_thread) # Now we simulate the job finishing and cleaning up it's reference dummy_job.remove_reference() # Ensure JOBS has been cleanedup self.assertEqual(len(identity.JOBS), 0)
def test_sync_from_rhic_serve_threaded(self): self.assertEqual(len(identity.JOBS), 0) rhics = ConsumerIdentity.objects() self.assertEquals(len(rhics), 0) sync_thread = sync_from_rhic_serve() for index in range(0,120): if not sync_thread.finished: time.sleep(.05) self.assertTrue(sync_thread.finished) rhics = ConsumerIdentity.objects() self.assertEquals(len(rhics), 3) expected_rhics = ["fb647f68-aa01-4171-b62b-35c2984a5328", "ef8548a9-c874-42a8-b5dc-bc5ab0b34cd7", "a17013d8-e896-4749-9b37-8606d62bf643"] for r in rhics: self.assertIn(str(r.uuid), expected_rhics)