Skip to content

Commit 7e1e4a8

Browse files
committed
More code coverage for notify.
1 parent 3042fa8 commit 7e1e4a8

File tree

5 files changed

+44
-2
lines changed

5 files changed

+44
-2
lines changed

lib/async/container/notify/socket.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# Copyright, 2020-2024, by Samuel Williams.
55

66
require_relative "client"
7+
require "socket"
78

89
module Async
910
module Container
@@ -31,6 +32,9 @@ def initialize(path)
3132
@address = Addrinfo.unix(path, ::Socket::SOCK_DGRAM)
3233
end
3334

35+
# @attribute [String] The path to the UNIX socket used for sending messages to the controller.
36+
attr :path
37+
3438
# Dump a message in the format requied by `sd_notify`.
3539
# @parameter message [Hash] Keys and values should be string convertible objects. Values which are `true`/`false` are converted to `1`/`0` respectively.
3640
def dump(message)
@@ -69,7 +73,7 @@ def send(**message)
6973
def error!(text, **message)
7074
message[:errno] ||= -1
7175

72-
send(status: text, **message)
76+
super
7377
end
7478
end
7579
end

test/async/container/notify.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,26 @@
5151
end
5252
end
5353

54+
with "#send" do
55+
it "sends message" do
56+
context = server.bind
57+
58+
client.send(hello: "world")
59+
60+
message = context.receive
61+
62+
expect(message).to be == {hello: "world"}
63+
end
64+
65+
it "fails if the message is too big" do
66+
context = server.bind
67+
68+
expect do
69+
client.send("x" * (subject::Socket::MAXIMUM_MESSAGE_SIZE+1))
70+
end.to raise_exception(ArgumentError)
71+
end
72+
end
73+
5474
with "#stopping!" do
5575
it "sends stopping message" do
5676
context = server.bind

test/async/container/notify/pipe.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
# Copyright, 2020, by Olle Jonsson.
66

77
require "async/container/controller"
8+
require "async/container/controllers"
89

910
describe Async::Container::Notify::Pipe do
10-
let(:notify_script) {File.expand_path(".notify.rb", __dir__)}
11+
let(:notify_script) {Async::Container::Controllers.path_for("notify")}
1112

1213
it "receives notification of child status" do
1314
container = Async::Container.new

test/async/container/notify/socket.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# frozen_string_literal: true
2+
3+
# Released under the MIT License.
4+
# Copyright, 2020-2025, by Samuel Williams.
5+
# Copyright, 2020, by Olle Jonsson.
6+
7+
require "async/container/notify/socket"
8+
9+
describe Async::Container::Notify::Socket do
10+
with ".open!" do
11+
it "can open a socket" do
12+
socket = subject.open!({subject::NOTIFY_SOCKET => "test"})
13+
14+
expect(socket).to have_attributes(path: be == "test")
15+
end
16+
end
17+
end

0 commit comments

Comments
 (0)