sanford 0.15.1 → 0.16.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 +2 -2
- data/bench/config.sanford +11 -4
- data/bench/report.rb +1 -1
- data/bench/report.txt +37 -31
- data/lib/sanford/connection_handler.rb +0 -5
- data/lib/sanford/runner.rb +34 -28
- data/lib/sanford/sanford_runner.rb +5 -12
- data/lib/sanford/server.rb +57 -117
- data/lib/sanford/server_data.rb +13 -9
- data/lib/sanford/service_handler.rb +50 -23
- data/lib/sanford/test_runner.rb +30 -26
- data/lib/sanford/version.rb +1 -1
- data/lib/sanford/worker.rb +106 -0
- data/sanford.gemspec +2 -1
- data/test/support/app_server.rb +7 -4
- data/test/system/server_tests.rb +7 -3
- data/test/system/service_handler_tests.rb +1 -2
- data/test/unit/connection_handler_tests.rb +0 -16
- data/test/unit/runner_tests.rb +152 -41
- data/test/unit/sanford_runner_tests.rb +105 -63
- data/test/unit/server_data_tests.rb +34 -25
- data/test/unit/server_tests.rb +132 -210
- data/test/unit/service_handler_tests.rb +137 -64
- data/test/unit/test_runner_tests.rb +40 -101
- data/test/unit/worker_tests.rb +185 -0
- metadata +32 -15
- data/lib/sanford/test_helpers.rb +0 -19
- /data/{LICENSE.txt → LICENSE} +0 -0
@@ -10,7 +10,7 @@ class Sanford::SanfordRunner
|
|
10
10
|
desc "Sanford::SanfordRunner"
|
11
11
|
setup do
|
12
12
|
@handler_class = TestServiceHandler
|
13
|
-
@runner_class
|
13
|
+
@runner_class = Sanford::SanfordRunner
|
14
14
|
end
|
15
15
|
subject{ @runner_class }
|
16
16
|
|
@@ -34,113 +34,149 @@ class Sanford::SanfordRunner
|
|
34
34
|
class RunTests < InitTests
|
35
35
|
desc "and run"
|
36
36
|
setup do
|
37
|
-
@handler
|
37
|
+
@handler = @runner.handler
|
38
38
|
@response = @runner.run
|
39
39
|
end
|
40
|
-
subject{ @response }
|
41
40
|
|
42
|
-
should "run the
|
41
|
+
should "run the handler's before callbacks" do
|
43
42
|
assert_equal 1, @handler.first_before_call_order
|
44
43
|
assert_equal 2, @handler.second_before_call_order
|
45
44
|
end
|
46
45
|
|
47
|
-
should "run the
|
46
|
+
should "run the handler's init and run methods" do
|
48
47
|
assert_equal 3, @handler.init_call_order
|
49
|
-
end
|
50
|
-
|
51
|
-
should "run the handlers run and use its result to build a response" do
|
52
48
|
assert_equal 4, @handler.run_call_order
|
53
|
-
assert_instance_of Sanford::Protocol::Response, subject
|
54
|
-
assert_equal @handler.response_data, subject.data
|
55
49
|
end
|
56
50
|
|
57
|
-
should "run the
|
51
|
+
should "run the handler's after callbacks" do
|
58
52
|
assert_equal 5, @handler.first_after_call_order
|
59
53
|
assert_equal 6, @handler.second_after_call_order
|
60
54
|
end
|
61
55
|
|
56
|
+
should "return its `to_response` value" do
|
57
|
+
assert_equal subject.to_response, @response
|
58
|
+
end
|
59
|
+
|
62
60
|
end
|
63
61
|
|
64
|
-
class
|
65
|
-
desc "
|
62
|
+
class RunWithInitHaltTests < UnitTests
|
63
|
+
desc "with a handler that halts on init"
|
66
64
|
setup do
|
67
|
-
runner = @runner_class.new(@handler_class, :params => {
|
68
|
-
'halt' => '
|
69
|
-
})
|
70
|
-
@handler
|
65
|
+
@runner = @runner_class.new(@handler_class, :params => {
|
66
|
+
'halt' => 'init'
|
67
|
+
})
|
68
|
+
@handler = @runner.handler
|
69
|
+
@response = @runner.run
|
70
|
+
end
|
71
|
+
subject{ @runner }
|
72
|
+
|
73
|
+
should "run the before and after callbacks despite the halt" do
|
74
|
+
assert_not_nil @handler.first_before_call_order
|
75
|
+
assert_not_nil @handler.second_before_call_order
|
76
|
+
assert_not_nil @handler.first_after_call_order
|
77
|
+
assert_not_nil @handler.second_after_call_order
|
71
78
|
end
|
72
|
-
subject{ @handler }
|
73
79
|
|
74
80
|
should "stop processing when the halt is called" do
|
75
|
-
assert_not_nil
|
76
|
-
assert_nil
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
+
assert_not_nil @handler.init_call_order
|
82
|
+
assert_nil @handler.run_call_order
|
83
|
+
end
|
84
|
+
|
85
|
+
should "return its `to_response` value despite the halt" do
|
86
|
+
assert_equal subject.to_response, @response
|
81
87
|
end
|
82
88
|
|
83
89
|
end
|
84
90
|
|
85
|
-
class
|
86
|
-
desc "
|
91
|
+
class RunWithRunHaltTests < UnitTests
|
92
|
+
desc "when run with a handler that halts on run"
|
87
93
|
setup do
|
88
|
-
runner = @runner_class.new(@handler_class, :params => {
|
89
|
-
'halt' => '
|
90
|
-
})
|
91
|
-
@handler
|
94
|
+
@runner = @runner_class.new(@handler_class, :params => {
|
95
|
+
'halt' => 'run'
|
96
|
+
})
|
97
|
+
@handler = @runner.handler
|
98
|
+
@response = @runner.run
|
99
|
+
end
|
100
|
+
subject{ @runner }
|
101
|
+
|
102
|
+
should "run the before and after callbacks despite the halt" do
|
103
|
+
assert_not_nil @handler.first_before_call_order
|
104
|
+
assert_not_nil @handler.second_before_call_order
|
105
|
+
assert_not_nil @handler.first_after_call_order
|
106
|
+
assert_not_nil @handler.second_after_call_order
|
92
107
|
end
|
93
|
-
subject{ @handler }
|
94
108
|
|
95
109
|
should "stop processing when the halt is called" do
|
96
|
-
assert_not_nil
|
97
|
-
assert_not_nil
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
110
|
+
assert_not_nil @handler.init_call_order
|
111
|
+
assert_not_nil @handler.run_call_order
|
112
|
+
end
|
113
|
+
|
114
|
+
should "return its `to_response` value despite the halt" do
|
115
|
+
assert_equal subject.to_response, @response
|
102
116
|
end
|
103
117
|
|
104
118
|
end
|
105
119
|
|
106
|
-
class
|
107
|
-
desc "
|
120
|
+
class RunWithBeforeHaltTests < UnitTests
|
121
|
+
desc "when run with a handler that halts in an after callback"
|
108
122
|
setup do
|
109
|
-
runner = @runner_class.new(@handler_class, :params => {
|
110
|
-
'halt' => '
|
111
|
-
})
|
112
|
-
@handler
|
123
|
+
@runner = @runner_class.new(@handler_class, :params => {
|
124
|
+
'halt' => 'before'
|
125
|
+
})
|
126
|
+
@handler = @runner.handler
|
127
|
+
@response = @runner.run
|
113
128
|
end
|
114
|
-
subject{ @
|
129
|
+
subject{ @runner }
|
115
130
|
|
116
131
|
should "stop processing when the halt is called" do
|
117
|
-
assert_not_nil
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
assert_nil
|
132
|
+
assert_not_nil @handler.first_before_call_order
|
133
|
+
assert_nil @handler.second_before_call_order
|
134
|
+
end
|
135
|
+
|
136
|
+
should "not run the after callbacks b/c of the halt" do
|
137
|
+
assert_nil @handler.first_after_call_order
|
138
|
+
assert_nil @handler.second_after_call_order
|
139
|
+
end
|
140
|
+
|
141
|
+
should "not run the handler's init and run b/c of the halt" do
|
142
|
+
assert_nil @handler.init_call_order
|
143
|
+
assert_nil @handler.run_call_order
|
144
|
+
end
|
145
|
+
|
146
|
+
should "return its `to_response` value despite the halt" do
|
147
|
+
assert_equal subject.to_response, @response
|
123
148
|
end
|
124
149
|
|
125
150
|
end
|
126
151
|
|
127
|
-
class
|
128
|
-
desc "
|
152
|
+
class RunWithAfterHaltTests < UnitTests
|
153
|
+
desc "when run with a handler that halts in an after callback"
|
129
154
|
setup do
|
130
|
-
runner = @runner_class.new(@handler_class, :params => {
|
155
|
+
@runner = @runner_class.new(@handler_class, :params => {
|
131
156
|
'halt' => 'after'
|
132
|
-
})
|
133
|
-
@handler
|
157
|
+
})
|
158
|
+
@handler = @runner.handler
|
159
|
+
@response = @runner.run
|
160
|
+
end
|
161
|
+
subject{ @runner }
|
162
|
+
|
163
|
+
should "run the before callback despite the halt" do
|
164
|
+
assert_not_nil @handler.first_before_call_order
|
165
|
+
assert_not_nil @handler.second_before_call_order
|
166
|
+
end
|
167
|
+
|
168
|
+
should "run the handler's init and run despite the halt" do
|
169
|
+
assert_not_nil @handler.init_call_order
|
170
|
+
assert_not_nil @handler.run_call_order
|
134
171
|
end
|
135
|
-
subject{ @handler }
|
136
172
|
|
137
173
|
should "stop processing when the halt is called" do
|
138
|
-
assert_not_nil
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
174
|
+
assert_not_nil @handler.first_after_call_order
|
175
|
+
assert_nil @handler.second_after_call_order
|
176
|
+
end
|
177
|
+
|
178
|
+
should "return its `to_response` value despite the halt" do
|
179
|
+
assert_equal subject.to_response, @response
|
144
180
|
end
|
145
181
|
|
146
182
|
end
|
@@ -159,7 +195,11 @@ class Sanford::SanfordRunner
|
|
159
195
|
after{ @first_after_call_order = next_call_order; halt_if('after') }
|
160
196
|
after{ @second_after_call_order = next_call_order }
|
161
197
|
|
162
|
-
def init
|
198
|
+
def init!
|
199
|
+
@init_call_order = next_call_order
|
200
|
+
halt_if('init')
|
201
|
+
end
|
202
|
+
|
163
203
|
def run!
|
164
204
|
@run_call_order = next_call_order
|
165
205
|
halt_if('run')
|
@@ -169,9 +209,11 @@ class Sanford::SanfordRunner
|
|
169
209
|
private
|
170
210
|
|
171
211
|
def next_call_order; @order ||= 0; @order += 1; end
|
212
|
+
|
172
213
|
def halt_if(value)
|
173
214
|
halt Factory.integer if params['halt'] == value
|
174
215
|
end
|
216
|
+
|
175
217
|
end
|
176
218
|
|
177
219
|
end
|
@@ -15,22 +15,22 @@ class Sanford::ServerData
|
|
15
15
|
|
16
16
|
@route = Sanford::Route.new(Factory.string, TestHandler.to_s).tap(&:validate!)
|
17
17
|
@config_hash = {
|
18
|
-
:name
|
19
|
-
:ip
|
20
|
-
:port
|
21
|
-
:pid_file
|
22
|
-
:receives_keep_alive
|
23
|
-
:
|
24
|
-
:
|
25
|
-
:
|
26
|
-
:
|
27
|
-
:
|
28
|
-
:
|
29
|
-
:
|
30
|
-
:
|
31
|
-
:
|
32
|
-
:router
|
33
|
-
:routes
|
18
|
+
:name => Factory.string,
|
19
|
+
:ip => Factory.string,
|
20
|
+
:port => Factory.integer,
|
21
|
+
:pid_file => Factory.file_path,
|
22
|
+
:receives_keep_alive => Factory.boolean,
|
23
|
+
:worker_class => Class.new,
|
24
|
+
:worker_params => { Factory.string => Factory.string },
|
25
|
+
:num_workers => Factory.integer,
|
26
|
+
:verbose_logging => Factory.boolean,
|
27
|
+
:logger => Factory.string,
|
28
|
+
:template_source => Factory.string,
|
29
|
+
:shutdown_timeout => Factory.integer,
|
30
|
+
:init_procs => Factory.integer(3).times.map{ proc{} },
|
31
|
+
:error_procs => Factory.integer(3).times.map{ proc{} },
|
32
|
+
:router => Factory.string,
|
33
|
+
:routes => [@route]
|
34
34
|
}
|
35
35
|
@server_data = Sanford::ServerData.new(@config_hash)
|
36
36
|
end
|
@@ -43,10 +43,10 @@ class Sanford::ServerData
|
|
43
43
|
should have_readers :name
|
44
44
|
should have_readers :pid_file
|
45
45
|
should have_readers :receives_keep_alive
|
46
|
-
should have_readers :
|
46
|
+
should have_readers :worker_class, :worker_params, :num_workers
|
47
|
+
should have_readers :debug, :logger, :dtcp_logger, :verbose_logging
|
48
|
+
should have_readers :template_source, :shutdown_timeout
|
47
49
|
should have_readers :init_procs, :error_procs
|
48
|
-
should have_readers :worker_start_procs, :worker_shutdown_procs
|
49
|
-
should have_readers :worker_sleep_procs, :worker_wakeup_procs
|
50
50
|
should have_readers :router, :routes
|
51
51
|
should have_accessors :ip, :port
|
52
52
|
|
@@ -59,18 +59,20 @@ class Sanford::ServerData
|
|
59
59
|
|
60
60
|
assert_equal h[:receives_keep_alive], subject.receives_keep_alive
|
61
61
|
|
62
|
+
assert_equal h[:worker_class], subject.worker_class
|
63
|
+
assert_equal h[:worker_params], subject.worker_params
|
64
|
+
assert_equal h[:num_workers], subject.num_workers
|
65
|
+
|
62
66
|
assert_equal h[:verbose_logging], subject.verbose_logging
|
63
67
|
assert_equal h[:logger], subject.logger
|
68
|
+
|
64
69
|
assert_equal h[:template_source], subject.template_source
|
65
70
|
|
71
|
+
assert_equal h[:shutdown_timeout], subject.shutdown_timeout
|
72
|
+
|
66
73
|
assert_equal h[:init_procs], subject.init_procs
|
67
74
|
assert_equal h[:error_procs], subject.error_procs
|
68
75
|
|
69
|
-
assert_equal h[:worker_start_procs], subject.worker_start_procs
|
70
|
-
assert_equal h[:worker_shutdown_procs], subject.worker_shutdown_procs
|
71
|
-
assert_equal h[:worker_sleep_procs], subject.worker_sleep_procs
|
72
|
-
assert_equal h[:worker_wakeup_procs], subject.worker_wakeup_procs
|
73
|
-
|
74
76
|
assert_equal h[:router], subject.router
|
75
77
|
end
|
76
78
|
|
@@ -113,9 +115,16 @@ class Sanford::ServerData
|
|
113
115
|
|
114
116
|
assert_false server_data.receives_keep_alive
|
115
117
|
|
118
|
+
assert_nil server_data.worker_class
|
119
|
+
assert_equal({}, server_data.worker_params)
|
120
|
+
assert_nil server_data.num_workers
|
121
|
+
|
116
122
|
assert_false server_data.verbose_logging
|
117
123
|
assert_nil server_data.logger
|
118
|
-
|
124
|
+
|
125
|
+
assert_nil server_data.template_source
|
126
|
+
|
127
|
+
assert_nil server_data.shutdown_timeout
|
119
128
|
|
120
129
|
assert_equal [], server_data.init_procs
|
121
130
|
assert_equal [], server_data.error_procs
|