|
1 | 1 | # frozen_string_literal: true
|
2 | 2 |
|
3 | 3 | require "syskit/test/self"
|
| 4 | +require "syskit/test/roby_app_helpers" |
| 5 | +require "syskit/process_managers/remote/server" |
4 | 6 |
|
5 | 7 | module Syskit
|
6 | 8 | module Runtime
|
@@ -38,11 +40,50 @@ def disconnect; end
|
38 | 40 | end
|
39 | 41 |
|
40 | 42 | describe ".update_deployment_states" do
|
| 43 | + describe "system behaviour with remote manager availability" do |
| 44 | + include Syskit::Test::RobyAppHelpers |
| 45 | + |
| 46 | + after do |
| 47 | + if @remote_process_server_pid |
| 48 | + remote_process_server_quit(@remote_process_server_pid) |
| 49 | + end |
| 50 | + end |
| 51 | + |
| 52 | + def roby_app_fixture_path |
| 53 | + File.expand_path("fixtures", __dir__) |
| 54 | + end |
| 55 | + |
| 56 | + it "gracefully handles a process manager that appears after start" do |
| 57 | + dir = roby_app_setup_single_script( |
| 58 | + "missing_process_manager_on_start.rb" |
| 59 | + ) |
| 60 | + port = roby_app_allocate_port |
| 61 | + token = SecureRandom.hex(10) |
| 62 | + env = { |
| 63 | + "SYSKIT_TEST_MISSING_PROCESS_SERVER_PORT" => port.to_s, |
| 64 | + "SYSKIT_TEST_MISSING_PROCESS_SERVER_TOKEN" => token |
| 65 | + } |
| 66 | + |
| 67 | + pid, = roby_app_start( |
| 68 | + "run", "-c", "scripts/missing_process_manager_on_start.rb", |
| 69 | + capture_output: true, chdir: dir, env: env |
| 70 | + ) |
| 71 | + sleep 5 |
| 72 | + |
| 73 | + @remote_process_server_pid = remote_process_server_spawn(port) |
| 74 | + assert_roby_app_exits(pid) |
| 75 | + output = roby_app_captured_output(pid) |
| 76 | + refute_match(/#{token} - failed/, output[:out]) |
| 77 | + assert_match(/#{token} - success/, output[:out]) |
| 78 | + end |
| 79 | + end |
| 80 | + |
41 | 81 | describe "#handle_dead_deployments" do
|
42 | 82 | it "calls #dead! on the dead deployments" do
|
43 | 83 | client = flexmock
|
44 |
| - flexmock(Syskit.conf).should_receive(:each_process_server_config) |
45 |
| - .and_return([flexmock(client: client)]) |
| 84 | + flexmock(Syskit.conf) |
| 85 | + .should_receive(:each_process_server_config) |
| 86 | + .and_return([flexmock(client: client, available?: true)]) |
46 | 87 | client.should_receive(:wait_termination)
|
47 | 88 | .and_return([[p = flexmock, s = flexmock]])
|
48 | 89 | flexmock(Deployment).should_receive(:deployment_by_process).with(p)
|
@@ -185,6 +226,22 @@ def mocked_deployment(
|
185 | 226 | mock
|
186 | 227 | end
|
187 | 228 | end
|
| 229 | + |
| 230 | + def remote_process_server_spawn(port) |
| 231 | + log_dir = make_tmpdir |
| 232 | + pid = spawn( |
| 233 | + "syskit", "process_server", |
| 234 | + "--log-dir=#{log_dir}", "--port=#{port}", |
| 235 | + chdir: log_dir, out: "/dev/null", err: "/dev/null" |
| 236 | + ) |
| 237 | + register_pid(pid) |
| 238 | + pid |
| 239 | + end |
| 240 | + |
| 241 | + def remote_process_server_quit(pid) |
| 242 | + Process.kill "INT", pid |
| 243 | + assert_process_exits(pid) |
| 244 | + end |
188 | 245 | end
|
189 | 246 | end
|
190 | 247 | end
|
0 commit comments