sanford 0.6.3 → 0.6.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. data/.gitignore +2 -2
  2. data/Gemfile +4 -3
  3. data/LICENSE.txt +2 -2
  4. data/README.md +2 -2
  5. data/Rakefile +0 -1
  6. data/bin/sanford +1 -1
  7. data/lib/sanford/cli.rb +25 -12
  8. data/lib/sanford/host_data.rb +1 -0
  9. data/lib/sanford/server.rb +3 -0
  10. data/lib/sanford/service_handler.rb +8 -26
  11. data/lib/sanford/test_runner.rb +1 -0
  12. data/lib/sanford/version.rb +1 -1
  13. data/lib/sanford/worker.rb +3 -1
  14. data/lib/sanford.rb +1 -3
  15. data/sanford.gemspec +2 -2
  16. data/test/helper.rb +9 -8
  17. data/test/support/helpers.rb +0 -2
  18. data/test/system/{request_handling_test.rb → request_handling_tests.rb} +21 -22
  19. data/test/unit/{config_test.rb → config_tests.rb} +1 -1
  20. data/test/unit/{error_handler_test.rb → error_handler_tests.rb} +4 -4
  21. data/test/unit/{host_configuration_test.rb → host_configuration_tests.rb} +1 -1
  22. data/test/unit/{host_data_test.rb → host_data_tests.rb} +1 -1
  23. data/test/unit/{host_test.rb → host_tests.rb} +2 -2
  24. data/test/unit/{host_version_group_test.rb → host_version_group_tests.rb} +1 -1
  25. data/test/unit/{hosts_test.rb → hosts_tests.rb} +2 -2
  26. data/test/unit/manager_pid_file_tests.rb +60 -0
  27. data/test/unit/{manager_test.rb → manager_tests.rb} +5 -6
  28. data/test/unit/{runner_test.rb → runner_tests.rb} +1 -1
  29. data/test/unit/{server_test.rb → server_tests.rb} +2 -3
  30. data/test/unit/{service_handler_test.rb → service_handler_tests.rb} +5 -6
  31. data/test/unit/{worker_test.rb → worker_tests.rb} +1 -2
  32. data/tmp/.gitkeep +0 -0
  33. metadata +35 -34
  34. data/test/unit/manager_pid_file_test.rb +0 -45
data/.gitignore CHANGED
@@ -1,5 +1,7 @@
1
1
  *.gem
2
+ *.log
2
3
  *.rbc
4
+ .rbx/
3
5
  .bundle
4
6
  .config
5
7
  .yardoc
@@ -15,5 +17,3 @@ spec/reports
15
17
  test/tmp
16
18
  test/version_tmp
17
19
  tmp
