Skip to content

Commit 24e84d9

Browse files
samuel-williams-shopifyioquatix
authored andcommitted
Add tests.
1 parent a709682 commit 24e84d9

File tree

1 file changed

+32
-1
lines changed
  • test/async/container/notify

1 file changed

+32
-1
lines changed

test/async/container/notify/log.rb

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,17 @@
77
require "async/container/controllers"
88

99
require "tmpdir"
10+
require "bake"
1011

11-
describe Async::Container::Notify::Pipe do
12+
describe Async::Container::Notify::Log do
1213
let(:notify_script) {Async::Container::Controllers.path_for("notify")}
1314
let(:notify_log) {File.expand_path("notify-#{::Process.pid}-#{SecureRandom.hex(8)}.log", Dir.tmpdir)}
15+
let(:notify) {Async::Container::Notify::Log.open!({"NOTIFY_LOG" => notify_log})}
1416

17+
after do
18+
File.unlink(notify_log) rescue nil
19+
end
20+
1521
it "receives notification of child status" do
1622
system({"NOTIFY_LOG" => notify_log}, "bundle", "exec", notify_script)
1723

@@ -22,4 +28,29 @@
2228
"size" => be > 0,
2329
)
2430
end
31+
32+
with "async:container:notify:log:ready?" do
33+
let(:context) {Bake::Context.load}
34+
let(:recipe) {context.lookup("async:container:notify:log:ready?")}
35+
36+
it "fails if the log file does not exist" do
37+
expect do
38+
recipe.call(path: "nonexistant.log")
39+
end.to raise_exception(RuntimeError, message: be =~ /log file does not exist/i)
40+
end
41+
42+
it "succeeds if the log file exists and is ready" do
43+
notify.ready!
44+
45+
expect(recipe.call(path: notify_log)).to be == true
46+
end
47+
48+
it "fails if the log file exists but is not ready" do
49+
notify.status!("Loading...")
50+
51+
expect do
52+
expect(recipe.call(path: notify_log))
53+
end.to raise_exception(RuntimeError, message: be =~ /service is not ready/i)
54+
end
55+
end
2556
end

0 commit comments

Comments
 (0)