sanford 0.10.1 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile +1 -1
- data/README.md +41 -56
- data/Rakefile +0 -1
- data/bench/client.rb +8 -3
- data/bench/{services.rb → config.sanford} +11 -6
- data/bench/{runner.rb → report.rb} +2 -2
- data/bench/report.txt +32 -32
- data/lib/sanford/cli.rb +42 -28
- data/lib/sanford/config_file.rb +79 -0
- data/lib/sanford/{worker.rb → connection_handler.rb} +28 -20
- data/lib/sanford/error_handler.rb +7 -7
- data/lib/sanford/pid_file.rb +42 -0
- data/lib/sanford/process.rb +136 -0
- data/lib/sanford/process_signal.rb +20 -0
- data/lib/sanford/route.rb +48 -0
- data/lib/sanford/router.rb +36 -0
- data/lib/sanford/runner.rb +30 -58
- data/lib/sanford/sanford_runner.rb +19 -9
- data/lib/sanford/server.rb +211 -42
- data/lib/sanford/server_data.rb +47 -0
- data/lib/sanford/service_handler.rb +8 -46
- data/lib/sanford/template_source.rb +19 -2
- data/lib/sanford/test_runner.rb +27 -28
- data/lib/sanford/version.rb +1 -1
- data/lib/sanford.rb +1 -23
- data/sanford.gemspec +4 -5
- data/test/helper.rb +3 -20
- data/test/support/app_server.rb +142 -0
- data/test/support/config.sanford +7 -0
- data/test/support/config_invalid_run.sanford +3 -0
- data/test/support/config_no_run.sanford +0 -0
- data/test/support/fake_server_connection.rb +58 -0
- data/test/support/pid_file_spy.rb +19 -0
- data/test/support/template.erb +1 -0
- data/test/system/server_tests.rb +378 -0
- data/test/system/service_handler_tests.rb +224 -0
- data/test/unit/cli_tests.rb +187 -0
- data/test/unit/config_file_tests.rb +59 -0
- data/test/unit/connection_handler_tests.rb +254 -0
- data/test/unit/error_handler_tests.rb +30 -35
- data/test/unit/pid_file_tests.rb +70 -0
- data/test/unit/process_signal_tests.rb +61 -0
- data/test/unit/process_tests.rb +428 -0
- data/test/unit/route_tests.rb +92 -0
- data/test/unit/router_tests.rb +65 -0
- data/test/unit/runner_tests.rb +61 -15
- data/test/unit/sanford_runner_tests.rb +162 -28
- data/test/unit/sanford_tests.rb +0 -8
- data/test/unit/server_data_tests.rb +87 -0
- data/test/unit/server_tests.rb +502 -21
- data/test/unit/service_handler_tests.rb +114 -219
- data/test/unit/template_engine_tests.rb +1 -1
- data/test/unit/template_source_tests.rb +56 -16
- data/test/unit/test_runner_tests.rb +206 -0
- metadata +67 -67
- data/bench/tasks.rb +0 -41
- data/lib/sanford/config.rb +0 -28
- data/lib/sanford/host.rb +0 -129
- data/lib/sanford/host_data.rb +0 -65
- data/lib/sanford/hosts.rb +0 -38
- data/lib/sanford/manager.rb +0 -275
- data/test/support/fake_connection.rb +0 -36
- data/test/support/helpers.rb +0 -17
- data/test/support/service_handlers.rb +0 -154
- data/test/support/services.rb +0 -123
- data/test/support/simple_client.rb +0 -62
- data/test/system/request_handling_tests.rb +0 -306
- data/test/unit/config_tests.rb +0 -56
- data/test/unit/host_data_tests.rb +0 -71
- data/test/unit/host_tests.rb +0 -141
- data/test/unit/hosts_tests.rb +0 -50
- data/test/unit/manager_tests.rb +0 -195
- data/test/unit/worker_tests.rb +0 -24
data/test/unit/manager_tests.rb
DELETED
@@ -1,195 +0,0 @@
|
|
1
|
-
require 'assert'
|
2
|
-
require 'sanford/manager'
|
3
|
-
|
4
|
-
module Sanford::Manager
|
5
|
-
|
6
|
-
class UnitTests < Assert::Context
|
7
|
-
desc "Sanford::Manager"
|
8
|
-
subject{ Sanford::Manager }
|
9
|
-
|
10
|
-
should have_imeths :call, :get_handler_class
|
11
|
-
|
12
|
-
should "return ServerHandler or SignalHandler with get_handler_class" do
|
13
|
-
assert_equal Sanford::Manager::ServerHandler, subject.get_handler_class('run')
|
14
|
-
assert_equal Sanford::Manager::ServerHandler, subject.get_handler_class('start')
|
15
|
-
assert_equal Sanford::Manager::SignalHandler, subject.get_handler_class('stop')
|
16
|
-
assert_equal Sanford::Manager::SignalHandler, subject.get_handler_class('restart')
|
17
|
-
end
|
18
|
-
|
19
|
-
end
|
20
|
-
|
21
|
-
class ConfigTests < UnitTests
|
22
|
-
desc "Config"
|
23
|
-
setup do
|
24
|
-
@config = Sanford::Manager::Config.new({ :host => 'TestHost' })
|
25
|
-
end
|
26
|
-
subject{ @config }
|
27
|
-
|
28
|
-
should have_readers :host_name, :host, :ip, :port, :pid, :pid_file, :restart_dir
|
29
|
-
should have_readers :file_descriptor, :client_file_descriptors
|
30
|
-
should have_imeths :listen_args, :has_listen_args?, :found_host?
|
31
|
-
|
32
|
-
should "find a host based on the `host` option" do
|
33
|
-
assert_equal TestHost, subject.host
|
34
|
-
assert_equal true, subject.found_host?
|
35
|
-
end
|
36
|
-
|
37
|
-
should "set the ip, port and pid file based on the host's configuration" do
|
38
|
-
assert_equal TestHost.ip, subject.ip
|
39
|
-
assert_equal TestHost.port, subject.port
|
40
|
-
assert_equal TestHost.pid_file.to_s, subject.pid_file.to_s
|
41
|
-
end
|
42
|
-
|
43
|
-
should "use the first host if no host option is provided" do
|
44
|
-
config = Sanford::Manager::Config.new({ :port => 1 })
|
45
|
-
assert_equal Sanford.hosts.first, config.host
|
46
|
-
end
|
47
|
-
|
48
|
-
should "return the file descriptor or ip and port with listen_args" do
|
49
|
-
config = Sanford::Manager::Config.new({
|
50
|
-
:file_descriptor => 1,
|
51
|
-
:ip => 'localhost', :port => 1234
|
52
|
-
})
|
53
|
-
assert_equal [ config.file_descriptor ], config.listen_args
|
54
|
-
assert_equal true, subject.has_listen_args?
|
55
|
-
|
56
|
-
config = Sanford::Manager::Config.new({ :ip => 'localhost', :port => 1234 })
|
57
|
-
assert_equal [ config.ip, config.port ], config.listen_args
|
58
|
-
assert_equal true, subject.has_listen_args?
|
59
|
-
|
60
|
-
config = Sanford::Manager::Config.new({ :host => 'InvalidHost' })
|
61
|
-
assert_equal false, config.has_listen_args?
|
62
|
-
end
|
63
|
-
|
64
|
-
should "build a NullHost when a host can't be found" do
|
65
|
-
config = Sanford::Manager::Config.new({ :host => 'poop' })
|
66
|
-
assert_instance_of Sanford::Manager::Config::NullHost, config.host
|
67
|
-
assert_equal false, config.found_host?
|
68
|
-
end
|
69
|
-
|
70
|
-
should "split a string list of client file descriptors into an array" do
|
71
|
-
config = Sanford::Manager::Config.new({ :client_fds => '1,2,3' })
|
72
|
-
assert_equal [ 1, 2, 3 ], config.client_file_descriptors
|
73
|
-
end
|
74
|
-
|
75
|
-
end
|
76
|
-
|
77
|
-
class EnvVarsTests < ConfigTests
|
78
|
-
desc "with env vars set"
|
79
|
-
setup do
|
80
|
-
ENV['SANFORD_HOST'] = 'TestHost'
|
81
|
-
ENV['SANFORD_IP'] = '127.0.0.1'
|
82
|
-
ENV['SANFORD_PORT'] = '12345'
|
83
|
-
@config = Sanford::Manager::Config.new({
|
84
|
-
:host => 'InvalidHost',
|
85
|
-
:port => 54678
|
86
|
-
})
|
87
|
-
end
|
88
|
-
teardown do
|
89
|
-
ENV.delete('SANFORD_HOST')
|
90
|
-
ENV.delete('SANFORD_IP')
|
91
|
-
ENV.delete('SANFORD_PORT')
|
92
|
-
end
|
93
|
-
|
94
|
-
should "use the env vars over passed in options or the host's configuration" do
|
95
|
-
assert_equal TestHost, subject.host
|
96
|
-
assert_equal '127.0.0.1', subject.ip
|
97
|
-
assert_equal 12345, subject.port
|
98
|
-
end
|
99
|
-
|
100
|
-
end
|
101
|
-
|
102
|
-
class PIDFileTests < ConfigTests
|
103
|
-
desc "PIDFile"
|
104
|
-
setup do
|
105
|
-
@pid_file_path = File.join(ROOT, "tmp/my.pid")
|
106
|
-
@pid_file = Sanford::Manager::Config::PIDFile.new(@pid_file_path)
|
107
|
-
end
|
108
|
-
teardown do
|
109
|
-
FileUtils.rm_rf(@pid_file_path)
|
110
|
-
end
|
111
|
-
subject{ @pid_file }
|
112
|
-
|
113
|
-
should have_imeths :pid, :to_s, :write, :remove
|
114
|
-
|
115
|
-
should "return its path with #to_s" do
|
116
|
-
assert_equal @pid_file_path, subject.to_s
|
117
|
-
end
|
118
|
-
|
119
|
-
should "write the pid file with #write" do
|
120
|
-
subject.write
|
121
|
-
|
122
|
-
assert_file_exists @pid_file_path
|
123
|
-
assert_equal "#{Process.pid}\n", File.read(@pid_file_path)
|
124
|
-
end
|
125
|
-
|
126
|
-
should "return the value stored in the pid value with #pid" do
|
127
|
-
subject.write
|
128
|
-
|
129
|
-
assert_equal Process.pid, subject.pid
|
130
|
-
end
|
131
|
-
|
132
|
-
should "remove the file with #remove" do
|
133
|
-
subject.write
|
134
|
-
subject.remove
|
135
|
-
|
136
|
-
assert_not File.exists?(@pid_file_path)
|
137
|
-
end
|
138
|
-
|
139
|
-
should "complain nicely if it can't write the pid file" do
|
140
|
-
pid_file_path = 'does/not/exist.pid'
|
141
|
-
pid_file = Sanford::Manager::Config::PIDFile.new(pid_file_path)
|
142
|
-
|
143
|
-
err = nil
|
144
|
-
begin
|
145
|
-
pid_file.write
|
146
|
-
rescue Exception => err
|
147
|
-
end
|
148
|
-
|
149
|
-
assert err
|
150
|
-
assert_kind_of RuntimeError, err
|
151
|
-
assert_includes File.dirname(pid_file_path), err.message
|
152
|
-
end
|
153
|
-
|
154
|
-
end
|
155
|
-
|
156
|
-
class ServerHandlerTests < UnitTests
|
157
|
-
desc "ServerHandler"
|
158
|
-
setup do
|
159
|
-
@handler = Sanford::Manager::ServerHandler.new({ :host => 'TestHost' })
|
160
|
-
end
|
161
|
-
subject{ @handler }
|
162
|
-
|
163
|
-
should have_imeths :run, :start
|
164
|
-
|
165
|
-
should "raise an error when a host can't be found" do
|
166
|
-
assert_raises(Sanford::NoHostError) do
|
167
|
-
Sanford::Manager::ServerHandler.new({ :host => 'not_found' })
|
168
|
-
end
|
169
|
-
end
|
170
|
-
|
171
|
-
should "raise an error when a host is invalid for running a server" do
|
172
|
-
assert_raises(Sanford::InvalidHostError) do
|
173
|
-
Sanford::Manager::ServerHandler.new({ :host => 'InvalidHost' })
|
174
|
-
end
|
175
|
-
end
|
176
|
-
|
177
|
-
end
|
178
|
-
|
179
|
-
class SignalHandlertests < UnitTests
|
180
|
-
desc "SignalHandler"
|
181
|
-
setup do
|
182
|
-
@handler = Sanford::Manager::SignalHandler.new({ :pid => -1 })
|
183
|
-
end
|
184
|
-
subject{ @handler }
|
185
|
-
|
186
|
-
should have_imeths :stop, :restart
|
187
|
-
|
188
|
-
should "raise an error when a pid can't be found" do
|
189
|
-
assert_raises(Sanford::NoPIDError) do
|
190
|
-
Sanford::Manager::SignalHandler.new
|
191
|
-
end
|
192
|
-
end
|
193
|
-
end
|
194
|
-
|
195
|
-
end
|
data/test/unit/worker_tests.rb
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
require 'assert'
|
2
|
-
require 'sanford/worker'
|
3
|
-
|
4
|
-
require 'sanford/host_data'
|
5
|
-
require 'test/support/fake_connection'
|
6
|
-
|
7
|
-
class Sanford::Worker
|
8
|
-
|
9
|
-
class UnitTests < Assert::Context
|
10
|
-
desc "Sanford::Worker"
|
11
|
-
setup do
|
12
|
-
@host_data = Sanford::HostData.new(TestHost)
|
13
|
-
@connection = FakeConnection.with_request('service', {})
|
14
|
-
@worker = Sanford::Worker.new(@host_data, @connection)
|
15
|
-
end
|
16
|
-
subject{ @worker }
|
17
|
-
|
18
|
-
should have_imeths :logger, :run
|
19
|
-
|
20
|
-
end
|
21
|
-
|
22
|
-
# `Worker`'s logic is tested in the system test: `request_handling_test.rb`
|
23
|
-
|
24
|
-
end
|