Skip to content

Commit 3519986

Browse files
committed
Allow to configure boot and connect timeout
The hardcoded values might not be enough for all applications.
1 parent cf107a5 commit 3519986

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

lib/spring/client/run.rb

+4-6
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ module Spring
66
module Client
77
class Run < Command
88
FORWARDED_SIGNALS = %w(INT QUIT USR1 USR2 INFO WINCH) & Signal.list.keys
9-
CONNECT_TIMEOUT = 1
10-
BOOT_TIMEOUT = 20
119

1210
attr_reader :server
1311

@@ -74,7 +72,7 @@ def boot_server
7472
env.socket_path.unlink if env.socket_path.exist?
7573

7674
pid = Process.spawn(server_process_env, env.server_command, out: File::NULL)
77-
timeout = Time.now + BOOT_TIMEOUT
75+
timeout = Time.now + String.boot_timeout
7876

7977
@server_booted = true
8078

@@ -85,7 +83,7 @@ def boot_server
8583
exit status.exitstatus
8684
elsif Time.now > timeout
8785
$stderr.puts "Starting Spring server with `#{env.server_command}` " \
88-
"timed out after #{BOOT_TIMEOUT} seconds"
86+
"timed out after #{Spring.boot_timeout} seconds"
8987
exit 1
9088
end
9189

@@ -122,7 +120,7 @@ def stop_server
122120
end
123121

124122
def verify_server_version
125-
unless IO.select([server], [], [], CONNECT_TIMEOUT)
123+
unless IO.select([server], [], [], Spring.connect_timeout)
126124
raise "Error connecting to Spring server"
127125
end
128126

@@ -151,7 +149,7 @@ def connect_to_application(client)
151149
server.send_io client
152150
send_json server, "args" => args, "default_rails_env" => default_rails_env, "spawn_env" => spawn_env, "reset_env" => reset_env
153151

154-
if IO.select([server], [], [], CONNECT_TIMEOUT)
152+
if IO.select([server], [], [], Spring.connect_timeout)
155153
server.gets or raise CommandNotFound
156154
else
157155
raise "Error connecting to Spring server"

lib/spring/configuration.rb

+6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ class << self
55
attr_accessor :application_root
66
attr_writer :quiet
77

8+
attr_accessor :connect_timeout
9+
@connect_timeout = 5
10+
11+
attr_accessor :boot_timeout
12+
@boot_timeout = 20
13+
814
def gemfile
915
require "bundler"
1016

test/support/acceptance_test.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,7 @@ def exec_name
691691
test "server boot timeout" do
692692
app.env["SPRING_SERVER_COMMAND"] = "sleep 1"
693693
File.write("#{app.spring_client_config}", %(
694-
Spring::Client::Run.const_set(:BOOT_TIMEOUT, 0.1)
694+
Spring.boot_timeout = 0.1
695695
))
696696

697697
assert_failure "bin/rails runner ''", stderr: "timed out"

0 commit comments

Comments
 (0)