Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions test/async/service/managed/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,8 @@ def name = @name
end

with "integration test with controller" do
include Sus::Fixtures::Async::SchedulerContext

let(:configuration) do
Async::Service::Configuration.build do
service "test-managed" do
Expand All @@ -367,14 +369,12 @@ def name = @name
it "runs service with health checking and no restarts when async context is present" do
container = Async::Container.new

begin
controller.setup(container)
controller.start
sleep(0.03)
ensure
controller.stop
container.stop
end
controller.setup(container)
controller.start
sleep(0.03)
ensure
controller.stop
container&.stop
end
end
end
13 changes: 12 additions & 1 deletion test/async/service/policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
require "async/container/best"
require "async/service/policy"
require "async/container/statistics"
require "sus/fixtures/async/scheduler_context"

describe Async::Service::Policy do
let(:policy) {subject.new(maximum_failures: 5, window: 10)}
Expand Down Expand Up @@ -160,9 +161,17 @@ def success_status.success?; true; end
end

with "concurrent failures" do
include Sus::Fixtures::Async::SchedulerContext

it "only stops container once when multiple children fail simultaneously" do
container = Async::Container.best_container_class.new(policy: policy)
expect(container).to receive(:stop)
stop_count = 0
original_stop = container.method(:stop)

container.define_singleton_method(:stop) do |*arguments|
stop_count += 1
original_stop.call(*arguments)
end

# Spawn 10 children that all fail immediately:
10.times do |i|
Expand All @@ -173,6 +182,8 @@ def success_status.success?; true; end
end

container.wait

expect(stop_count).to be == 1
end
end
end
Loading