|
23 | 23 | worker_task&.stop |
24 | 24 | end |
25 | 25 |
|
| 26 | + with "state handling" do |
| 27 | + it "stores state on supervisor_controller during registration" do |
| 28 | + custom_state = {name: "test-service", version: "1.0"} |
| 29 | + worker = Async::Service::Supervisor::Worker.new( |
| 30 | + process_id: ::Process.pid, |
| 31 | + endpoint: endpoint, |
| 32 | + state: custom_state |
| 33 | + ) |
| 34 | + worker_task = worker.run |
| 35 | + |
| 36 | + # Wait for registration via the registration monitor |
| 37 | + event = registration_monitor.pop(timeout: 5) |
| 38 | + |
| 39 | + expect(event).to be_truthy |
| 40 | + supervisor_controller = event.supervisor_controller |
| 41 | + |
| 42 | + expect(supervisor_controller.state).to have_keys( |
| 43 | + name: be == "test-service", |
| 44 | + version: be == "1.0" |
| 45 | + ) |
| 46 | + ensure |
| 47 | + worker_task&.stop |
| 48 | + end |
| 49 | + |
| 50 | + it "defaults to empty state hash" do |
| 51 | + worker = Async::Service::Supervisor::Worker.new(process_id: ::Process.pid, endpoint: endpoint) |
| 52 | + worker_task = worker.run |
| 53 | + |
| 54 | + # Wait for registration via the registration monitor |
| 55 | + event = registration_monitor.pop(timeout: 5) |
| 56 | + |
| 57 | + expect(event).to be_truthy |
| 58 | + supervisor_controller = event.supervisor_controller |
| 59 | + |
| 60 | + expect(supervisor_controller.state).to be == {} |
| 61 | + ensure |
| 62 | + worker_task&.stop |
| 63 | + end |
| 64 | + |
| 65 | + it "allows monitors to access state" do |
| 66 | + custom_state = {name: "outbox"} |
| 67 | + worker = Async::Service::Supervisor::Worker.new( |
| 68 | + process_id: ::Process.pid, |
| 69 | + endpoint: endpoint, |
| 70 | + state: custom_state |
| 71 | + ) |
| 72 | + worker_task = worker.run |
| 73 | + |
| 74 | + # Wait for registration via the registration monitor |
| 75 | + event = registration_monitor.pop(timeout: 5) |
| 76 | + |
| 77 | + expect(event).to be_truthy |
| 78 | + supervisor_controller = event.supervisor_controller |
| 79 | + |
| 80 | + # Verify state can be accessed by monitors |
| 81 | + expect(supervisor_controller.state[:name]).to be == "outbox" |
| 82 | + ensure |
| 83 | + worker_task&.stop |
| 84 | + end |
| 85 | + end |
| 86 | + |
26 | 87 | with "memory_dump" do |
27 | 88 | it "can dump memory" do |
28 | 89 | worker = Async::Service::Supervisor::Worker.new(process_id: ::Process.pid, endpoint: endpoint) |
|
113 | 174 | end |
114 | 175 | end |
115 | 176 |
|
| 177 | + with "state handling" do |
| 178 | + it "stores state on supervisor_controller during registration" do |
| 179 | + custom_state = {name: "test-service", version: "1.0"} |
| 180 | + worker = Async::Service::Supervisor::Worker.new( |
| 181 | + process_id: ::Process.pid, |
| 182 | + endpoint: endpoint, |
| 183 | + state: custom_state |
| 184 | + ) |
| 185 | + worker_task = worker.run |
| 186 | + |
| 187 | + # Wait for registration via the registration monitor |
| 188 | + event = registration_monitor.pop(timeout: 5) |
| 189 | + |
| 190 | + expect(event).to be_truthy |
| 191 | + supervisor_controller = event.supervisor_controller |
| 192 | + |
| 193 | + expect(supervisor_controller.state).to have_keys( |
| 194 | + name: be == "test-service", |
| 195 | + version: be == "1.0" |
| 196 | + ) |
| 197 | + ensure |
| 198 | + worker_task&.stop |
| 199 | + end |
| 200 | + |
| 201 | + it "defaults to empty state hash" do |
| 202 | + worker = Async::Service::Supervisor::Worker.new(process_id: ::Process.pid, endpoint: endpoint) |
| 203 | + worker_task = worker.run |
| 204 | + |
| 205 | + # Wait for registration via the registration monitor |
| 206 | + event = registration_monitor.pop(timeout: 5) |
| 207 | + |
| 208 | + expect(event).to be_truthy |
| 209 | + supervisor_controller = event.supervisor_controller |
| 210 | + |
| 211 | + expect(supervisor_controller.state).to be == {} |
| 212 | + ensure |
| 213 | + worker_task&.stop |
| 214 | + end |
| 215 | + |
| 216 | + it "allows monitors to access state" do |
| 217 | + custom_state = {name: "outbox"} |
| 218 | + worker = Async::Service::Supervisor::Worker.new( |
| 219 | + process_id: ::Process.pid, |
| 220 | + endpoint: endpoint, |
| 221 | + state: custom_state |
| 222 | + ) |
| 223 | + worker_task = worker.run |
| 224 | + |
| 225 | + # Wait for registration via the registration monitor |
| 226 | + event = registration_monitor.pop(timeout: 5) |
| 227 | + |
| 228 | + expect(event).to be_truthy |
| 229 | + supervisor_controller = event.supervisor_controller |
| 230 | + |
| 231 | + # Verify state can be accessed by monitors |
| 232 | + expect(supervisor_controller.state[:name]).to be == "outbox" |
| 233 | + ensure |
| 234 | + worker_task&.stop |
| 235 | + end |
| 236 | + end |
| 237 | + |
116 | 238 | end |
117 | 239 |
|
0 commit comments