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 44# Copyright, 2020-2024, by Samuel Williams.
55
66require_relative "client"
7+ require "socket"
78
89module 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
Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff line change 55# Copyright, 2020, by Olle Jonsson.
66
77require "async/container/controller"
8+ require "async/container/controllers"
89
910describe 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
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