sanford 0.14.0 → 0.15.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -23,6 +23,8 @@ module Sanford::Server
23
23
  should have_imeths :receives_keep_alive
24
24
  should have_imeths :verbose_logging, :logger
25
25
  should have_imeths :init, :error
26
+ should have_imeths :on_worker_start, :on_worker_shutdown
27
+ should have_imeths :on_worker_sleep, :on_worker_wakeup
26
28
  should have_imeths :router, :template_source
27
29
 
28
30
  should "know its configuration" do
@@ -93,6 +95,22 @@ module Sanford::Server
93
95
  assert_includes new_error_proc, subject.configuration.error_procs
94
96
  end
95
97
 
98
+ should "allow reading/writing its configuration worker procs" do
99
+ p = proc{}
100
+
101
+ subject.on_worker_start(&p)
102
+ assert_equal [p], subject.configuration.worker_start_procs
103
+
104
+ subject.on_worker_shutdown(&p)
105
+ assert_equal [p], subject.configuration.worker_shutdown_procs
106
+
107
+ subject.on_worker_sleep(&p)
108
+ assert_equal [p], subject.configuration.worker_sleep_procs
109
+
110
+ subject.on_worker_wakeup(&p)
111
+ assert_equal [p], subject.configuration.worker_wakeup_procs
112
+ end
113
+
96
114
  should "allow reading/writing its configuration router" do
97
115
  new_router = Factory.string
98
116
  subject.router(new_router)
@@ -124,13 +142,26 @@ module Sanford::Server
124
142
  @server_class.name Factory.string
125
143
  @server_class.ip Factory.string
126
144
  @server_class.port Factory.integer
127
- @server_class.error{ Factory.string }
145
+
146
+ @error_procs = Factory.integer(3).times.map{ proc{} }
147
+ @error_procs.each{ |p| @server_class.error(&p) }
148
+
149
+ @start_procs = Factory.integer(3).times.map{ proc{} }
150
+ @shutdown_procs = Factory.integer(3).times.map{ proc{} }
151
+ @sleep_procs = Factory.integer(3).times.map{ proc{} }
152
+ @wakeup_procs = Factory.integer(3).times.map{ proc{} }
153
+ @start_procs.each { |p| @server_class.on_worker_start(&p) }
154
+ @shutdown_procs.each { |p| @server_class.on_worker_shutdown(&p) }
155
+ @sleep_procs.each { |p| @server_class.on_worker_sleep(&p) }
156
+ @wakeup_procs.each { |p| @server_class.on_worker_wakeup(&p) }
157
+
128
158
  @server_class.router do
129
159
  service Factory.string, TestHandler.to_s
130
160
  end
131
161
 
132
- @dat_tcp_server_spy = DatTCP::ServerSpy.new
162
+ @dat_tcp_server_spy = nil
133
163
  Assert.stub(DatTCP::Server, :new) do |&block|
164
+ @dat_tcp_server_spy = DatTCP::ServerSpy.new
134
165
  @dat_tcp_server_spy.serve_proc = block
135
166
  @dat_tcp_server_spy
136
167
  end
@@ -156,22 +187,34 @@ module Sanford::Server
156
187
  sd = subject.server_data
157
188
 
158
189
  assert_instance_of Sanford::ServerData, sd
159
- assert_equal configuration.name, sd.name
160
- assert_equal configuration.ip, sd.ip
161
- assert_equal configuration.port, sd.port
162
- assert_equal configuration.verbose_logging, sd.verbose_logging
163
- assert_equal configuration.receives_keep_alive, sd.receives_keep_alive
164
- assert_equal configuration.error_procs, sd.error_procs
165
- assert_equal configuration.routes, sd.routes.values
190
+ assert_equal configuration.name, sd.name
191
+ assert_equal configuration.ip, sd.ip
192
+ assert_equal configuration.port, sd.port
193
+ assert_equal configuration.verbose_logging, sd.verbose_logging
194
+ assert_equal configuration.receives_keep_alive, sd.receives_keep_alive
195
+ assert_equal configuration.error_procs, sd.error_procs
196
+ assert_equal configuration.worker_start_procs, sd.worker_start_procs
197
+ assert_equal configuration.worker_shutdown_procs, sd.worker_shutdown_procs
198
+ assert_equal configuration.worker_sleep_procs, sd.worker_sleep_procs
199
+ assert_equal configuration.worker_wakeup_procs, sd.worker_wakeup_procs
200
+ assert_equal configuration.routes, sd.routes.values
201
+
166
202
  assert_instance_of configuration.logger.class, sd.logger
167
203
  end
168
204
 
169
205
  should "know its dat tcp server" do
170
- assert_equal @dat_tcp_server_spy, subject.dat_tcp_server
206
+ assert_not_nil @dat_tcp_server_spy
171
207
  assert_not_nil @dat_tcp_server_spy.serve_proc
208
+
209
+ assert_equal @start_procs, @dat_tcp_server_spy.worker_start_procs
210
+ assert_equal @shutdown_procs, @dat_tcp_server_spy.worker_shutdown_procs
211
+ assert_equal @sleep_procs, @dat_tcp_server_spy.worker_sleep_procs
212
+ assert_equal @wakeup_procs, @dat_tcp_server_spy.worker_wakeup_procs
213
+
214
+ assert_equal @dat_tcp_server_spy, subject.dat_tcp_server
172
215
  end
173
216
 
174
- should "know its name, pid file" do
217
+ should "demeter its server data" do
175
218
  assert_equal subject.server_data.name, subject.name
176
219
  assert_equal subject.server_data.ip, subject.configured_ip
177
220
  assert_equal subject.server_data.port, subject.configured_port
@@ -195,6 +238,16 @@ module Sanford::Server
195
238
  assert_equal subject.server_data.port, @dat_tcp_server_spy.port
