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: 16 additions & 0 deletions fixtures/container_context.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# frozen_string_literal: true

require "async"
require "async/container/group"

module ContainerContext
def container_context(&block)
# Newer async-container supervises containers using Async tasks, while
# released versions can fail when forking under a scheduler on Ruby 3.x.
if Async::Container::Group.method_defined?(:supervise)
Sync(&block)
else
block.call
end
end
end
37 changes: 21 additions & 16 deletions test/falcon/command/serve.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@
# Copyright, 2019, by Sho Ito.

require "falcon/command/serve"
require "container_context"
require "sus/fixtures/console/captured_logger"

ServeCommand = Sus::Shared("falcon serve") do
include ContainerContext

let(:command) do
subject[
"--port", port,
Expand All @@ -16,23 +19,25 @@
end

it "can listen on specified port" do
configuration = command.configuration
controller = configuration.make_controller

controller.start

begin
Async do
client = command.client

response = client.get("/")
expect(response).to be(:success?)

response.finish
client.close
container_context do
configuration = command.configuration
controller = configuration.make_controller

controller.start

begin
Async do
client = command.client

response = client.get("/")
expect(response).to be(:success?)

response.finish
client.close
end
ensure
controller.stop
end
ensure
controller.stop
end
end
end
Expand Down
29 changes: 18 additions & 11 deletions test/falcon/command/top.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
# Copyright, 2018-2026, by Samuel Williams.

require "falcon/command"
require "container_context"
require "sus/fixtures/console/captured_logger"

describe Falcon::Command::Top do
include ContainerContext
include Sus::Fixtures::Console::CapturedLogger

with "basic server configuration" do
Expand All @@ -19,20 +21,25 @@
]

serve = top.command
controller = serve.configuration.make_controller
controller.start

Async do
client = serve.client
container_context do
controller = serve.configuration.make_controller
controller.start

response = client.get("/")
expect(response).to be(:success?)

response.finish
client.close
begin
Async do
client = serve.client

response = client.get("/")
expect(response).to be(:success?)

response.finish
client.close
end
ensure
controller.stop
end
end

controller.stop
end
end

Expand Down
24 changes: 15 additions & 9 deletions test/falcon/command/virtual.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
# Copyright, 2019-2026, by Samuel Williams.

require "falcon/command/virtual"
require "async"
require "container_context"
require "sus/fixtures/console/captured_logger"

require "async/http"
Expand All @@ -12,6 +14,8 @@
require "async/websocket/client"

VirtualCommand = Sus::Shared("falcon virtual") do
include ContainerContext

let(:paths) {[
File.expand_path("hello/falcon.rb", examples_root),
File.expand_path("beer/falcon.rb", examples_root),
Expand All @@ -32,15 +36,17 @@
end

def around
configuration = command.configuration
controller = configuration.make_controller

controller.start

begin
yield
ensure
controller.stop
container_context do
configuration = command.configuration
controller = configuration.make_controller

controller.start

begin
yield
ensure
controller.stop
end
end
end

Expand Down
49 changes: 29 additions & 20 deletions test/falcon/service/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@
require "falcon/service/server"
require "falcon/environment/server"
require "falcon/environment/rackup"
require "async/container"
require "async/service/environment"
require "container_context"

describe Falcon::Service::Server do
include ContainerContext

let(:environment) do
Async::Service::Environment.new(Falcon::Environment::Server).with(
Falcon::Environment::Rackup,
Expand All @@ -26,16 +31,18 @@
end

it "can start and stop server" do
container = Async::Container.new

server.start
server.setup(container)
container.wait_until_ready

expect(container.group.running).to have_attributes(size: be == Etc.nprocessors)

server.stop
container.stop
container_context do
container = Async::Container.new

server.start
server.setup(container)
container.wait_until_ready

expect(container.group.running).to have_attributes(size: be == Etc.nprocessors)
ensure
server.stop
container&.stop
end
end

with "a limited count" do
Expand All @@ -50,16 +57,18 @@
end

it "can start and stop server" do
container = Async::Container.new

server.start
server.setup(container)
container.wait_until_ready

expect(container.group.running).to have_attributes(size: be == 1)

server.stop
container.stop
container_context do
container = Async::Container.new

server.start
server.setup(container)
container.wait_until_ready

expect(container.group.running).to have_attributes(size: be == 1)
ensure
server.stop
container&.stop
end
end
end

Expand Down
Loading