|
12 | 12 | let(:server) {subject::Server.open} |
13 | 13 | let(:notify_socket) {server.path} |
14 | 14 | let(:client) {subject::Socket.new(notify_socket)} |
15 | | - |
| 15 | + |
16 | 16 | it "can send and receive messages" do |
17 | 17 | context = server.bind |
18 | | - |
| 18 | + |
19 | 19 | client.send(hello: "world", count: 42) |
20 | | - |
| 20 | + |
21 | 21 | message = context.receive |
22 | | - |
| 22 | + |
23 | 23 | # Custom fields are transmitted as strings per the systemd protocol |
24 | 24 | expect(message).to be == {hello: "world", count: "42"} |
25 | 25 | end |
26 | | - |
| 26 | + |
27 | 27 | with "#ready!" do |
28 | 28 | it "should send message" do |
29 | 29 | begin |
30 | 30 | context = server.bind |
31 | | - |
| 31 | + |
32 | 32 | pid = fork do |
33 | 33 | client.ready! |
34 | 34 | end |
35 | | - |
| 35 | + |
36 | 36 | messages = [] |
37 | | - |
| 37 | + |
38 | 38 | Sync do |
39 | 39 | context.receive do |message, address| |
40 | 40 | messages << message |
41 | 41 | break |
42 | 42 | end |
43 | 43 | end |
44 | | - |
| 44 | + |
45 | 45 | expect(messages.last).to have_keys( |
46 | 46 | ready: be == true |
47 | 47 | ) |
|
51 | 51 | end |
52 | 52 | end |
53 | 53 | end |
54 | | - |
| 54 | + |
55 | 55 | with "#healthy!" do |
56 | 56 | it "sends healthy message" do |
57 | 57 | context = server.bind |
58 | | - |
| 58 | + |
59 | 59 | client.healthy! |
60 | | - |
| 60 | + |
61 | 61 | message = context.receive |
62 | | - |
| 62 | + |
63 | 63 | expect(message).to have_keys( |
64 | 64 | healthy: be == true |
65 | 65 | ) |
66 | 66 | end |
67 | | - |
| 67 | + |
68 | 68 | it "sends healthy message with additional details" do |
69 | 69 | context = server.bind |
70 | | - |
| 70 | + |
71 | 71 | client.healthy!(status: "All systems operational", uptime: 3600) |
72 | | - |
| 72 | + |
73 | 73 | message = context.receive |
74 | | - |
| 74 | + |
75 | 75 | expect(message).to have_keys( |
76 | 76 | healthy: be == true, |
77 | 77 | status: be == "All systems operational", |
78 | 78 | uptime: be == "3600" |
79 | 79 | ) |
80 | 80 | end |
81 | 81 | end |
82 | | - |
| 82 | + |
83 | 83 | with "#send" do |
84 | 84 | it "sends message" do |
85 | 85 | context = server.bind |
86 | | - |
| 86 | + |
87 | 87 | client.send(hello: "world") |
88 | | - |
| 88 | + |
89 | 89 | message = context.receive |
90 | | - |
| 90 | + |
91 | 91 | expect(message).to be == {hello: "world"} |
92 | 92 | end |
93 | | - |
| 93 | + |
94 | 94 | it "fails if the message is too big" do |
95 | 95 | context = server.bind |
96 | | - |
| 96 | + |
97 | 97 | expect do |
98 | 98 | client.send(test: "x" * (subject::Socket::MAXIMUM_MESSAGE_SIZE+1)) |
99 | 99 | end.to raise_exception(ArgumentError, message: be =~ /Message length \d+ exceeds \d+/) |
100 | 100 | end |
101 | 101 | end |
102 | | - |
| 102 | + |
103 | 103 | with "#stopping!" do |
104 | 104 | it "sends stopping message" do |
105 | 105 | context = server.bind |
106 | | - |
| 106 | + |
107 | 107 | client.stopping! |
108 | | - |
| 108 | + |
109 | 109 | message = context.receive |
110 | | - |
| 110 | + |
111 | 111 | expect(message).to have_keys( |
112 | 112 | stopping: be == true |
113 | 113 | ) |
114 | 114 | end |
115 | 115 | end |
116 | | - |
| 116 | + |
117 | 117 | with "#error!" do |
118 | 118 | it "sends error message" do |
119 | 119 | context = server.bind |
120 | | - |
| 120 | + |
121 | 121 | client.error!("Boom!") |
122 | | - |
| 122 | + |
123 | 123 | message = context.receive |
124 | | - |
| 124 | + |
125 | 125 | expect(message).to have_keys( |
126 | 126 | status: be == "Boom!", |
127 | 127 | errno: be == -1, |
|
0 commit comments