@@ -250,6 +250,21 @@ def make_mixed_dataframe_v2(test_size):
250
250
index = range (test_size ))
251
251
252
252
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
+
253
268
def test_generate_bq_schema_deprecated ():
254
269
# 11121 Deprecation of generate_bq_schema
255
270
with tm .assert_produces_warning (FutureWarning ):
@@ -1019,7 +1034,7 @@ def test_upload_data(self):
1019
1034
gbq .to_gbq (df , self .destination_table + test_id , _get_project_id (),
1020
1035
chunksize = 10000 , private_key = _get_private_key_path ())
1021
1036
1022
- sleep ( 30 ) # <- Curses Google!!!
1037
+ wait_for_job ()
1023
1038
1024
1039
result = gbq .read_gbq ("SELECT COUNT(*) AS num_rows FROM {0}"
1025
1040
.format (self .destination_table + test_id ),
@@ -1057,7 +1072,7 @@ def test_upload_data_if_table_exists_append(self):
1057
1072
gbq .to_gbq (df , self .destination_table + test_id , _get_project_id (),
1058
1073
if_exists = 'append' , private_key = _get_private_key_path ())
1059
1074
1060
- sleep ( 30 ) # <- Curses Google!!!
1075
+ wait_for_job ()
1061
1076
1062
1077
result = gbq .read_gbq ("SELECT COUNT(*) AS num_rows FROM {0}"
1063
1078
.format (self .destination_table + test_id ),
@@ -1088,7 +1103,7 @@ def test_upload_subset_columns_if_table_exists_append(self):
1088
1103
self .destination_table + test_id , _get_project_id (),
1089
1104
if_exists = 'append' , private_key = _get_private_key_path ())
1090
1105
1091
- sleep ( 30 ) # <- Curses Google!!!
1106
+ wait_for_job ()
1092
1107
1093
1108
result = gbq .read_gbq ("SELECT COUNT(*) AS num_rows FROM {0}"
1094
1109
.format (self .destination_table + test_id ),
@@ -1111,7 +1126,7 @@ def test_upload_data_if_table_exists_replace(self):
1111
1126
_get_project_id (), if_exists = 'replace' ,
1112
1127
private_key = _get_private_key_path ())
1113
1128
1114
- sleep ( 30 ) # <- Curses Google!!!
1129
+ wait_for_job ()
1115
1130
1116
1131
result = gbq .read_gbq ("SELECT COUNT(*) AS num_rows FROM {0}"
1117
1132
.format (self .destination_table + test_id ),
@@ -1445,7 +1460,7 @@ def test_upload_data(self):
1445
1460
gbq .to_gbq (df , self .destination_table + test_id , _get_project_id (),
1446
1461
chunksize = 10000 )
1447
1462
1448
- sleep ( 30 ) # <- Curses Google!!!
1463
+ wait_for_job ()
1449
1464
1450
1465
result = gbq .read_gbq ("SELECT COUNT(*) AS num_rows FROM {0}" .format (
1451
1466
self .destination_table + test_id ),
@@ -1503,7 +1518,7 @@ def test_upload_data(self):
1503
1518
gbq .to_gbq (df , self .destination_table + test_id , _get_project_id (),
1504
1519
chunksize = 10000 , private_key = _get_private_key_contents ())
1505
1520
1506
- sleep ( 30 ) # <- Curses Google!!!
1521
+ wait_for_job ()
1507
1522
1508
1523
result = gbq .read_gbq ("SELECT COUNT(*) as num_rows FROM {0}" .format (
1509
1524
self .destination_table + test_id ),
0 commit comments