|
62 | 62 | expect(options_captured[:restart]).to be == true |
63 | 63 | end |
64 | 64 |
|
| 65 | + with "integration test" do |
| 66 | + include Sus::Fixtures::Async::SchedulerContext |
| 67 | + |
| 68 | + it "executes the container block with async context and health checking" do |
| 69 | + container = Async::Container.new |
| 70 | + block_executed = false |
| 71 | + health_checker_called = false |
| 72 | + instance_ready_called = false |
| 73 | + |
| 74 | + # Create a mock instance that tracks ready! calls |
| 75 | + mock_instance = Object.new |
| 76 | + def mock_instance.ready! |
| 77 | + @ready_called = true |
| 78 | + end |
| 79 | + |
| 80 | + def mock_instance.ready_called? |
| 81 | + @ready_called || false |
| 82 | + end |
| 83 | + |
| 84 | + def mock_instance.name=(value) |
| 85 | + @name = value |
| 86 | + end |
| 87 | + |
| 88 | + def mock_instance.name |
| 89 | + @name |
| 90 | + end |
| 91 | + |
| 92 | + # Mock container.run to actually execute the block |
| 93 | + mock(container) do |mock| |
| 94 | + mock.replace(:run) do |**options, &block| |
| 95 | + # Execute the block in an async context (simulating what container does) |
| 96 | + Async do |
| 97 | + block.call(mock_instance) |
| 98 | + end |
| 99 | + end |
| 100 | + end |
| 101 | + |
| 102 | + # Override run to track execution |
| 103 | + service_class = Class.new(Async::Service::Managed::Service) do |
| 104 | + def run(instance, evaluator) |
| 105 | + @run_called = true |
| 106 | + super |
| 107 | + end |
| 108 | + |
| 109 | + def run_called? |
| 110 | + @run_called || false |
| 111 | + end |
| 112 | + end |
| 113 | + |
| 114 | + test_service = service_class.new(service.environment) |
| 115 | + |
| 116 | + # Setup should execute without errors |
| 117 | + expect{test_service.setup(container) |
| 118 | + }.not.to raise_exception |
| 119 | + |
| 120 | + # Give async tasks time to execute |
| 121 | + sleep(0.1) |
| 122 | + |
| 123 | + # Verify run was called |
| 124 | + expect(test_service.run_called?).to be == true |
| 125 | + |
| 126 | + # Verify health checker would have been called (it creates async tasks) |
| 127 | + # The instance should have been marked ready by the health checker |
| 128 | + expect(mock_instance.ready_called?).to be == true |
| 129 | + end |
| 130 | + end |
| 131 | + |
65 | 132 | with "custom managed service options" do |
66 | 133 | let(:configuration) do |
67 | 134 | Async::Service::Configuration.build do |
|
207 | 274 | task.stop |
208 | 275 | end |
209 | 276 | end |
| 277 | + |
| 278 | + with "integration test with controller" do |
| 279 | + let(:configuration) do |
| 280 | + Async::Service::Configuration.build do |
| 281 | + service "test-managed" do |
| 282 | + service_class Async::Service::Managed::Service |
| 283 | + include Async::Service::Managed::Environment |
| 284 | + |
| 285 | + count 1 |
| 286 | + |
| 287 | + # Very short timeout to detect failures quickly: |
| 288 | + health_check_timeout 0.01 |
| 289 | + end |
| 290 | + end |
| 291 | + end |
| 292 | + |
| 293 | + let(:test_service) {configuration.services.first} |
| 294 | + let(:controller) {Async::Service::Controller.for(test_service)} |
| 295 | + |
| 296 | + it "runs service with health checking and no restarts when async context is present" do |
| 297 | + container = Async::Container.new |
| 298 | + |
| 299 | + controller.setup(container) |
| 300 | + controller.start |
| 301 | + sleep(0.03) |
| 302 | + controller.stop |
| 303 | + end |
| 304 | + end |
210 | 305 | end |
0 commit comments