Skip to content

Commit 8a7eb38

Browse files
authored
test(bigquery): simplify scripting system test to reduce flakiness (#9458)
No need to filter by time in the scripting system tests. Rather, we only care about filtering by parent job when testing those features. This addresses flakiness encountered: * https://source.cloud.google.com/results/invocations/a29867f9-6492-4477-85d4-d9de8d9ff85b/targets/cloud-devrel%2Fclient-libraries%2Fgoogle-cloud-python%2Fpresubmit%2Fbigquery/log * https://source.cloud.google.com/results/invocations/cdb77d4a-b0e3-4339-ab55-ae08fb2b297d/targets/cloud-devrel%2Fclient-libraries%2Fgoogle-cloud-python%2Fpresubmit%2Fbigquery/log
1 parent 37166af commit 8a7eb38

1 file changed

Lines changed: 7 additions & 24 deletions

File tree

bigquery/tests/system.py

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ def test_list_tables(self):
432432
self.assertGreater(len(list(iterator)), 0)
433433

434434
def test_listing_scripting_jobs(self):
435-
# run an SQL script
435+
# Run a SQL script.
436436
sql_script = """
437437
-- Declare a variable to hold names as an array.
438438
DECLARE top_names ARRAY<STRING>;
@@ -453,31 +453,14 @@ def test_listing_scripting_jobs(self):
453453
FROM `bigquery-public-data.samples.shakespeare`
454454
);
455455
"""
456-
test_start = datetime.datetime.utcnow()
457-
query_job = Config.CLIENT.query(sql_script, project=Config.CLIENT.project)
458-
query_job.result()
459-
460-
# fetch jobs created by the SQL script, sort them into parent and
461-
# child jobs
462-
script_jobs = list(Config.CLIENT.list_jobs(min_creation_time=test_start))
463-
464-
parent_jobs = []
465-
child_jobs = []
456+
parent_job = Config.CLIENT.query(sql_script, project=Config.CLIENT.project)
457+
parent_job.result()
466458

467-
for job in script_jobs:
468-
if job.num_child_jobs > 0:
469-
parent_jobs.append(job)
470-
else:
471-
child_jobs.append(job)
472-
473-
assert len(parent_jobs) == 1 # also implying num_child_jobs > 0
474-
assert len(child_jobs) == parent_jobs[0].num_child_jobs
459+
# Fetch jobs created by the SQL script.
460+
child_jobs = list(Config.CLIENT.list_jobs(parent_job=parent_job))
475461

476-
# fetch jobs using the parent job filter, verify that results are as expected
477-
fetched_jobs = list(Config.CLIENT.list_jobs(parent_job=parent_jobs[0]))
478-
assert sorted(job.job_id for job in fetched_jobs) == sorted(
479-
job.job_id for job in child_jobs
480-
)
462+
assert parent_job.num_child_jobs > 0
463+
assert len(child_jobs) == parent_job.num_child_jobs
481464

482465
def test_update_table(self):
483466
dataset = self.temp_dataset(_make_dataset_id("update_table"))

0 commit comments

Comments
 (0)