Skip to content

Commit

Permalink
Fix tests (but not passing).
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed Mar 18, 2024
1 parent 10c24f3 commit 156e9b7
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 25 deletions.
13 changes: 8 additions & 5 deletions lib/falcon/command/serve.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def endpoint_options
@options.slice(:hostname, :port, :timeout)
end

def service
def environment
Async::Service::Environment.new(Falcon::Service::Rackup::Environment).with(
root: Dir.pwd,

Expand All @@ -70,6 +70,12 @@ def service
)
end

def configuration
Configuration.new.tap do |configuration|
configuration.add(self.environment)
end
end

# The container class to use.
def container_class
case @options[:container]
Expand Down Expand Up @@ -106,10 +112,7 @@ def call
buffer.puts "- To reload configuration: kill -HUP #{Process.pid}"
end

configuration = Async::Service::Configuration.new
configuration.add(self.service)

Async::Service::Controller.run(configuration, container_class: self.container_class)
Async::Service::Controller.run(self.configuration, container_class: self.container_class)
end
end
end
Expand Down
15 changes: 9 additions & 6 deletions lib/falcon/command/virtual.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ class Virtual < Samovar::Command

include Paths

def service
Async::Service::Environment.new(Falcon::Service::Virtual).with(
def environment
Async::Service::Environment.new(Falcon::Service::Virtual::Environment).with(
verbose: self.parent&.verbose?,
configuration_paths: self.paths,
bind_insecure: @options[:bind_insecure],
Expand All @@ -42,6 +42,12 @@ def service
)
end

def configuration
super.tap do |configuration|
configuration.add(self.environment)
end
end

# Prepare the environment and run the controller.
def call
Console.logger.info(self) do |buffer|
Expand All @@ -50,10 +56,7 @@ def call
buffer.puts "- To reload all sites: kill -HUP #{Process.pid}"
end

configuration = self.configuration
configuration.add(self.service)

Async::Service::Controller.run(configuration)
Async::Service::Controller.run(self.configuration)
end
end
end
Expand Down
12 changes: 6 additions & 6 deletions lib/falcon/environments/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ module Falcon
module Environments
# A general application environment. Suitable for use with any {Protocol::HTTP::Middleware}.
module Application
# The service class to use for the application.
# @returns [Class]
def service_class
::Falcon::Service::Application
end

# The middleware stack for the application.
# @returns [Protocol::HTTP::Middleware]
def middleware
Expand Down Expand Up @@ -51,12 +57,6 @@ def endpoint
)
end

# The service class to use for the application.
# @returns [Class]
def service_class
::Falcon::Service::Application
end

# Number of instances to start.
# @returns [Integer | nil]
def count
Expand Down
2 changes: 1 addition & 1 deletion lib/falcon/service/proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module Environment
# The service class to use for the proxy.
# @attribute [Class]
def service_class
::Falcon::Service::Proxy
Proxy
end

# The host that this proxy will receive connections for.
Expand Down
2 changes: 1 addition & 1 deletion lib/falcon/service/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module Environment
# The service class to use for the proxy.
# @returns [Class]
def service_class
::Falcon::Service::Server
Server
end

# Options to use when creating the container.
Expand Down
6 changes: 6 additions & 0 deletions lib/falcon/service/virtual.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ module Service
# A virtual host is an application bound to a specific authority (essentially a hostname). The virtual controller manages multiple hosts and allows a single server to host multiple applications easily.
class Virtual < Async::Service::Generic
module Environment
# The service class to use for the virtual host.
# @returns [Class]
def service_class
Virtual
end

# All the falcon application configuration paths.
# @returns [Array(String)] Paths to the falcon application configuration files.
def configuration_paths
Expand Down
3 changes: 2 additions & 1 deletion test/falcon/command/serve.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
end

it "can listen on specified port" do
controller = command.controller
configuration = command.configuration
controller = Async::Service::Controller.new(configuration.services.to_a)

controller.start

Expand Down
6 changes: 3 additions & 3 deletions test/falcon/command/top.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
]

serve = top.command
container = serve.controller
container.start
controller = Async::Service::Controller.new(serve.configuration)
controller.start

Async do
client = serve.client
Expand All @@ -29,7 +29,7 @@
client.close
end

container.stop
controller.stop
end
end
end
4 changes: 2 additions & 2 deletions test/falcon/command/virtual.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
}

def around
# Wait for the container to start...
controller = command.controller
configuration = command.configuration
controller = Async::Service::Controller.new(configuration.services.to_a)

controller.start

Expand Down

0 comments on commit 156e9b7

Please sign in to comment.