Skip to content

Commit 01cd1d8

Browse files
author
Frank Natividad
committed
Added wait_until helper function and removed direct call to sleep
1 parent e522da5 commit 01cd1d8

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

logging/spec/quickstart_spec.rb

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,15 @@
1717

1818
describe "Logging Quickstart" do
1919

20+
# Simple wait method. Test for condition 5 times, delaying 1 second each time
21+
def wait_until times: 5, delay: 1, &condition
22+
times.times do
23+
return if condition.call
24+
sleep delay
25+
end
26+
raise "Condition not met. Waited #{times} times with #{delay} sec delay"
27+
end
28+
2029
it "logs a new entry" do
2130
entry_filter = 'logName:"my-log" textPayload:"Hello, world!"'
2231
gcloud = Google::Cloud.new ENV["GOOGLE_CLOUD_PROJECT"]
@@ -38,7 +47,9 @@
3847
"Logged Hello, world!\n"
3948
).to_stdout
4049

41-
sleep(5)
50+
wait_until(delay: 2) do
51+
logging.entries(filter: entry_filter).any?
52+
end
4253

4354
entries = logging.entries filter: entry_filter
4455
expect(entries).to_not be_empty

0 commit comments

Comments
 (0)