def test_column_fetch_slow(self): mock_response_future = Future() mock_response_future.executed = False # noinspection PyUnusedLocal def upon_execute( query ): # Parameter required since function is passed as Callable[[RecordedQuery], None] mock_response_future.result() mock_response_future.executed = True try: mock_kusto_client = MockKustoClient(upon_execute=upon_execute, record_metadata=True) table = PyKustoClient( mock_kusto_client, fetch_by_default=False)['test_db']['mock_table'] table.refresh() self.assertEqual(type(table['foo']), _AnyTypeColumn) self.assertEqual(type(table['bar']), _AnyTypeColumn) self.assertEqual(type(table['baz']), _AnyTypeColumn) # Make sure above lines were called while the fetch query was still waiting assert not mock_response_future.executed finally: # Return the fetch mock_response_future.set_result(None) table.wait_for_items() # Make sure the fetch query was indeed called assert mock_response_future.executed
def test_query_before_fetch_returned(self): mock_response_future = Future() mock_response_future.returned_queries = [] mock_response_future.called = False mock_response_future.executed = False future_called_lock = Lock() def upon_execute(query): with future_called_lock: if mock_response_future.called: first_run = False else: mock_response_future.called = True first_run = True if first_run: mock_response_future.result() mock_response_future.executed = True mock_response_future.returned_queries.append(query) try: mock_kusto_client = MockKustoClient(upon_execute=upon_execute, record_metadata=True) table = PyKustoClient( mock_kusto_client, fetch_by_default=False)['test_db']['mock_table'] table.refresh() # Executing a query in a separate thread, because it is supposed to block until the fetch returns query_thread = Thread(target=Query(table).take(5).execute) query_thread.start() # Make sure above lines were called while the fetch query was still waiting assert not mock_response_future.executed finally: # Return the fetch mock_response_future.set_result(None) table.wait_for_items() query_thread.join() # Make sure the fetch query was indeed called assert mock_response_future.executed # Before the fix the order of returned query was reversed self.assertEqual( [ RecordedQuery( 'test_db', '.show table mock_table | project AttributeName, AttributeType | limit 10000' ), RecordedQuery('test_db', 'mock_table | take 5'), ], mock_response_future.returned_queries, )