18
- log/*.output
19
- .pid
data/Gemfile CHANGED
@@ -1,7 +1,8 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- # Specify your gem's dependencies in sanford.gemspec
4
3
  gemspec
5
4
 
6
- gem 'bson_ext'
7
- gem 'rake', '~>0.9.2'
5
+ gem 'rake'
6
+ gem 'pry'
7
+
8
+ gem 'bson_ext', '~>1.7'
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2012 jcredding
1
+ Copyright (c) 2012-Present Collin Redding and Kelly Redding
2
2
 
3
3
  MIT License
4
4
 
@@ -19,4 +19,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
19
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
20
  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
21
  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # Sanford
2
2
 
3
- Sanford: simple hosts for Sanford services. Define hosts for versioned services. Setup handlers for the services. Run the host as a daemon.
3
+ Sanford TCP protocol server for hosting services. Define hosts for versioned services. Setup handlers for the services. Run the host as a daemon.
4
4
 
5
- Sanford uses [Sanford::Protocol](https://github.com/redding/sanford-protocol) to communicate with clients.
5
+ Sanford uses [Sanford::Protocol](https://github.com/redding/sanford-protocol) to communicate with clients. Check out [AndSon](https://github.com/redding/and-son) for a Ruby Sanford protocol client.
6
6
 
7
7
  ## Usage
8
8
 
data/Rakefile CHANGED
@@ -1,3 +1,2 @@
1
1
  require "bundler/gem_tasks"
2
-
3
2
  require 'bench/tasks'
data/bin/sanford CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
  #
3
- # Copyright (c) 2013 Collin Redding & Kelly Redding
3
+ # Copyright (c) 2012 Collin Redding & Kelly Redding
4
4
  #
5
5
 
6
6
  require 'sanford/cli'
data/lib/sanford/cli.rb CHANGED
@@ -96,27 +96,32 @@ module Sanford
96
96
  def run!(daemonize = false)
97
97
  daemonize!(true) if daemonize
98
98
  Sanford::Server.new(@host, @server_options).tap do |server|
99
- log "Starting server for #{@host.name}"
99
+ log "Starting #{@host.name} server..."
100
100
 
101
101
  server.listen(*@config.listen_args)
102
+ $0 = ProcessName.new(@host.name, server.ip, server.port)
102
103
  log "Listening on #{server.ip}:#{server.port}"
103
- log "PID: #{Process.pid}"
104
104
 
105
- $0 = ProcessName.new(@host.name, server.ip, server.port)
106
105
  @config.pid_file.write
106
+ log "PID: #{Process.pid}"
107
107
 
108
108
  Signal.trap("TERM"){ self.stop!(server) }
109
109
  Signal.trap("INT"){ self.halt!(server) }
110
110
  Signal.trap("USR2"){ self.restart!(server) }
111
111
 
112
- server.run(@config.client_file_descriptors).join
112
+ server_thread = server.run(@config.client_file_descriptors)
113
+ log "#{@host.name} server started and ready."
114
+ server_thread.join
113
115
  end
116
+ rescue RuntimeError => err
117
+ log "Error: #{err.message}"
118
+ log "#{@host.name} server never started."
114
119
  ensure
115
120
  @config.pid_file.remove
116
121
  end
117
122
 
118
123
  def restart!(server)
119
- log "Restarting the server..."
124
+ log "Restarting #{@host.name} server..."
120
125
  server.pause
121
126
  log "server paused"
122
127
 
@@ -124,21 +129,21 @@ module Sanford
124
129
  ENV['SANFORD_SERVER_FD'] = server.file_descriptor.to_s
125
130
  ENV['SANFORD_CLIENT_FDS'] = server.client_file_descriptors.join(',')
126
131
 
127
- @logger.info "calling exec ..."
132
+ log "calling exec ..."
128
133
  Dir.chdir @restart_cmd.dir
129
134
  Kernel.exec(*@restart_cmd.argv)
130
135
  end
131
136
 
132
137
  def stop!(server)
133
- log "Stopping the server..."
138
+ log "Stopping #{@host.name} server..."
134
139
  server.stop
135
- log "Done"
140
+ log "#{@host.name} server stopped."
136
141
  end
137
142
 
138
143
  def halt!(server)
139
- log "Halting the server..."
144
+ log "Halting #{@host.name} server..."
140
145
  server.halt false
141
- log "Done"
146
+ log "#{@host.name} server halted."
142
147
  end
143
148
 
144
149
  # Full explanation: http://www.steve.org.uk/Reference/Unix/faq_2.html#SEC16
@@ -232,8 +237,10 @@ module Sanford
232
237
  end
233
238
 
234
239
  class PIDFile
240
+ DEF_FILE = '/dev/null'
241
+
235
242
  def initialize(path)
236
- @path = (path || '/dev/null').to_s
243
+ @path = (path || DEF_FILE).to_s
237
244
  end
238
245
 
239
246
  def pid
@@ -242,7 +249,13 @@ module Sanford
242
249
  end
243
250
 
244
251
  def write
245
- File.open(@path, 'w'){|f| f.puts Process.pid }
252
+ begin
253
+ File.open(@path, 'w'){|f| f.puts Process.pid }
254
+ rescue Errno::ENOENT => err
255
+ e = RuntimeError.new("Can't write pid to file `#{@path}`")
256
+ e.set_backtrace(err.backtrace)
257
+ raise e
258
+ end
246
259
  end
247
260
 
248
261
  def remove
@@ -11,6 +11,7 @@ module Sanford
11
11
 
12
12
  # NOTE: The `name` attribute shouldn't be removed, it is used to identify
13
13
  # a `HostData`, particularly in error handlers
14
+
14
15
  attr_reader :name, :logger, :verbose, :keep_alive, :runner, :error_procs
15
16
 
16
17
  def initialize(service_host, options = nil)
@@ -25,6 +25,7 @@ module Sanford
25
25
  # communication, we have all the information we need to send up front and
26
26
  # are closing the connection, so it doesn't need to buffer.
27
27
  # See http://linux.die.net/man/7/tcp
28
+
28
29
  def configure_tcp_server(tcp_server)
29
30
  tcp_server.setsockopt(::Socket::IPPROTO_TCP, ::Socket::TCP_NODELAY, true)
30
31
  end
@@ -37,6 +38,7 @@ module Sanford
37
38
  # a new instance of the handler for every request.
38
39
  # When using TCP_CORK, you "cork" the socket, handle it and then "uncork"
39
40
  # it, see the `TCPCork` module for more info.
41
+
40
42
  def serve(socket)
41
43
  TCPCork.apply(socket)
42
44
  connection = Connection.new(socket)
@@ -88,6 +90,7 @@ module Sanford
88
90
  # to HTTP, it doesn't receive sporadic packets, it has all it's data
89
91
  # come in at once.
90
92
  # For more information: http://baus.net/on-tcp_cork
93
+
91
94
  if RUBY_PLATFORM =~ /linux/
92
95
  # 3 == TCP_CORK
93
96
  def self.apply(socket)
@@ -52,17 +52,10 @@ module Sanford
52
52
 
53
53
  protected
54
54
 
55
- def before_init
56
- end
57
-
58
- def after_init
59
- end
60
-
61
- def before_run
62
- end
63
-
64
- def after_run
65
- end
55
+ def before_init; end
56
+ def after_init; end
57
+ def before_run; end
58
+ def after_run; end
66
59
 
67
60
  # Helpers
68
61
 
@@ -70,21 +63,10 @@ module Sanford
70
63
  handler_class.run(params || {}, self.logger)
71
64
  end
72
65
 
73
- def halt(*args)
74
- @sanford_runner.halt(*args)
75
- end
76
-
77
- def request
78
- @sanford_runner.request
79
- end
80
-
81
- def params
82
- self.request.params
83
- end
84
-
85
- def logger
86
- @sanford_runner.logger
87
- end
66
+ def halt(*args); @sanford_runner.halt(*args); end
67
+ def request; @sanford_runner.request; end
68
+ def params; self.request.params; end
69
+ def logger; @sanford_runner.logger; end
88
70
 
89
71
  def run_callback(callback)
90
72
  self.send(callback.to_s)
@@ -19,6 +19,7 @@ module Sanford
19
19
  # we override the `run` method because the TestRunner wants to control
20
20
  # storing any generated response. If `init` generated a response, we don't
21
21
  # want to `run` at all.
22
+
22
23
  def run
23
24
  @response ||= build_response catch_halt{ @handler.run }
24
25
  end
@@ -1,3 +1,3 @@
1
1
  module Sanford
2
- VERSION = "0.6.3"
2
+ VERSION = "0.6.4"
3
3
  end
@@ -9,7 +9,9 @@ module Sanford
9
9
 
10
10
  class Worker
11
11
 
12
- ProcessedService = Struct.new(:request, :handler_class, :response, :exception, :time_taken)
12
+ ProcessedService = Struct.new(*[
13
+ :request, :handler_class, :response, :exception, :time_taken
14
+ ])
13
15
 
14
16
  attr_reader :logger
15
17
 
data/lib/sanford.rb CHANGED
@@ -1,15 +1,13 @@
1
- module Sanford; end
2
-
3
1
  require 'ns-options'
4
2
  require 'pathname'
5
3
  require 'set'
6
4
 
5
+ require 'sanford/version'
7
6
  require 'sanford/host'
8
7
  require 'sanford/logger'
9
8
  require 'sanford/runner'
10
9
  require 'sanford/server'
11
10
  require 'sanford/service_handler'
12
- require 'sanford/version'
13
11
 
14
12
  ENV['SANFORD_SERVICES_FILE'] ||= 'config/services'
15
13
 
data/sanford.gemspec CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |gem|
8
8
  gem.version = Sanford::VERSION
9
9
  gem.authors = ["Collin Redding", "Kelly Redding"]
10
10
  gem.email = ["collin.redding@me.com", "kelly@kellyredding.com"]
11
- gem.description = "Simple hosts for Sanford services."
12
- gem.summary = "Simple hosts for Sanford services."
11
+ gem.description = "Sanford TCP protocol server for hosting services"
12
+ gem.summary = "Sanford TCP protocol server for hosting services"
13
13
  gem.homepage = "https://github.com/redding/sanford"
14
14
 
15
15
  gem.files = `git ls-files`.split($/)
data/test/helper.rb CHANGED
@@ -1,11 +1,16 @@
1
- ENV['SANFORD_PROTOCOL_DEBUG'] = 'yes'
1
+ # this file is automatically required when you run `assert`
2
+ # put any test helpers here
2
3
 
3
- require 'ostruct'
4
+ # add the root dir to the load path
5
+ $LOAD_PATH.unshift(File.expand_path("../..", __FILE__))
4
6
 
5
- ROOT = File.expand_path('../..', __FILE__)
7
+ require 'pry' # require pry for debugging (`binding.pry`)
8
+ require 'assert-mocha' if defined?(Assert)
6
9
 
7
- require 'sanford'
10
+ ENV['SANFORD_PROTOCOL_DEBUG'] = 'yes'
8
11
 
12
+ require 'sanford'
13
+ ROOT = File.expand_path('../..', __FILE__)
9
14
  Sanford.configure do |config|
10
15
  config.services_file = File.join(ROOT, 'test/support/services')
11
16
  end
@@ -15,7 +20,3 @@ require 'test/support/fake_connection'
15
20
  require 'test/support/service_handlers'
16
21
  require 'test/support/simple_client'
17
22
  require 'test/support/helpers'
18
-
19
- if defined?(Assert)
20
- require 'assert-mocha'
21
- end
@@ -1,5 +1,4 @@
1
1
  module Test
2
-
3
2
  module SpawnServerHelper
4
3
 
5
4
  def start_server(host, &block)
@@ -15,5 +14,4 @@ module Test
15
14
  end
16
15
 
17
16
  end
18
-
19
17
  end
@@ -1,11 +1,10 @@
1
- # These tests are intended as a high level test against Sanford's server. They
2
- # use fake and real connections to test how Sanford behaves.
3
-
4
1
  require 'assert'
5
-
6
2
  require 'sanford-protocol/test/fake_socket'
7
3
 
8
- class RequestHandlingTest < Assert::Context
4
+ # These tests are intended as a high level test against Sanford's server. They
5
+ # use fake and real connections to test how Sanford behaves.
6
+
7
+ class RequestHandlingTests < Assert::Context
9
8
  desc "Sanford's handling of requests"
10
9
  setup do
11
10
  @env_sanford_protocol_debug = ENV['SANFORD_PROTOCOL_DEBUG']
@@ -18,13 +17,13 @@ class RequestHandlingTest < Assert::Context
18
17
  ENV['SANFORD_PROTOCOL_DEBUG'] = @env_sanford_protocol_debug
19
18
  end
20
19
 
21
- class FakeConnectionTest < RequestHandlingTest
20
+ class FakeConnectionTests < RequestHandlingTests
22
21
  setup do
23
22
  @host_data = Sanford::HostData.new(TestHost)
24
23
  end
25
24
  end
26
25
 
27
- class EchoTest < FakeConnectionTest
26
+ class EchoTests < FakeConnectionTests
28
27
  desc "running a request for the echo server"
29
28
  setup do
30
29
  @connection = FakeConnection.with_request('v1', 'echo', { :message => 'test' })
@@ -48,7 +47,7 @@ class RequestHandlingTest < Assert::Context
48
47
 
49
48
  end
50
49
 
51
- class MissingServiceVersionTest < FakeConnectionTest
50
+ class MissingServiceVersionTests < FakeConnectionTests
52
51
  desc "running a request with no service version"
53
52
  setup do
54
53
  request_hash = Sanford::Protocol::Request.new('v1', 'what', {}).to_hash
@@ -71,7 +70,7 @@ class RequestHandlingTest < Assert::Context
71
70
 
72
71
  end
73
72
 
74
- class MissingServiceNameTest < FakeConnectionTest
73
+ class MissingServiceNameTests < FakeConnectionTests
75
74
  desc "running a request with no service name"
76
75
  setup do
77
76
  request_hash = Sanford::Protocol::Request.new('v1', 'what', {}).to_hash
@@ -94,7 +93,7 @@ class RequestHandlingTest < Assert::Context
94
93
 
95
94
  end
96
95
 
97
- class NotFoundServiceTest < FakeConnectionTest
96
+ class NotFoundServiceTests < FakeConnectionTests
98
97
  desc "running a request with no matching service name"
99
98
  setup do
100
99
  @connection = FakeConnection.with_request('v1', 'what', {})
@@ -114,7 +113,7 @@ class RequestHandlingTest < Assert::Context
114
113
 
115
114
  end
116
115
 
117
- class ErrorServiceTest < FakeConnectionTest
116
+ class ErrorServiceTests < FakeConnectionTests
118
117
  desc "running a request that errors on the server"
119
118
  setup do
120
119
  @connection = FakeConnection.with_request('v1', 'bad', {})
@@ -134,7 +133,7 @@ class RequestHandlingTest < Assert::Context
134
133
 
135
134
  end
136
135
 
137
- class HaltTest < FakeConnectionTest
136
+ class HaltTests < FakeConnectionTests
138
137
  desc "running a request that halts"
139
138
  setup do
140
139
  @connection = FakeConnection.with_request('v1', 'halt_it', {})
@@ -152,7 +151,7 @@ class RequestHandlingTest < Assert::Context
152
151
 
153
152
  end
154
153
 
155
- class AuthorizeRequestTest < FakeConnectionTest
154
+ class AuthorizeRequestTests < FakeConnectionTests
156
155
  desc "running a request that halts in a callback"
157
156
  setup do
158
157
  @connection = FakeConnection.with_request('v1', 'authorized', {})
@@ -170,7 +169,7 @@ class RequestHandlingTest < Assert::Context
170
169
 
171
170
  end
172
171
 
173
- class WithCustomErrorHandlerTest < FakeConnectionTest
172
+ class WithCustomErrorHandlerTests < FakeConnectionTests
174
173
  desc "running a request that triggers our custom error handler"
175
174
  setup do
176
175
  @connection = FakeConnection.with_request('v1', 'custom_error', {})
@@ -188,7 +187,7 @@ class RequestHandlingTest < Assert::Context
188
187
 
189
188
  end
190
189
 
191
- class WithBadResponseHashTest < FakeConnectionTest
190
+ class WithBadResponseHashTests < FakeConnectionTests
192
191
  desc "running a request that builds an object that can't be encoded"
193
192
  setup do
194
193
  @connection = FakeConnection.with_request('v1', 'echo', { :message => 'cant encode' }, true)
@@ -213,7 +212,7 @@ class RequestHandlingTest < Assert::Context
213
212
  end
214
213
  end
215
214
 
216
- class WithAKeepAliveTest < FakeConnectionTest
215
+ class WithAKeepAliveTests < FakeConnectionTests
217
216
  desc "receiving a keep-alive connection"
218
217
  setup do
219
218
  @server = Sanford::Server.new(TestHost, {
@@ -238,12 +237,12 @@ class RequestHandlingTest < Assert::Context
238
237
 
239
238
  end
240
239
 
241
- class ForkedServerTest < RequestHandlingTest
240
+ class ForkedServerTests < RequestHandlingTests
242
241
  include Test::SpawnServerHelper
243
242
  end
244
243
 
245
244
  # Simple service test that echos back the params sent to it
246
- class EchoServerTest < ForkedServerTest
245
+ class EchoServerTests < ForkedServerTests
247
246
  desc "when hitting an echo service"
248
247
 
249
248
  should "return a successful response and echo the params sent to it" do
@@ -260,7 +259,7 @@ class RequestHandlingTest < Assert::Context
260
259
  end
261
260
 
262
261
  # Sending the server a completely wrong stream of bytes
263
- class BadMessageTest < ForkedServerTest
262
+ class BadMessageTests < ForkedServerTests
264
263
  desc "when sent a invalid request stream"
265
264
 
266
265
  should "return a bad request response with an error message" do
@@ -276,7 +275,7 @@ class RequestHandlingTest < Assert::Context
276
275
  end
277
276
 
278
277
  # Sending the server a protocol version that doesn't match it's version
279
- class WrongProtocolVersionTest < ForkedServerTest
278
+ class WrongProtocolVersionTests < ForkedServerTests
280
279
  desc "when sent a request with a wrong protocol version"
281
280
 
282
281
  should "return a bad request response with an error message" do
@@ -292,7 +291,7 @@ class RequestHandlingTest < Assert::Context
292
291
  end
293
292
 
294
293
  # Sending the server a body that it can't parse
295
- class BadBodyTest < ForkedServerTest
294
+ class BadBodyTests < ForkedServerTests
296
295
  desc "when sent a request with an invalid body"
297
296
 
298
297
  should "return a bad request response with an error message" do
@@ -306,7 +305,7 @@ class RequestHandlingTest < Assert::Context
306
305
  end
307
306
  end
308
307
 
309
- class HangingRequestTest < ForkedServerTest
308
+ class HangingRequestTests < ForkedServerTests
310
309
  desc "when a client connects but doesn't send anything for to long"
311
310
  setup do
312
311
  ENV['SANFORD_TIMEOUT'] = '0.1'
@@ -2,7 +2,7 @@ require 'assert'
2
2
 
3
3
  module Sanford::Config
4
4
 
5
- class BaseTest < Assert::Context
5
+ class BaseTests < Assert::Context
6
6
  desc "Sanford::Config"
7
7
  subject{ Sanford::Config }
8
8
 
@@ -2,7 +2,7 @@ require 'assert'
2
2
 
3
3
  class Sanford::ErrorHandler
4
4
 
5
- class BaseTest < Assert::Context
5
+ class BaseTests < Assert::Context
6
6
  desc "Sanford::ErrorHandler"
7
7
  setup do
8
8
  @exception = RuntimeError.new('test')
@@ -28,7 +28,7 @@ class Sanford::ErrorHandler
28
28
 
29
29
  end
30
30
 
31
- class ResponseFromProcTest < BaseTest
31
+ class ResponseFromProcTests < BaseTests
32
32
  desc "generating a respone from an error proc"
33
33
  setup do
34
34
  @host_defaults = { :ip => "localhost", :port => 8000 }
@@ -94,7 +94,7 @@ class Sanford::ErrorHandler
94
94
 
95
95
  end
96
96
 
97
- class ResponseFromExceptionTest < BaseTest
97
+ class ResponseFromExceptionTests < BaseTests
98
98
  desc "generating a respone from an exception"
99
99
 
100
100
  should "build a 400 response with a protocol BadMessageError" do
@@ -130,7 +130,7 @@ class Sanford::ErrorHandler
130
130
 
131
131
  end
132
132
 
133
- class MultipleErrorProcsTest < ResponseFromProcTest
133
+ class MultipleErrorProcsTests < ResponseFromProcTests
134
134
  desc "with multiple error procs"
135
135
  setup do
136
136
  @first_called, @second_called, @third_called = nil, nil, nil
@@ -2,7 +2,7 @@ require 'assert'
2
2
 
3
3
  class Sanford::Host::Configuration
4
4
 
5
- class BaseTest < Assert::Context
5
+ class BaseTests < Assert::Context
6
6
  desc "Sanford::Host::Configuration"
7
7
  setup do
8
8
  @configuration = Sanford::Host::Configuration.new(EmptyHost.instance)
@@ -2,7 +2,7 @@ require 'assert'
2
2
 
3
3
  class Sanford::HostData
4
4
 
5
- class BaseTest < Assert::Context
5
+ class BaseTests < Assert::Context
6
6
  desc "Sanford::HostData"
7
7
  setup do
8
8
  TestHost.init_has_been_called = false
@@ -2,7 +2,7 @@ require 'assert'
2
2
 
3
3
  module Sanford::Host
4
4
 
5
- class BaseTest < Assert::Context
5
+ class BaseTests < Assert::Context
6
6
  desc "Sanford::Host"
7
7
  setup do
8
8
  @configuration = MyHost.configuration.to_hash
@@ -31,7 +31,7 @@ module Sanford::Host
31
31
 
32
32
  end
33
33
 
34
- class ClassMethodsTest < Assert::Context
34
+ class ClassMethodsTests < Assert::Context
35
35
  desc "Sanford::Host class"
36
36
  subject{ MyHost }
37
37
 
@@ -2,7 +2,7 @@ require 'assert'
2
2
 
3
3
  class Sanford::Host::VersionGroup
4
4
 
5
- class BaseTest < Assert::Context
5
+ class BaseTests < Assert::Context
6
6
  desc "Sanford::Host::VersionGroup"
7
7
  setup do
8
8
  @version_group = Sanford::Host::VersionGroup.new('v1'){ }
@@ -2,7 +2,7 @@ require 'assert'
2
2
 
3
3
  class Sanford::Hosts
4
4
 
5
- class BaseTest < Assert::Context
5
+ class BaseTests < Assert::Context
6
6
  desc "Sanford::hosts"
7
7
  setup do
8
8
  @hosts = Sanford::Hosts.new
@@ -13,7 +13,7 @@ class Sanford::Hosts
13
13
 
14
14
  end
15
15
 
16
- class FindTest < BaseTest
16
+ class FindTests < BaseTests
17
17
  desc "find"
18
18
  setup do
19
19
  @hosts.add ::NotNamedHost
@@ -0,0 +1,60 @@
1
+ require 'assert'
2
+ require 'sanford/cli'
3
+
4
+ class Sanford::Manager::PIDFile
5
+
6
+ class BaseTests < Assert::Context
7
+ desc "Sanford::Manager::PIDFile"
8
+ setup do
9
+ @pid_file_path = File.join(ROOT, "tmp/my.pid")
10
+ @pid_file = Sanford::Manager::PIDFile.new(@pid_file_path)
11
+ end
12
+ teardown do
13
+ FileUtils.rm_rf(@pid_file_path)
14
+ end
15
+ subject{ @pid_file }
16
+
17
+ should have_instance_methods :pid, :to_s, :write, :remove
18
+
19
+ should "return it's path with #to_s" do
20
+ assert_equal @pid_file_path, subject.to_s
21
+ end
22
+
23
+ should "write the pid file with #write" do
24
+ subject.write
25
+
26
+ assert_file_exists @pid_file_path
27
+ assert_equal "#{Process.pid}\n", File.read(@pid_file_path)
28
+ end
29
+
30
+ should "return the value stored in the pid value with #pid" do
31
+ subject.write
32
+
33
+ assert_equal Process.pid, subject.pid
34
+ end
35
+
36
+ should "remove the file with #remove" do
37
+ subject.write
38
+ subject.remove
39
+
40
+ assert_not File.exists?(@pid_file_path)
41
+ end
42
+
43
+ should "complain nicely if it can't write the pid file" do
44
+ pid_file_path = 'does/not/exist.pid'
45
+ pid_file = Sanford::Manager::PIDFile.new(pid_file_path)
46
+
47
+ err = nil
48
+ begin
49
+ pid_file.write
50
+ rescue Exception => err
51
+ end
52
+
53
+ assert err
54
+ assert_kind_of RuntimeError, err
55
+ assert_includes File.dirname(pid_file_path), err.message
56
+ end
57
+
58
+ end
59
+
60
+ end
@@ -1,10 +1,9 @@
1
1
  require 'assert'
2
-
3
2
  require 'sanford/cli'
4
3
 
5
4
  module Sanford::Manager
6
5
 
7
- class BaseTest < Assert::Context
6
+ class BaseTests < Assert::Context
8
7
  desc "Sanford::Manager"
9
8
  subject{ Sanford::Manager }
10
9
 
@@ -19,7 +18,7 @@ module Sanford::Manager
19
18
 
20
19
  end
21
20
 
22
- class ServerHandlerTest < BaseTest
21
+ class ServerHandlerTests < BaseTests
23
22
  desc "ServerHandler"
24
23
  setup do
25
24
  @handler = Sanford::Manager::ServerHandler.new({ :host => 'TestHost' })
@@ -42,7 +41,7 @@ module Sanford::Manager
42
41
 
43
42
  end
44
43
 
45
- class SignalHandlertest < BaseTest
44
+ class SignalHandlertests < BaseTests
46
45
  desc "SignalHandler"
47
46
  setup do
48
47
  @handler = Sanford::Manager::SignalHandler.new({ :pid => -1 })
@@ -58,7 +57,7 @@ module Sanford::Manager
58
57
  end
59
58
  end
60
59
 
61
- class ConfigTest < BaseTest
60
+ class ConfigTests < BaseTests
62
61
  desc "Config"
63
62
  setup do
64
63
  @config = Sanford::Manager::Config.new({ :host => 'TestHost' })
@@ -115,7 +114,7 @@ module Sanford::Manager
115
114
 
116
115
  end
117
116
 
118
- class EnvVarsTest < ConfigTest
117
+ class EnvVarsTests < ConfigTests
119
118
  desc "with env vars set"
120
119
  setup do
121
120
  ENV['SANFORD_HOST'] = 'TestHost'
@@ -2,7 +2,7 @@ require 'assert'
2
2
 
3
3
  module Sanford::Runner
4
4
 
5
- class BaseTest < Assert::Context
5
+ class BaseTests < Assert::Context
6
6
  desc "Sanford::Runner"
7
7
  setup do
8
8
  request = Sanford::Protocol::Request.new('v1', 'test', {})
@@ -1,10 +1,9 @@
1
1
  require 'assert'
2
-
3
2
  require 'sanford/server'
4
3
 
5
4
  class Sanford::Server
6
5
 
7
- class BaseTest < Assert::Context
6
+ class BaseTests < Assert::Context
8
7
  desc "Sanford::Server"
9
8
  setup do
10
9
  @server = Sanford::Server.new(TestHost, { :keep_alive => true })
@@ -26,7 +25,7 @@ class Sanford::Server
26
25
 
27
26
  end
28
27
 
29
- class RunTest < BaseTest
28
+ class RunTests < BaseTests
30
29
  desc "run"
31
30
  setup do
32
31
  @server.listen(TestHost.ip, TestHost.port)
@@ -1,10 +1,9 @@
1
1
  require 'assert'
2
-
3
2
  require 'sanford/test_runner'
4
3
 
5
4
  module Sanford::ServiceHandler
6
5
 
7
- class BaseTest < Assert::Context
6
+ class BaseTests < Assert::Context
8
7
  include Sanford::TestRunner::Helpers
9
8
 
10
9
  desc "Sanford::ServiceHandler"
@@ -31,7 +30,7 @@ module Sanford::ServiceHandler
31
30
 
32
31
  end
33
32
 
34
- class RunHandlerTest < BaseTest
33
+ class RunHandlerTests < BaseTests
35
34
  desc "run_handler helper"
36
35
 
37
36
  should "allow easily running another handler" do
@@ -40,7 +39,7 @@ module Sanford::ServiceHandler
40
39
  end
41
40
  end
42
41
 
43
- class WithMethodFlagsTest < BaseTest
42
+ class WithMethodFlagsTests < BaseTests
44
43
  setup do
45
44
  @handler = test_runner(FlagServiceHandler).handler
46
45
  end
@@ -67,7 +66,7 @@ module Sanford::ServiceHandler
67
66
 
68
67
  end
69
68
 
70
- class HaltTest < BaseTest
69
+ class HaltTests < BaseTests
71
70
  desc "halt"
72
71
 
73
72
  should "return a response with the status code and the passed data" do
@@ -96,7 +95,7 @@ module Sanford::ServiceHandler
96
95
 
97
96
  end
98
97
 
99
- class HaltingTest < BaseTest
98
+ class HaltingTests < BaseTests
100
99
  desc "halting at different points"
101
100
 
102
101
  should "not call `init!, `after_init`, `run!` or run's callbacks when `before_init` halts" do
@@ -1,10 +1,9 @@
1
1
  require 'assert'
2
-
3
2
  require 'sanford-protocol/test/helpers'
4
3
 
5
4
  class Sanford::Worker
6
5
 
7
- class BaseTest < Assert::Context
6
+ class BaseTests < Assert::Context
8
7
  include Sanford::Protocol::Test::Helpers
9
8
 
10
9
  desc "Sanford::Worker"
data/tmp/.gitkeep ADDED
File without changes
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: 1
4
+ hash: 15
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 6
9
- - 3
10
- version: 0.6.3
9
+ - 4
10
+ version: 0.6.4
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: 2013-03-15 00:00:00 Z
19
+ date: 2013-03-26 00:00:00 Z
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
22
  prerelease: false
@@ -93,7 +93,7 @@ dependencies:
93
93
  requirement: *id005
94
94
  name: assert-mocha
95
95
  type: :development
96
- description: Simple hosts for Sanford services.
96
+ description: Sanford TCP protocol server for hosting services
97
97
  email:
98
98
  - collin.redding@me.com
99
99
  - kelly@kellyredding.com
@@ -135,20 +135,21 @@ files:
135
135
  - test/support/service_handlers.rb
136
136
  - test/support/services.rb
137
137
  - test/support/simple_client.rb
138
- - test/system/request_handling_test.rb
139
- - test/unit/config_test.rb
140
- - test/unit/error_handler_test.rb
141
- - test/unit/host_configuration_test.rb
142
- - test/unit/host_data_test.rb
143
- - test/unit/host_test.rb
144
- - test/unit/host_version_group_test.rb
145
- - test/unit/hosts_test.rb
146
- - test/unit/manager_pid_file_test.rb
147
- - test/unit/manager_test.rb
148
- - test/unit/runner_test.rb
149
- - test/unit/server_test.rb
150
- - test/unit/service_handler_test.rb
151
- - test/unit/worker_test.rb
138
+ - test/system/request_handling_tests.rb
139
+ - test/unit/config_tests.rb
140
+ - test/unit/error_handler_tests.rb
141
+ - test/unit/host_configuration_tests.rb
142
+ - test/unit/host_data_tests.rb
143
+ - test/unit/host_tests.rb
144
+ - test/unit/host_version_group_tests.rb
145
+ - test/unit/hosts_tests.rb
146
+ - test/unit/manager_pid_file_tests.rb
147
+ - test/unit/manager_tests.rb
148
+ - test/unit/runner_tests.rb
149
+ - test/unit/server_tests.rb
150
+ - test/unit/service_handler_tests.rb
151
+ - test/unit/worker_tests.rb
152
+ - tmp/.gitkeep
152
153
  homepage: https://github.com/redding/sanford
153
154
  licenses: []
154
155
 
@@ -181,7 +182,7 @@ rubyforge_project:
181
182
  rubygems_version: 1.8.15
182
183
  signing_key:
183
184
  specification_version: 3
184
- summary: Simple hosts for Sanford services.
185
+ summary: Sanford TCP protocol server for hosting services
185
186
  test_files:
186
187
  - test/helper.rb
187
188
  - test/support/fake_connection.rb
@@ -189,17 +190,17 @@ test_files:
189
190
  - test/support/service_handlers.rb
190
191
  - test/support/services.rb
191
192
  - test/support/simple_client.rb
192
- - test/system/request_handling_test.rb
193
- - test/unit/config_test.rb
194
- - test/unit/error_handler_test.rb
195
- - test/unit/host_configuration_test.rb
196
- - test/unit/host_data_test.rb
197
- - test/unit/host_test.rb
198
- - test/unit/host_version_group_test.rb
199
- - test/unit/hosts_test.rb
200
- - test/unit/manager_pid_file_test.rb
201
- - test/unit/manager_test.rb
202
- - test/unit/runner_test.rb
203
- - test/unit/server_test.rb
204
- - test/unit/service_handler_test.rb
205
- - test/unit/worker_test.rb
193
+ - test/system/request_handling_tests.rb
194
+ - test/unit/config_tests.rb
195
+ - test/unit/error_handler_tests.rb
196
+ - test/unit/host_configuration_tests.rb
197
+ - test/unit/host_data_tests.rb
198
+ - test/unit/host_tests.rb
199
+ - test/unit/host_version_group_tests.rb
200
+ - test/unit/hosts_tests.rb
201
+ - test/unit/manager_pid_file_tests.rb
202
+ - test/unit/manager_tests.rb
203
+ - test/unit/runner_tests.rb
204
+ - test/unit/server_tests.rb
205
+ - test/unit/service_handler_tests.rb
206
+ - test/unit/worker_tests.rb
@@ -1,45 +0,0 @@
1
- require 'assert'
2
-
3
- require 'sanford/cli'
4
-
5
- class Sanford::Manager::PIDFile
6
-
7
- class BaseTest < Assert::Context
8
- desc "Sanford::Manager::PIDFile"
9
- setup do
10
- @pid_file = Sanford::Manager::PIDFile.new("tmp/my.pid")
11
- end
12
- teardown do
13
- FileUtils.rm_rf("tmp/my.pid")
14
- end
15
- subject{ @pid_file }
16
-
17
- should have_instance_methods :pid, :to_s, :write, :remove
18
-
19
- should "return it's path with #to_s" do
20
- assert_equal "tmp/my.pid", subject.to_s
21
- end
22
-
23
- should "write the pid file with #write" do
24
- subject.write
25
-
26
- assert File.exists?("tmp/my.pid")
27
- assert_equal "#{Process.pid}\n", File.read("tmp/my.pid")
28
- end
29
-
30
- should "return the value stored in the pid value with #pid" do
31
- subject.write
32
-
33
- assert_equal Process.pid, subject.pid
34
- end
35
-
36
- should "remove the file with #remove" do
37
- subject.write
38
- subject.remove
39
-
40
- assert_not File.exists?("tmp/my.pid")
41
- end
42
-
43
- end
44
-
45
- end