def test_db_query_get_result(self): """pop in db_query shouldn't pop from result itself""" self.client[:].apply_sync(lambda : 1) found = self.client.db_query({'msg_id': {'$ne' : ''}}) rc2 = clientmod.Client(profile='iptest') # If this bug is not fixed, this call will hang: ar = rc2.get_result(self.client.history[-1]) ar.wait(2) self.assertTrue(ar.ready()) ar.get() rc2.close()
def test_get_result(self): """test getting results from the Hub.""" c = clientmod.Client(profile='iptest') t = c.ids[-1] ar = c[t].apply_async(wait, 1) # give the monitor time to notice the message time.sleep(.25) ahr = self.client.get_result(ar.msg_ids) self.assertTrue(isinstance(ahr, AsyncHubResult)) self.assertEquals(ahr.get(), ar.get()) ar2 = self.client.get_result(ar.msg_ids) self.assertFalse(isinstance(ar2, AsyncHubResult)) c.close()
def test_get_execute_result(self): """test getting execute results from the Hub.""" c = clientmod.Client(profile='iptest') t = c.ids[-1] cell = '\n'.join(['import time', 'time.sleep(0.25)', '5']) ar = c[t].execute("import time; time.sleep(1)", silent=False) # give the monitor time to notice the message time.sleep(.25) ahr = self.client.get_result(ar.msg_ids[0]) self.assertTrue(isinstance(ahr, AsyncHubResult)) self.assertEqual(ahr.get().pyout, ar.get().pyout) ar2 = self.client.get_result(ar.msg_ids[0]) self.assertFalse(isinstance(ar2, AsyncHubResult)) c.close()
def test_purge_results(self): # ensure there are some tasks for i in range(5): self.client[:].apply_sync(lambda : 1) # Wait for the Hub to realise the result is done: # This prevents a race condition, where we # might purge a result the Hub still thinks is pending. time.sleep(0.1) rc2 = clientmod.Client(profile='iptest') hist = self.client.hub_history() ahr = rc2.get_result([hist[-1]]) ahr.wait(10) self.client.purge_results(hist[-1]) newhist = self.client.hub_history() self.assertEquals(len(newhist)+1,len(hist)) rc2.spin() rc2.close()