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.
@@ -10,7 +10,7 @@ class Sanford::SanfordRunner
10
10
  desc "Sanford::SanfordRunner"
11
11
  setup do
12
12
  @handler_class = TestServiceHandler
13
- @runner_class = Sanford::SanfordRunner
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 = @runner.handler
37
+ @handler = @runner.handler
38
38
  @response = @runner.run
39
39
  end
40
- subject{ @response }
41
40
 
42
- should "run the handlers before callbacks" do
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 handlers init" do
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 handlers after callbacks" do
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 RunHaltInBeforeTests < UnitTests
65
- desc "running a handler that halts in a before callback"
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' => 'before'
69
- }).tap(&:run)
70
- @handler = runner.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 subject.first_before_call_order
76
- assert_nil subject.second_before_call_order
77
- assert_nil subject.init_call_order
78
- assert_nil subject.run_call_order
79
- assert_nil subject.first_after_call_order
80
- assert_nil subject.second_after_call_order
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 RunHandlerHaltInitTests < UnitTests
86
- desc "running a handler that halts in init"
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' => 'init'
90
- }).tap(&:run)
91
- @handler = runner.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 subject.first_before_call_order
97
- assert_not_nil subject.second_before_call_order
98
- assert_not_nil subject.init_call_order
99
- assert_nil subject.run_call_order
100
- assert_nil subject.first_after_call_order
101
- assert_nil subject.second_after_call_order
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 RunHandlerHaltRunTests < UnitTests
107
- desc "running a handler that halts in run"
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' => 'run'
111
- }).tap(&:run)
112
- @handler = runner.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{ @handler }
129
+ subject{ @runner }
115
130
 
116
131
  should "stop processing when the halt is called" do
117
- assert_not_nil subject.first_before_call_order
118
- assert_not_nil subject.second_before_call_order
119
- assert_not_nil subject.init_call_order
120
- assert_not_nil subject.run_call_order
121
- assert_nil subject.first_after_call_order
122
- assert_nil subject.second_after_call_order
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 RunHandlerHaltAfterTests < UnitTests
128
- desc "running a handler that halts in a after callback"
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
- }).tap(&:run)
133
- @handler = runner.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 subject.first_before_call_order
139
- assert_not_nil subject.second_before_call_order
140
- assert_not_nil subject.init_call_order
141
- assert_not_nil subject.run_call_order
142
- assert_not_nil subject.first_after_call_order
143
- assert_nil subject.second_after_call_order
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!; @init_call_order = next_call_order; halt_if('init'); end
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 => Factory.string,
19
- :ip => Factory.string,
20
- :port => Factory.integer,
21
- :pid_file => Factory.file_path,
22
- :receives_keep_alive => Factory.boolean,
23
- :verbose_logging => Factory.boolean,
24
- :logger => Factory.string,
25
- :template_source => Factory.string,
26
- :init_procs => Factory.integer(3).times.map{ proc{} },
27
- :error_procs => Factory.integer(3).times.map{ proc{} },
28
- :worker_start_procs => Factory.integer(3).times.map{ proc{} },
29
- :worker_shutdown_procs => Factory.integer(3).times.map{ proc{} },
30
- :worker_sleep_procs => Factory.integer(3).times.map{ proc{} },
31
- :worker_wakeup_procs => Factory.integer(3).times.map{ proc{} },
32
- :router => Factory.string,
33
- :routes => [@route]
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 :verbose_logging, :logger, :template_source
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
- assert_nil server_data.template_source
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