|
11 | 11 | describe Async::Container::Supervisor::ProcessMonitor do |
12 | 12 | include Sus::Fixtures::Console::CapturedLogger |
13 | 13 |
|
14 | | - let(:monitor) {subject.new(interval: 10)} |
| 14 | + let(:monitor) {subject.new(interval: 1)} |
15 | 15 | it_behaves_like Async::Container::Supervisor::AMonitor |
16 | 16 |
|
17 | | - it "has a parent process id" do |
18 | | - expect(monitor.ppid).to be == Process.ppid |
19 | | - end |
20 | | - |
21 | | - it "can capture process metrics" do |
22 | | - metrics = monitor.metrics |
23 | | - |
24 | | - # Should capture at least the current process |
25 | | - expect(metrics).to be_a(Hash) |
26 | | - expect(metrics).not.to be(:empty?) |
27 | | - |
28 | | - # Check that we have a metric for the current process |
29 | | - metric = metrics[Process.pid] |
30 | | - expect(metric).not.to be_nil |
31 | | - expect(metric.process_id).to be == Process.pid |
32 | | - expect(metric.command).to be_a(String) |
| 17 | + with "#ppid" do |
| 18 | + it "defaults to the current parent process id" do |
| 19 | + expect(monitor.ppid).to be == Process.ppid |
| 20 | + end |
33 | 21 | end |
34 | 22 |
|
35 | | - it "can respond to status calls" do |
36 | | - # Create a mock connection and call |
37 | | - stream = StringIO.new |
38 | | - connection = Async::Container::Supervisor::Connection.new(stream) |
| 23 | + with "#run" do |
| 24 | + include Sus::Fixtures::Async::SchedulerContext |
39 | 25 |
|
40 | | - # Create a mock call |
41 | | - call_messages = [] |
42 | | - call = Object.new |
43 | | - def call.push(**message) |
44 | | - @messages ||= [] |
45 | | - @messages << message |
46 | | - end |
47 | | - def call.messages |
48 | | - @messages || [] |
| 26 | + it "can run the monitor" do |
| 27 | + task = monitor.run |
| 28 | + expect(task).to be(:running?) |
49 | 29 | end |
50 | 30 |
|
51 | | - monitor.status(call) |
52 | | - |
53 | | - expect(call.messages).not.to be(:empty?) |
54 | | - status = call.messages.first |
55 | | - expect(status).to have_keys(:process_monitor) |
56 | | - expect(status[:process_monitor]).to have_keys(:ppid, :metrics) |
57 | | - end |
58 | | - |
59 | | - it "can register and remove connections" do |
60 | | - stream = StringIO.new |
61 | | - connection = Async::Container::Supervisor::Connection.new(stream, 0, process_id: Process.pid) |
62 | | - |
63 | | - # These should not raise errors |
64 | | - expect do |
65 | | - monitor.register(connection) |
66 | | - monitor.remove(connection) |
67 | | - end.not.to raise_exception |
| 31 | + it "can handle failures" do |
| 32 | + expect(monitor).to receive(:metrics).and_raise(Errno::ESRCH) |
| 33 | + |
| 34 | + task = monitor.run |
| 35 | + expect(task).to be(:running?) |
| 36 | + |
| 37 | + sleep 1 |
| 38 | + |
| 39 | + expect(task).to be(:running?) |
| 40 | + end |
68 | 41 | end |
69 | 42 | end |
70 | | - |
0 commit comments