File tree Expand file tree Collapse file tree 5 files changed +44
-2
lines changed
fixtures/async/container/controllers
lib/async/container/notify Expand file tree Collapse file tree 5 files changed +44
-2
lines changed File renamed without changes.
Original file line number Diff line number Diff line change 4
4
# Copyright, 2020-2024, by Samuel Williams.
5
5
6
6
require_relative "client"
7
+ require "socket"
7
8
8
9
module Async
9
10
module Container
@@ -31,6 +32,9 @@ def initialize(path)
31
32
@address = Addrinfo . unix ( path , ::Socket ::SOCK_DGRAM )
32
33
end
33
34
35
+ # @attribute [String] The path to the UNIX socket used for sending messages to the controller.
36
+ attr :path
37
+
34
38
# Dump a message in the format requied by `sd_notify`.
35
39
# @parameter message [Hash] Keys and values should be string convertible objects. Values which are `true`/`false` are converted to `1`/`0` respectively.
36
40
def dump ( message )
@@ -69,7 +73,7 @@ def send(**message)
69
73
def error! ( text , **message )
70
74
message [ :errno ] ||= -1
71
75
72
- send ( status : text , ** message )
76
+ super
73
77
end
74
78
end
75
79
end
Original file line number Diff line number Diff line change 51
51
end
52
52
end
53
53
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
+
54
74
with "#stopping!" do
55
75
it "sends stopping message" do
56
76
context = server . bind
Original file line number Diff line number Diff line change 5
5
# Copyright, 2020, by Olle Jonsson.
6
6
7
7
require "async/container/controller"
8
+ require "async/container/controllers"
8
9
9
10
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" ) }
11
12
12
13
it "receives notification of child status" do
13
14
container = Async ::Container . new
Original file line number Diff line number Diff line change
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
You can’t perform that action at this time.
0 commit comments