Skip to content

Commit 76bc2b6

Browse files
Use scheduler context for container tests
1 parent 3ae6b62 commit 76bc2b6

3 files changed

Lines changed: 31 additions & 52 deletions

File tree

fixtures/container_context.rb

Lines changed: 0 additions & 16 deletions
This file was deleted.

test/async/service/managed/service.rb

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,8 @@
1010
require "async"
1111

1212
require "sus/fixtures/async/scheduler_context"
13-
require "container_context"
1413

1514
describe Async::Service::Managed::Service do
16-
include ContainerContext
17-
1815
let(:configuration) do
1916
Async::Service::Configuration.build do
2017
service "test-container" do
@@ -350,6 +347,8 @@ def name = @name
350347
end
351348

352349
with "integration test with controller" do
350+
include Sus::Fixtures::Async::SchedulerContext
351+
353352
let(:configuration) do
354353
Async::Service::Configuration.build do
355354
service "test-managed" do
@@ -368,16 +367,14 @@ def name = @name
368367
let(:controller) {Async::Service::Controller.for(test_service)}
369368

370369
it "runs service with health checking and no restarts when async context is present" do
371-
container_context do
372-
container = Async::Container.new
373-
374-
controller.setup(container)
375-
controller.start
376-
sleep(0.03)
377-
ensure
378-
controller.stop
379-
container&.stop
380-
end
370+
container = Async::Container.new
371+
372+
controller.setup(container)
373+
controller.start
374+
sleep(0.03)
375+
ensure
376+
controller.stop
377+
container&.stop
381378
end
382379
end
383380
end

test/async/service/policy.rb

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,9 @@
66
require "async/container/best"
77
require "async/service/policy"
88
require "async/container/statistics"
9-
require "container_context"
9+
require "sus/fixtures/async/scheduler_context"
1010

1111
describe Async::Service::Policy do
12-
include ContainerContext
13-
1412
let(:policy) {subject.new(maximum_failures: 5, window: 10)}
1513

1614
with "::DEFAULT" do
@@ -163,29 +161,29 @@ def success_status.success?; true; end
163161
end
164162

165163
with "concurrent failures" do
164+
include Sus::Fixtures::Async::SchedulerContext
165+
166166
it "only stops container once when multiple children fail simultaneously" do
167-
container_context do
168-
container = Async::Container.best_container_class.new(policy: policy)
169-
stop_count = 0
170-
original_stop = container.method(:stop)
171-
172-
container.define_singleton_method(:stop) do |*arguments|
173-
stop_count += 1
174-
original_stop.call(*arguments)
175-
end
176-
177-
# Spawn 10 children that all fail immediately:
178-
10.times do |i|
179-
container.spawn(name: "worker-#{i}") do |instance|
180-
instance.ready!
181-
exit(1)
182-
end
167+
container = Async::Container.best_container_class.new(policy: policy)
168+
stop_count = 0
169+
original_stop = container.method(:stop)
170+
171+
container.define_singleton_method(:stop) do |*arguments|
172+
stop_count += 1
173+
original_stop.call(*arguments)
174+
end
175+
176+
# Spawn 10 children that all fail immediately:
177+
10.times do |i|
178+
container.spawn(name: "worker-#{i}") do |instance|
179+
instance.ready!
180+
exit(1)
183181
end
184-
185-
container.wait
186-
187-
expect(stop_count).to be == 1
188182
end
183+
184+
container.wait
185+
186+
expect(stop_count).to be == 1
189187
end
190188
end
191189
end

0 commit comments

Comments
 (0)