Skip to content

Commit 8726a01

Browse files
committed
Use wait_for_job rather than sleep
1 parent 7eee379 commit 8726a01

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

pandas_gbq/tests/test_gbq.py

+21-6
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,21 @@ def make_mixed_dataframe_v2(test_size):
250250
index=range(test_size))
251251

252252

253+
def wait_for_job(job):
254+
255+
# from
256+
# https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/bigquery/cloud-client/snippets.py
257+
258+
while True:
259+
job.reload() # Refreshes the state via a GET request.
260+
if job.state == 'DONE':
261+
if job.error_result:
262+
raise RuntimeError(job.errors)
263+
return
264+
logging.info("Waiting for {} to complete".format(job))
265+
sleep(1)
266+
267+
253268
def test_generate_bq_schema_deprecated():
254269
# 11121 Deprecation of generate_bq_schema
255270
with tm.assert_produces_warning(FutureWarning):
@@ -1019,7 +1034,7 @@ def test_upload_data(self):
10191034
gbq.to_gbq(df, self.destination_table + test_id, _get_project_id(),
10201035
chunksize=10000, private_key=_get_private_key_path())
10211036

1022-
sleep(30) # <- Curses Google!!!
1037+
wait_for_job()
10231038

10241039
result = gbq.read_gbq("SELECT COUNT(*) AS num_rows FROM {0}"
10251040
.format(self.destination_table + test_id),
@@ -1057,7 +1072,7 @@ def test_upload_data_if_table_exists_append(self):
10571072
gbq.to_gbq(df, self.destination_table + test_id, _get_project_id(),
10581073
if_exists='append', private_key=_get_private_key_path())
10591074

1060-
sleep(30) # <- Curses Google!!!
1075+
wait_for_job()
10611076

10621077
result = gbq.read_gbq("SELECT COUNT(*) AS num_rows FROM {0}"
10631078
.format(self.destination_table + test_id),
@@ -1088,7 +1103,7 @@ def test_upload_subset_columns_if_table_exists_append(self):
10881103
self.destination_table + test_id, _get_project_id(),
10891104
if_exists='append', private_key=_get_private_key_path())
10901105

1091-
sleep(30) # <- Curses Google!!!
1106+
wait_for_job()
10921107

10931108
result = gbq.read_gbq("SELECT COUNT(*) AS num_rows FROM {0}"
10941109
.format(self.destination_table + test_id),
@@ -1111,7 +1126,7 @@ def test_upload_data_if_table_exists_replace(self):
11111126
_get_project_id(), if_exists='replace',
11121127
private_key=_get_private_key_path())
11131128

1114-
sleep(30) # <- Curses Google!!!
1129+
wait_for_job()
11151130

11161131
result = gbq.read_gbq("SELECT COUNT(*) AS num_rows FROM {0}"
11171132
.format(self.destination_table + test_id),
@@ -1445,7 +1460,7 @@ def test_upload_data(self):
14451460
gbq.to_gbq(df, self.destination_table + test_id, _get_project_id(),
14461461
chunksize=10000)
14471462

1448-
sleep(30) # <- Curses Google!!!
1463+
wait_for_job()
14491464

14501465
result = gbq.read_gbq("SELECT COUNT(*) AS num_rows FROM {0}".format(
14511466
self.destination_table + test_id),
@@ -1503,7 +1518,7 @@ def test_upload_data(self):
15031518
gbq.to_gbq(df, self.destination_table + test_id, _get_project_id(),
15041519
chunksize=10000, private_key=_get_private_key_contents())
15051520

1506-
sleep(30) # <- Curses Google!!!
1521+
wait_for_job()
15071522

15081523
result = gbq.read_gbq("SELECT COUNT(*) as num_rows FROM {0}".format(
15091524
self.destination_table + test_id),

0 commit comments

Comments
 (0)