Skip to content

Commit f720e2a

Browse files
Add tests.
1 parent 7391cda commit f720e2a

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
@@ -8,11 +8,17 @@
88
require "async/container/controllers"
99

1010
require "tmpdir"
11+
require "bake"
1112

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

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

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

0 commit comments

Comments
 (0)