Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Falcon host container count #234

Merged
merged 3 commits into from
Apr 3, 2024
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
6 changes: 0 additions & 6 deletions lib/falcon/environment/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,6 @@ def endpoint
authority: authority
)
end

# Number of instances to start.
# @returns [Integer | nil]
def count
nil
end
end
end
end
2 changes: 1 addition & 1 deletion lib/falcon/environment/rackup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module Environment
# Provides an environment for hosting loading a Rackup `config.ru` file.
module Rackup
def rackup_path
'config.ru'
File.expand_path('config.ru', root)
end

def rack_app
Expand Down
8 changes: 7 additions & 1 deletion lib/falcon/environment/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,15 @@ def authority
self.name
end

# Number of instances to start. By default (when nil), uses `Etc.nprocessors`.
# @returns [Integer | nil]
def count
nil
end

# Options to use when creating the container.
def container_options
{restart: true}
{restart: true, count: self.count}.compact
end

# The host that this server will receive connections for.
Expand Down
6 changes: 6 additions & 0 deletions test/falcon/service/.server/hello/config.ru
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

app = proc do |env|
[200, {}, ["Hello World"]]
end

run app
66 changes: 66 additions & 0 deletions test/falcon/service/server.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# frozen_string_literal: true

# Released under the MIT License.
# Copyright, 2024, by Samuel Williams.

require 'falcon/service/server'
require 'falcon/configuration'
require 'falcon/environment/server'
require 'falcon/environment/rackup'

describe Falcon::Service::Server do
let(:environment) do
Async::Service::Environment.new(Falcon::Environment::Server).with(
Falcon::Environment::Rackup,
name: 'hello',
root: File.expand_path('.server/hello', __dir__),
url: "http://localhost:0",
)
end

let(:server) do
subject.new(environment)
end

it "can create a server" do
expect(server).to be_a subject
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
end

with 'a limited count' do
let(:environment) do
Async::Service::Environment.new(Falcon::Environment::Server).with(
Falcon::Environment::Rackup,
name: 'hello',
root: File.expand_path('.server/hello', __dir__),
url: "http://localhost:0",
count: 1,
)
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
end
end
end
Loading