196
239
  end
197
240
 
241
+ should "write its ip and port back to its server data" do
242
+ ip = Factory.string
243
+ port = Factory.integer
244
+ assert_not_equal ip, subject.server_data.ip
245
+ assert_not_equal port, subject.server_data.port
246
+ subject.listen(ip, port)
247
+ assert_equal ip, subject.server_data.ip
248
+ assert_equal port, subject.server_data.port
249
+ end
250
+
198
251
  should "pass any args to its dat tcp server using `listen`" do
199
252
  ip, port = Factory.string, Factory.integer
200
253
  subject.listen(ip, port)
@@ -386,12 +439,21 @@ module Sanford::Server
386
439
 
387
440
  desc "Configuration"
388
441
  setup do
442
+ @orig_ip_env_var = ENV['SANFORD_IP']
443
+ @orig_port_env_var = ENV['SANFORD_PORT']
444
+ ENV.delete('SANFORD_IP')
445
+ ENV.delete('SANFORD_PORT')
446
+
389
447
  @configuration = Configuration.new.tap do |c|
390
448
  c.name Factory.string
391
- c.ip Factory.string
449
+ c.ip Factory.string
392
450
  c.port Factory.integer
393
451
  end
394
452
  end
453
+ teardown do
454
+ ENV['SANFORD_IP'] = @orig_ip_env_var
455
+ ENV['SANFORD_PORT'] = @orig_port_env_var
456
+ end
395
457
  subject{ @configuration }
396
458
 
397
459
  should have_options :name, :ip, :port, :pid_file
@@ -400,6 +462,8 @@ module Sanford::Server
400
462
  should have_options :template_source
401
463
  should have_accessors :init_procs, :error_procs
402
464
  should have_accessors :router
465
+ should have_readers :worker_start_procs, :worker_shutdown_procs
466
+ should have_readers :worker_sleep_procs, :worker_wakeup_procs
403
467
  should have_imeths :routes
404
468
  should have_imeths :to_hash
405
469
  should have_imeths :valid?, :validate!
@@ -424,10 +488,24 @@ module Sanford::Server
424
488
  assert_equal [], config.init_procs
425
489
  assert_equal [], config.error_procs
426
490
 
491
+ assert_equal [], subject.worker_start_procs
492
+ assert_equal [], subject.worker_shutdown_procs
493
+ assert_equal [], subject.worker_sleep_procs
494
+ assert_equal [], subject.worker_wakeup_procs
495
+
427
496
  assert_instance_of Sanford::Router, config.router
428
497
  assert_empty config.router.routes
429
498
  end
430
499
 
500
+ should "use env vars for its options if they are set" do
501
+ ENV['SANFORD_IP'] = Factory.string
502
+ ENV['SANFORD_PORT'] = Factory.integer.to_s
503
+
504
+ config = Configuration.new
505
+ assert_equal ENV['SANFORD_IP'], config.ip
506
+ assert_equal ENV['SANFORD_PORT'].to_i, config.port
507
+ end
508
+
431
509
  should "not be valid by default" do
432
510
  assert_false subject.valid?
433
511
  end
@@ -438,12 +516,16 @@ module Sanford::Server
438
516
  assert_equal subject.router.routes, subject.routes
439
517
  end
440
518
 
441
- should "include its init/error procs and router/routes in its `to_hash`" do
519
+ should "include its procs and router/routes in its `to_hash`" do
442
520
  config_hash = subject.to_hash
443
- assert_equal subject.init_procs, config_hash[:init_procs]
444
- assert_equal subject.error_procs, config_hash[:error_procs]
445
- assert_equal subject.router, config_hash[:router]
446
- assert_equal subject.routes, config_hash[:routes]
521
+ assert_equal subject.init_procs, config_hash[:init_procs]
522
+ assert_equal subject.error_procs, config_hash[:error_procs]
523
+ assert_equal subject.worker_start_procs, config_hash[:worker_start_procs]
524
+ assert_equal subject.worker_shutdown_procs, config_hash[:worker_shutdown_procs]
525
+ assert_equal subject.worker_sleep_procs, config_hash[:worker_sleep_procs]
526
+ assert_equal subject.worker_wakeup_procs, config_hash[:worker_wakeup_procs]
527
+ assert_equal subject.router, config_hash[:router]
528
+ assert_equal subject.routes, config_hash[:routes]
447
529
  end
448
530
 
449
531
  should "call its init procs when validated" do
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sanford
3
3
  version: !ruby/object:Gem::Version
4
- hash: 39
4
+ hash: 35
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 14
8
+ - 15
9
9
  - 0
10
- version: 0.14.0
10
+ version: 0.15.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Collin Redding
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2015-06-22 00:00:00 Z
19
+ date: 2015-09-10 00:00:00 Z
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
22
  requirement: &id001 !ruby/object:Gem::Requirement
@@ -24,11 +24,11 @@ dependencies:
24
24
  requirements:
25
25
  - - ~>
26
26
  - !ruby/object:Gem::Version
27
- hash: 7
27
+ hash: 5
28
28
  segments:
29
29
  - 0
30
- - 6
31
- version: "0.6"
30
+ - 7
31
+ version: "0.7"
32
32
  type: :runtime
33
33
  name: dat-tcp
34
34
  version_requirements: *id001
@@ -69,11 +69,11 @@ dependencies:
69
69
  requirements:
70
70
  - - ~>
71
71
  - !ruby/object:Gem::Version
72
- hash: 31
72
+ hash: 29
73
73
  segments:
74
74
  - 2
75
- - 14
76
- version: "2.14"
75
+ - 15
76
+ version: "2.15"
77
77
  type: :development
78
78
  name: assert
79
79
  version_requirements: *id004