Skip to content

Commit 1a329eb

Browse files
author
remi Taylor
committed
Merge branch 'master' of github.com:GoogleCloudPlatform/ruby-docs-samples
2 parents 22b30f5 + ceccd32 commit 1a329eb

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

bigquery/spec/bigquery_sample_spec.rb

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,15 @@ def capture &block
8888
end
8989
attr_reader :captured_output
9090

91+
# Simple wait method. Test for condition 5 times, delaying 1 second each time
92+
def wait_until times: 5, delay: 1, &condition
93+
times.times do
94+
return if condition.call
95+
sleep delay
96+
end
97+
raise "Condition not met. Waited #{times} times with #{delay} sec delay"
98+
end
99+
91100
example "create BigQuery client" do
92101
client = create_bigquery_client project_id: @project_id
93102

@@ -275,7 +284,12 @@ def capture &block
275284
"Inserted rows successfully\n"
276285
).to_stdout
277286

278-
loaded_data = @table.data
287+
loaded_data = nil
288+
289+
wait_until do
290+
loaded_data = @table.data
291+
loaded_data.any?
292+
end
279293

280294
expect(loaded_data).not_to be_empty
281295
expect(loaded_data.count).to eq 2

0 commit comments

Comments
 (0)