servolux 0.9.6 → 0.9.7
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +18 -0
- data/.travis.yml +11 -0
- data/History.txt +7 -0
- data/README.rdoc +4 -2
- data/Rakefile +0 -1
- data/lib/servolux/child.rb +4 -5
- data/lib/servolux/daemon.rb +33 -17
- data/lib/servolux/piper.rb +1 -1
- data/lib/servolux/prefork.rb +2 -2
- data/lib/servolux/server.rb +5 -5
- data/lib/servolux/threaded.rb +12 -5
- data/spec/child_spec.rb +4 -5
- data/spec/daemon_spec.rb +1 -1
- data/spec/piper_spec.rb +11 -12
- data/spec/prefork_spec.rb +8 -7
- data/spec/server_spec.rb +10 -11
- data/spec/servolux_spec.rb +4 -5
- data/spec/spec_helper.rb +6 -16
- data/spec/threaded_spec.rb +56 -20
- data/version.txt +1 -1
- metadata +63 -98
data/.gitignore
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# The list of files that should be ignored by Mr Bones.
|
2
|
+
# Lines that start with '#' are comments.
|
3
|
+
#
|
4
|
+
# A .gitignore file can be used instead by setting it as the ignore
|
5
|
+
# file in your Rakefile:
|
6
|
+
#
|
7
|
+
# PROJ.ignore_file = '.gitignore'
|
8
|
+
#
|
9
|
+
# For a project with a C extension, the following would be a good set of
|
10
|
+
# exclude patterns (uncomment them if you want to use them):
|
11
|
+
# *.[oa]
|
12
|
+
*~
|
13
|
+
*.sw[op]
|
14
|
+
announcement.txt
|
15
|
+
coverage
|
16
|
+
doc
|
17
|
+
pkg
|
18
|
+
.yardoc
|
data/.travis.yml
ADDED
data/History.txt
CHANGED
data/README.rdoc
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
= Serv-O-Lux
|
2
|
-
|
3
|
-
|
2
|
+
by Tim Pease {<img src="https://secure.travis-ci.org/TwP/servolux.png">}[http://travis-ci.org/TwP/servolux]
|
3
|
+
|
4
|
+
* {Homepage}[http://rubygems.org/gems/servolux]
|
5
|
+
* {Github Project}[http://github.com/TwP/servolux]
|
4
6
|
|
5
7
|
=== DESCRIPTION
|
6
8
|
|
data/Rakefile
CHANGED
data/lib/servolux/child.rb
CHANGED
@@ -67,10 +67,10 @@ class Servolux::Child
|
|
67
67
|
# signal before trying the next one in the list.
|
68
68
|
#
|
69
69
|
def initialize( opts = {} )
|
70
|
-
@command = opts
|
71
|
-
@timeout = opts
|
72
|
-
@signals = opts
|
73
|
-
@suspend = opts
|
70
|
+
@command = opts.fetch(:command, nil)
|
71
|
+
@timeout = opts.fetch(:timeout, nil)
|
72
|
+
@signals = opts.fetch(:signals, %w[TERM QUIT KILL])
|
73
|
+
@suspend = opts.fetch(:suspend, 4)
|
74
74
|
@io = @pid = @status = @thread = @timed_out = nil
|
75
75
|
yield self if block_given?
|
76
76
|
end
|
@@ -218,4 +218,3 @@ class Servolux::Child
|
|
218
218
|
|
219
219
|
end
|
220
220
|
|
221
|
-
# EOF
|
data/lib/servolux/daemon.rb
CHANGED
@@ -39,7 +39,7 @@ require 'ostruct'
|
|
39
39
|
#
|
40
40
|
# Again, the Daemon instance will wait till the daemon process shuts down.
|
41
41
|
# This is determined by attempting to signal the daemon process PID and then
|
42
|
-
# returning when this signal fails -- i.e. then the
|
42
|
+
# returning when this signal fails -- i.e. then the daemon process has died.
|
43
43
|
#
|
44
44
|
# == Examples
|
45
45
|
#
|
@@ -75,7 +75,7 @@ class Servolux::Daemon
|
|
75
75
|
Timeout = Class.new(Error)
|
76
76
|
StartupError = Class.new(Error)
|
77
77
|
|
78
|
-
|
78
|
+
attr_accessor :name
|
79
79
|
attr_accessor :logger
|
80
80
|
attr_accessor :pid_file
|
81
81
|
attr_reader :startup_command
|
@@ -85,8 +85,10 @@ class Servolux::Daemon
|
|
85
85
|
attr_accessor :noclose
|
86
86
|
attr_reader :log_file
|
87
87
|
attr_reader :look_for
|
88
|
+
attr_accessor :after_fork
|
89
|
+
attr_accessor :before_exec
|
88
90
|
|
89
|
-
# Create a new Daemon that will manage the +startup_command+ as a
|
91
|
+
# Create a new Daemon that will manage the +startup_command+ as a daemon
|
90
92
|
# process.
|
91
93
|
#
|
92
94
|
# @option opts [String] :name
|
@@ -119,7 +121,7 @@ class Servolux::Daemon
|
|
119
121
|
#
|
120
122
|
# @option opts [Boolen] :noclose (false)
|
121
123
|
# When set to true this flag keeps the standard input/output streams from
|
122
|
-
# being reopend to /dev/null when the
|
124
|
+
# being reopend to /dev/null when the daemon process is created. Reopening
|
123
125
|
# the standard input/output streams frees the file descriptors which are
|
124
126
|
# still being used by the parent process. This prevents zombie processes.
|
125
127
|
#
|
@@ -138,23 +140,32 @@ class Servolux::Daemon
|
|
138
140
|
# is a useful check for determining if the daemon process is fully
|
139
141
|
# started.
|
140
142
|
#
|
143
|
+
# @option opts [Proc, lambda] :after_fork (nil)
|
144
|
+
# This proc will be called in the child process immediately after forking.
|
145
|
+
#
|
146
|
+
# @option opts [Proc, lambda] :before_exec (nil)
|
147
|
+
# This proc will be called in the child process immediately before calling
|
148
|
+
# `exec` to execute the desired process. This proc will be called after
|
149
|
+
# the :after_fork proc if present.
|
150
|
+
#
|
141
151
|
# @yield [self] Block used to configure the daemon instance
|
142
152
|
#
|
143
153
|
def initialize( opts = {} )
|
144
|
-
self.server = opts[:server] || opts[:startup_command]
|
145
|
-
|
146
|
-
@name = opts[:name] if opts.key?(:name)
|
147
|
-
@logger = opts[:logger] if opts.key?(:logger)
|
148
|
-
@pid_file = opts[:pid_file] if opts.key?(:pid_file)
|
149
|
-
@timeout = opts[:timeout] || 30
|
150
|
-
@nochdir = opts[:nochdir] || false
|
151
|
-
@noclose = opts[:noclose] || false
|
152
|
-
@shutdown_command = opts[:shutdown_command]
|
153
|
-
|
154
154
|
@piper = nil
|
155
155
|
@logfile_reader = nil
|
156
|
-
|
157
|
-
self.
|
156
|
+
|
157
|
+
self.name = opts.fetch(:name, nil)
|
158
|
+
self.logger = opts.fetch(:logger, nil)
|
159
|
+
self.pid_file = opts.fetch(:pid_file, nil)
|
160
|
+
self.startup_command = opts.fetch(:server, nil) || opts.fetch(:startup_command, nil)
|
161
|
+
self.shutdown_command = opts.fetch(:shutdown_command, nil)
|
162
|
+
self.timeout = opts.fetch(:timeout, 30)
|
163
|
+
self.nochdir = opts.fetch(:nochdir, false)
|
164
|
+
self.noclose = opts.fetch(:noclose, false)
|
165
|
+
self.log_file = opts.fetch(:log_file, nil)
|
166
|
+
self.look_for = opts.fetch(:look_for, nil)
|
167
|
+
self.after_fork = opts.fetch(:after_fork, nil)
|
168
|
+
self.before_exec = opts.fetch(:before_exec, nil)
|
158
169
|
|
159
170
|
yield self if block_given?
|
160
171
|
|
@@ -324,9 +335,11 @@ class Servolux::Daemon
|
|
324
335
|
end
|
325
336
|
|
326
337
|
|
327
|
-
|
338
|
+
private
|
328
339
|
|
329
340
|
def run_startup_command
|
341
|
+
after_fork.call if after_fork.respond_to? :call
|
342
|
+
|
330
343
|
case startup_command
|
331
344
|
when String; exec(startup_command)
|
332
345
|
when Array; exec(*startup_command)
|
@@ -347,12 +360,15 @@ class Servolux::Daemon
|
|
347
360
|
|
348
361
|
def exec( *args )
|
349
362
|
logger.debug "Calling: exec(*#{args.inspect})"
|
363
|
+
|
350
364
|
skip = [STDIN, STDOUT, STDERR]
|
351
365
|
skip << @piper.socket if @piper
|
352
366
|
ObjectSpace.each_object(IO) { |obj|
|
353
367
|
next if skip.include? obj
|
354
368
|
obj.close rescue nil
|
355
369
|
}
|
370
|
+
|
371
|
+
before_exec.call if before_exec.respond_to? :call
|
356
372
|
Kernel.exec(*args)
|
357
373
|
end
|
358
374
|
|
data/lib/servolux/piper.rb
CHANGED
@@ -124,7 +124,7 @@ class Servolux::Piper
|
|
124
124
|
raise ArgumentError, "Unsupported mode #{mode.inspect}"
|
125
125
|
end
|
126
126
|
|
127
|
-
@timeout = opts.
|
127
|
+
@timeout = opts.fetch(:timeout, nil)
|
128
128
|
socket_pair = Socket.pair(Socket::AF_UNIX, Socket::SOCK_STREAM, 0)
|
129
129
|
@child_pid = Kernel.fork
|
130
130
|
|
data/lib/servolux/prefork.rb
CHANGED
@@ -160,8 +160,8 @@ class Servolux::Prefork
|
|
160
160
|
# left to the user to implement this functionality.
|
161
161
|
#
|
162
162
|
def initialize( opts = {}, &block )
|
163
|
-
@timeout = opts
|
164
|
-
@module = opts
|
163
|
+
@timeout = opts.fetch(:timeout, nil)
|
164
|
+
@module = opts.fetch(:module, nil)
|
165
165
|
@module = Module.new { define_method :execute, &block } if block
|
166
166
|
@workers = []
|
167
167
|
@harvest = Queue.new
|
data/lib/servolux/server.rb
CHANGED
@@ -45,7 +45,7 @@ require 'thread'
|
|
45
45
|
# just after the run loop thread has died; the +after_stopping+ method is
|
46
46
|
# guarnteed to NOT be called till after the run loop thread is well and
|
47
47
|
# truly dead.
|
48
|
-
#
|
48
|
+
#
|
49
49
|
# == Usage
|
50
50
|
# For simple, quick and dirty servers just pass a block to the Server
|
51
51
|
# initializer. This block will be used as the run method.
|
@@ -153,10 +153,10 @@ class Servolux::Server
|
|
153
153
|
@mutex = Mutex.new
|
154
154
|
@shutdown = nil
|
155
155
|
|
156
|
-
self.logger = opts
|
157
|
-
self.pid_file = opts
|
158
|
-
self.pid_file_mode = opts
|
159
|
-
self.interval = opts
|
156
|
+
self.logger = opts.fetch(:logger, nil)
|
157
|
+
self.pid_file = opts.fetch(:pid_file, nil)
|
158
|
+
self.pid_file_mode = opts.fetch(:pid_file_mode, DEFAULT_PID_FILE_MODE)
|
159
|
+
self.interval = opts.fetch(:interval, 0)
|
160
160
|
|
161
161
|
if block
|
162
162
|
eg = class << self; self; end
|
data/lib/servolux/threaded.rb
CHANGED
@@ -213,16 +213,23 @@ module Servolux::Threaded
|
|
213
213
|
|
214
214
|
def stop
|
215
215
|
self.running = false
|
216
|
-
thread.wakeup
|
216
|
+
thread.wakeup if thread.alive?
|
217
217
|
end # @private
|
218
218
|
|
219
219
|
def run( threaded )
|
220
|
-
loop
|
220
|
+
loop do
|
221
221
|
begin
|
222
222
|
break unless running?
|
223
223
|
threaded.run
|
224
|
-
|
225
|
-
|
224
|
+
|
225
|
+
if maximum_iterations
|
226
|
+
self.iterations += 1
|
227
|
+
if finished_iterations?
|
228
|
+
self.running = false
|
229
|
+
break
|
230
|
+
end
|
231
|
+
end
|
232
|
+
|
226
233
|
sleep interval if running?
|
227
234
|
rescue SystemExit; raise
|
228
235
|
rescue Exception => err
|
@@ -233,7 +240,7 @@ module Servolux::Threaded
|
|
233
240
|
raise err
|
234
241
|
end
|
235
242
|
end
|
236
|
-
|
243
|
+
end
|
237
244
|
ensure
|
238
245
|
if threaded.respond_to?(:after_stopping) and !self.running
|
239
246
|
threaded.after_stopping
|
data/spec/child_spec.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
|
2
|
-
require File.
|
2
|
+
require File.expand_path('../spec_helper', __FILE__)
|
3
3
|
|
4
4
|
describe Servolux::Child do
|
5
5
|
|
@@ -14,8 +14,8 @@ describe Servolux::Child do
|
|
14
14
|
it 'has some sensible defaults' do
|
15
15
|
@child.command.should be_nil
|
16
16
|
@child.timeout.should be_nil
|
17
|
-
@child.signals.should == %w[TERM QUIT KILL]
|
18
|
-
@child.suspend.should == 4
|
17
|
+
@child.signals.should be == %w[TERM QUIT KILL]
|
18
|
+
@child.suspend.should be == 4
|
19
19
|
@child.pid.should be_nil
|
20
20
|
@child.io.should be_nil
|
21
21
|
end
|
@@ -26,7 +26,7 @@ describe Servolux::Child do
|
|
26
26
|
|
27
27
|
@child.pid.should_not be_nil
|
28
28
|
@child.wait
|
29
|
-
@child.io.read.strip.should == Dir.pwd
|
29
|
+
@child.io.read.strip.should be == Dir.pwd
|
30
30
|
@child.success?.should be_true
|
31
31
|
end
|
32
32
|
|
@@ -48,4 +48,3 @@ describe Servolux::Child do
|
|
48
48
|
|
49
49
|
end
|
50
50
|
|
51
|
-
# EOF
|
data/spec/daemon_spec.rb
CHANGED
data/spec/piper_spec.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
|
2
|
-
require File.
|
2
|
+
require File.expand_path('../spec_helper', __FILE__)
|
3
3
|
|
4
4
|
if Servolux.fork?
|
5
5
|
|
@@ -45,20 +45,20 @@ describe Servolux::Piper do
|
|
45
45
|
|
46
46
|
@piper.parent {
|
47
47
|
@piper.puts 'foo bar baz'
|
48
|
-
@piper.gets.should == 'foo bar baz'
|
48
|
+
@piper.gets.should be == 'foo bar baz'
|
49
49
|
|
50
50
|
@piper.puts %w[one two three]
|
51
|
-
@piper.gets.should == %w[one two three]
|
51
|
+
@piper.gets.should be == %w[one two three]
|
52
52
|
|
53
|
-
@piper.puts('Returns # of bytes written').should > 0
|
54
|
-
@piper.gets.should == 'Returns # of bytes written'
|
53
|
+
@piper.puts('Returns # of bytes written').should be > 0
|
54
|
+
@piper.gets.should be == 'Returns # of bytes written'
|
55
55
|
|
56
56
|
@piper.puts 1
|
57
57
|
@piper.puts 2
|
58
58
|
@piper.puts 3
|
59
|
-
@piper.gets.should == 1
|
60
|
-
@piper.gets.should == 2
|
61
|
-
@piper.gets.should == 3
|
59
|
+
@piper.gets.should be == 1
|
60
|
+
@piper.gets.should be == 2
|
61
|
+
@piper.gets.should be == 3
|
62
62
|
|
63
63
|
@piper.timeout = 0.1
|
64
64
|
@piper.readable?.should be_false
|
@@ -82,13 +82,13 @@ describe Servolux::Piper do
|
|
82
82
|
}
|
83
83
|
|
84
84
|
@piper.parent {
|
85
|
-
@piper.gets.should == :ready
|
85
|
+
@piper.gets.should be == :ready
|
86
86
|
|
87
87
|
@piper.signal 'USR2'
|
88
|
-
@piper.gets.should == "'USR2' was received"
|
88
|
+
@piper.gets.should be == "'USR2' was received"
|
89
89
|
|
90
90
|
@piper.signal 'INT'
|
91
|
-
@piper.gets.should == "'INT' was received"
|
91
|
+
@piper.gets.should be == "'INT' was received"
|
92
92
|
}
|
93
93
|
end
|
94
94
|
|
@@ -109,4 +109,3 @@ describe Servolux::Piper do
|
|
109
109
|
end
|
110
110
|
end # if Servolux.fork?
|
111
111
|
|
112
|
-
# EOF
|
data/spec/prefork_spec.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
|
2
|
-
require File.
|
2
|
+
require File.expand_path('../spec_helper', __FILE__)
|
3
3
|
require 'tempfile'
|
4
4
|
require 'fileutils'
|
5
5
|
require 'enumerator'
|
@@ -70,8 +70,8 @@ describe Servolux::Prefork do
|
|
70
70
|
sleep 0.1 until worker_count >= 1
|
71
71
|
|
72
72
|
ary = Dir.glob(@glob)
|
73
|
-
ary.length.should == 1
|
74
|
-
File.basename(ary.first).to_i.should == pids.first
|
73
|
+
ary.length.should be == 1
|
74
|
+
File.basename(ary.first).to_i.should be == pids.first
|
75
75
|
end
|
76
76
|
|
77
77
|
it "starts up a number of workers" do
|
@@ -82,10 +82,10 @@ describe Servolux::Prefork do
|
|
82
82
|
sleep 0.250 until worker_count >= 8
|
83
83
|
|
84
84
|
ary = Dir.glob(@glob)
|
85
|
-
ary.length.should == 8
|
85
|
+
ary.length.should be == 8
|
86
86
|
|
87
87
|
ary.map! { |fn| File.basename(fn).to_i }.sort!
|
88
|
-
ary.should == pids.sort
|
88
|
+
ary.should be == pids.sort
|
89
89
|
end
|
90
90
|
|
91
91
|
it "stops workers gracefullly" do
|
@@ -96,13 +96,14 @@ describe Servolux::Prefork do
|
|
96
96
|
sleep 0.250 until worker_count >= 3
|
97
97
|
|
98
98
|
ary = Dir.glob(@glob)
|
99
|
-
ary.length.should == 3
|
99
|
+
ary.length.should be == 3
|
100
100
|
|
101
101
|
@prefork.stop
|
102
102
|
sleep 0.250 until Dir.glob(@glob).length == 0
|
103
|
+
workers.each { |w| w.wait rescue nil }
|
103
104
|
|
104
105
|
rv = workers.all? { |w| !w.alive? }
|
105
|
-
rv.should == true
|
106
|
+
rv.should be == true
|
106
107
|
end
|
107
108
|
|
108
109
|
it "restarts a worker via SIGHUP" do
|
data/spec/server_spec.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
|
2
|
-
require File.
|
2
|
+
require File.expand_path('../spec_helper', __FILE__)
|
3
3
|
|
4
4
|
describe Servolux::Server do
|
5
5
|
base = Class.new(Servolux::Server) do
|
@@ -36,9 +36,9 @@ describe Servolux::Server do
|
|
36
36
|
Thread.pass until @server.running? and t.status == 'sleep'
|
37
37
|
test(?e, @server.pid_file).should be_true
|
38
38
|
|
39
|
-
@log_output.readline.chomp.should == %q(DEBUG Servolux : Server "Test Server" creating pid file "test_server.pid")
|
40
|
-
@log_output.readline.chomp.should == %q(DEBUG Servolux : Starting)
|
41
|
-
(File.stat(@server.pid_file).mode & 0777).should == 0640
|
39
|
+
@log_output.readline.chomp.should be == %q(DEBUG Servolux : Server "Test Server" creating pid file "test_server.pid")
|
40
|
+
@log_output.readline.chomp.should be == %q(DEBUG Servolux : Starting)
|
41
|
+
(File.stat(@server.pid_file).mode & 0777).should be == 0640
|
42
42
|
|
43
43
|
@server.shutdown
|
44
44
|
Thread.pass until t.status == false
|
@@ -51,9 +51,9 @@ describe Servolux::Server do
|
|
51
51
|
Thread.pass until @server.running? and t.status == 'sleep'
|
52
52
|
test(?e, @server.pid_file).should be_true
|
53
53
|
|
54
|
-
@log_output.readline.chomp.should == %q(DEBUG Servolux : Server "Test Server" creating pid file "test_server.pid")
|
55
|
-
@log_output.readline.chomp.should == %q(DEBUG Servolux : Starting)
|
56
|
-
(File.stat(@server.pid_file).mode & 0777).should == 0400
|
54
|
+
@log_output.readline.chomp.should be == %q(DEBUG Servolux : Server "Test Server" creating pid file "test_server.pid")
|
55
|
+
@log_output.readline.chomp.should be == %q(DEBUG Servolux : Starting)
|
56
|
+
(File.stat(@server.pid_file).mode & 0777).should be == 0400
|
57
57
|
|
58
58
|
@server.shutdown
|
59
59
|
Thread.pass until t.status == false
|
@@ -82,13 +82,13 @@ describe Servolux::Server do
|
|
82
82
|
@log_output.readline
|
83
83
|
|
84
84
|
Process.kill('USR1', $$)
|
85
|
-
@log_output.readline.strip.should == 'INFO Servolux : usr1 was called'
|
85
|
+
@log_output.readline.strip.should be == 'INFO Servolux : usr1 was called'
|
86
86
|
|
87
87
|
Process.kill('HUP', $$)
|
88
|
-
@log_output.readline.strip.should == 'INFO Servolux : hup was called'
|
88
|
+
@log_output.readline.strip.should be == 'INFO Servolux : hup was called'
|
89
89
|
|
90
90
|
Process.kill('USR2', $$)
|
91
|
-
@log_output.readline.strip.should == 'INFO Servolux : usr2 was called'
|
91
|
+
@log_output.readline.strip.should be == 'INFO Servolux : usr2 was called'
|
92
92
|
|
93
93
|
Process.kill('TERM', $$)
|
94
94
|
Thread.pass until t.status == false
|
@@ -96,4 +96,3 @@ describe Servolux::Server do
|
|
96
96
|
end
|
97
97
|
end
|
98
98
|
|
99
|
-
# EOF
|
data/spec/servolux_spec.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
|
2
|
-
require File.
|
2
|
+
require File.expand_path('../spec_helper', __FILE__)
|
3
3
|
|
4
4
|
describe Servolux do
|
5
5
|
|
@@ -9,12 +9,11 @@ describe Servolux do
|
|
9
9
|
|
10
10
|
it "finds things releative to 'lib'" do
|
11
11
|
Servolux.libpath(%w[servolux threaded]).should == File.join(@root_dir, %w[lib servolux threaded])
|
12
|
-
end
|
13
|
-
|
12
|
+
end
|
13
|
+
|
14
14
|
it "finds things releative to 'root'" do
|
15
15
|
Servolux.path('Rakefile').should == File.join(@root_dir, 'Rakefile')
|
16
|
-
end
|
16
|
+
end
|
17
17
|
|
18
18
|
end
|
19
19
|
|
20
|
-
# EOF
|
data/spec/spec_helper.rb
CHANGED
@@ -4,27 +4,17 @@ SERVOLUX_SPEC_HELPER = true
|
|
4
4
|
|
5
5
|
require 'rubygems'
|
6
6
|
require 'logging'
|
7
|
-
require '
|
8
|
-
require '
|
7
|
+
require 'rspec'
|
8
|
+
require 'rspec/logging_helper'
|
9
9
|
|
10
|
-
require File.expand_path(
|
11
|
-
File.join(File.dirname(__FILE__), %w[.. lib servolux]))
|
10
|
+
require File.expand_path('../../lib/servolux', __FILE__)
|
12
11
|
|
13
12
|
include Logging.globally
|
14
13
|
|
15
|
-
|
16
|
-
include
|
14
|
+
RSpec.configure do |config|
|
15
|
+
include RSpec::LoggingHelper
|
17
16
|
config.capture_log_messages
|
18
|
-
|
19
|
-
# == Mock Framework
|
20
|
-
#
|
21
|
-
# RSpec uses it's own mocking framework by default. If you prefer to
|
22
|
-
# use mocha, flexmock or RR, uncomment the appropriate line:
|
23
|
-
#
|
24
|
-
# config.mock_with :mocha
|
25
|
-
# config.mock_with :flexmock
|
26
|
-
# config.mock_with :rr
|
27
17
|
end
|
28
18
|
|
29
19
|
end # unless defined?
|
30
|
-
|
20
|
+
|
data/spec/threaded_spec.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
|
2
|
-
require File.
|
2
|
+
require File.expand_path('../spec_helper', __FILE__)
|
3
3
|
|
4
4
|
describe Servolux::Threaded do
|
5
5
|
|
@@ -78,11 +78,11 @@ describe Servolux::Threaded do
|
|
78
78
|
obj.ary = []
|
79
79
|
|
80
80
|
obj.start
|
81
|
-
obj.ary.should == [1,2]
|
81
|
+
obj.ary.should be == [1,2]
|
82
82
|
obj.pass
|
83
83
|
|
84
84
|
obj.stop.join(2)
|
85
|
-
obj.ary.should == [1,2,3,4]
|
85
|
+
obj.ary.should be == [1,2,3,4]
|
86
86
|
end
|
87
87
|
|
88
88
|
it "dies when an exception is thrown" do
|
@@ -97,7 +97,7 @@ describe Servolux::Threaded do
|
|
97
97
|
|
98
98
|
obj.running?.should be_false
|
99
99
|
@log_output.readline
|
100
|
-
@log_output.readline.chomp.should == "FATAL Object : <RuntimeError> ni"
|
100
|
+
@log_output.readline.chomp.should be == "FATAL Object : <RuntimeError> ni"
|
101
101
|
|
102
102
|
lambda { obj.join }.should raise_error(RuntimeError, 'ni')
|
103
103
|
end
|
@@ -124,7 +124,7 @@ describe Servolux::Threaded do
|
|
124
124
|
|
125
125
|
obj.running?.should be_true
|
126
126
|
@log_output.readline
|
127
|
-
@log_output.readline.chomp.should == "ERROR Object : <RuntimeError> ni"
|
127
|
+
@log_output.readline.chomp.should be == "ERROR Object : <RuntimeError> ni"
|
128
128
|
|
129
129
|
obj.stop.join(2)
|
130
130
|
obj.running?.should be_false
|
@@ -136,27 +136,63 @@ describe Servolux::Threaded do
|
|
136
136
|
obj.pass nil
|
137
137
|
|
138
138
|
@log_output.readline
|
139
|
-
@log_output.readline.chomp.should == "FATAL Object : <NotImplementedError> The run method must be defined by the threaded object."
|
139
|
+
@log_output.readline.chomp.should be == "FATAL Object : <NotImplementedError> The run method must be defined by the threaded object."
|
140
140
|
|
141
141
|
lambda { obj.join }.should raise_error(NotImplementedError, 'The run method must be defined by the threaded object.')
|
142
142
|
end
|
143
143
|
|
144
|
-
|
145
|
-
|
146
|
-
|
144
|
+
# --------------------------------------------------------------------------
|
145
|
+
describe 'when setting maximum iterations' do
|
146
|
+
|
147
|
+
it "stops after a limited number of iterations" do
|
148
|
+
klass = Class.new( base ) do
|
149
|
+
def run() ; end
|
150
|
+
end
|
151
|
+
|
152
|
+
obj = klass.new
|
153
|
+
obj.maximum_iterations = 5
|
154
|
+
obj.iterations.should be == 0
|
155
|
+
|
156
|
+
obj.start
|
157
|
+
obj.wait
|
158
|
+
obj.iterations.should be == 5
|
159
|
+
end
|
160
|
+
|
161
|
+
it "runs the 'after_stopping' method" do
|
162
|
+
klass = Class.new( base ) do
|
163
|
+
attr_accessor :ary
|
164
|
+
def run() ; end
|
165
|
+
def after_stopping() ary << 4; end
|
166
|
+
end
|
167
|
+
|
168
|
+
obj = klass.new
|
169
|
+
obj.maximum_iterations = 5
|
170
|
+
obj.ary = []
|
171
|
+
|
172
|
+
obj.start
|
173
|
+
obj.wait
|
174
|
+
obj.ary.should be == [4]
|
175
|
+
end
|
176
|
+
|
177
|
+
it "should not increment iterations if maximum iterations has not been set" do
|
178
|
+
klass = Class.new( base ) do
|
179
|
+
def run() ; end
|
180
|
+
end
|
181
|
+
|
182
|
+
obj = klass.new
|
183
|
+
obj.iterations.should be == 0
|
184
|
+
|
185
|
+
obj.start
|
186
|
+
sleep 0.1
|
187
|
+
obj.stop.join(2)
|
188
|
+
obj.iterations.should be == 0
|
189
|
+
end
|
190
|
+
|
191
|
+
it "complains loudly if you attempt to set a maximum number of iterations < 1" do
|
192
|
+
obj = base.new
|
193
|
+
lambda { obj.maximum_iterations = -1 }.should raise_error( ArgumentError, "maximum iterations must be >= 1" )
|
147
194
|
end
|
148
|
-
obj = klass.new
|
149
|
-
obj.maximum_iterations = 5
|
150
|
-
obj.iterations.should == 0
|
151
|
-
obj.start
|
152
|
-
obj.wait
|
153
|
-
obj.iterations.should == 5
|
154
|
-
end
|
155
195
|
|
156
|
-
it "complains loudly if you attempt to set a maximum number of iterations < 1" do
|
157
|
-
obj = base.new
|
158
|
-
lambda { obj.maximum_iterations = -1 }.should raise_error( ArgumentError, "maximum iterations must be >= 1" )
|
159
196
|
end
|
160
197
|
end
|
161
198
|
|
162
|
-
# EOF
|
data/version.txt
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.9.
|
1
|
+
0.9.7
|
metadata
CHANGED
@@ -1,102 +1,77 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: servolux
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 9
|
9
|
-
- 6
|
10
|
-
version: 0.9.6
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.9.7
|
5
|
+
prerelease:
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Tim Pease
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
dependencies:
|
21
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2012-01-19 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
22
15
|
name: bones-rspec
|
23
|
-
|
24
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
16
|
+
requirement: &2154204220 !ruby/object:Gem::Requirement
|
25
17
|
none: false
|
26
|
-
requirements:
|
27
|
-
- -
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
|
30
|
-
segments:
|
31
|
-
- 1
|
32
|
-
- 1
|
33
|
-
- 0
|
34
|
-
version: 1.1.0
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 2.0.1
|
35
22
|
type: :development
|
36
|
-
version_requirements: *id001
|
37
|
-
- !ruby/object:Gem::Dependency
|
38
|
-
name: bones-git
|
39
23
|
prerelease: false
|
40
|
-
|
24
|
+
version_requirements: *2154204220
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: bones-git
|
27
|
+
requirement: &2154203600 !ruby/object:Gem::Requirement
|
41
28
|
none: false
|
42
|
-
requirements:
|
43
|
-
- -
|
44
|
-
- !ruby/object:Gem::Version
|
45
|
-
|
46
|
-
segments:
|
47
|
-
- 1
|
48
|
-
- 2
|
49
|
-
- 2
|
50
|
-
version: 1.2.2
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 1.2.4
|
51
33
|
type: :development
|
52
|
-
version_requirements: *id002
|
53
|
-
- !ruby/object:Gem::Dependency
|
54
|
-
name: logging
|
55
34
|
prerelease: false
|
56
|
-
|
35
|
+
version_requirements: *2154203600
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: logging
|
38
|
+
requirement: &2154203040 !ruby/object:Gem::Requirement
|
57
39
|
none: false
|
58
|
-
requirements:
|
59
|
-
- -
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
|
62
|
-
segments:
|
63
|
-
- 1
|
64
|
-
- 4
|
65
|
-
- 3
|
66
|
-
version: 1.4.3
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 1.6.1
|
67
44
|
type: :development
|
68
|
-
version_requirements: *id003
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: bones
|
71
45
|
prerelease: false
|
72
|
-
|
46
|
+
version_requirements: *2154203040
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: bones
|
49
|
+
requirement: &2154202560 !ruby/object:Gem::Requirement
|
73
50
|
none: false
|
74
|
-
requirements:
|
75
|
-
- -
|
76
|
-
- !ruby/object:Gem::Version
|
77
|
-
|
78
|
-
segments:
|
79
|
-
- 3
|
80
|
-
- 5
|
81
|
-
- 4
|
82
|
-
version: 3.5.4
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 3.7.2
|
83
55
|
type: :development
|
84
|
-
|
85
|
-
|
86
|
-
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *2154202560
|
58
|
+
description: ! 'Serv-O-Lux is a collection of Ruby classes that are useful for daemon
|
59
|
+
and
|
60
|
+
|
87
61
|
process management, and for writing your own Ruby services. The code is well
|
62
|
+
|
88
63
|
documented and tested. It works with Ruby and JRuby supporing both 1.8 and 1.9
|
89
|
-
|
64
|
+
|
65
|
+
interpreters.'
|
90
66
|
email: tim.pease@gmail.com
|
91
67
|
executables: []
|
92
|
-
|
93
68
|
extensions: []
|
94
|
-
|
95
|
-
extra_rdoc_files:
|
69
|
+
extra_rdoc_files:
|
96
70
|
- History.txt
|
97
71
|
- README.rdoc
|
98
|
-
|
99
|
-
|
72
|
+
files:
|
73
|
+
- .gitignore
|
74
|
+
- .travis.yml
|
100
75
|
- History.txt
|
101
76
|
- README.rdoc
|
102
77
|
- Rakefile
|
@@ -119,40 +94,30 @@ files:
|
|
119
94
|
- spec/spec_helper.rb
|
120
95
|
- spec/threaded_spec.rb
|
121
96
|
- version.txt
|
122
|
-
has_rdoc: true
|
123
97
|
homepage: http://gemcutter.org/gems/servolux
|
124
98
|
licenses: []
|
125
|
-
|
126
99
|
post_install_message:
|
127
|
-
rdoc_options:
|
100
|
+
rdoc_options:
|
128
101
|
- --main
|
129
102
|
- README.rdoc
|
130
|
-
require_paths:
|
103
|
+
require_paths:
|
131
104
|
- lib
|
132
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
105
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
133
106
|
none: false
|
134
|
-
requirements:
|
135
|
-
- -
|
136
|
-
- !ruby/object:Gem::Version
|
137
|
-
|
138
|
-
|
139
|
-
- 0
|
140
|
-
version: "0"
|
141
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ! '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
142
112
|
none: false
|
143
|
-
requirements:
|
144
|
-
- -
|
145
|
-
- !ruby/object:Gem::Version
|
146
|
-
|
147
|
-
segments:
|
148
|
-
- 0
|
149
|
-
version: "0"
|
113
|
+
requirements:
|
114
|
+
- - ! '>='
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
150
117
|
requirements: []
|
151
|
-
|
152
118
|
rubyforge_project: servolux
|
153
|
-
rubygems_version: 1.
|
119
|
+
rubygems_version: 1.8.11
|
154
120
|
signing_key:
|
155
121
|
specification_version: 3
|
156
|
-
summary:
|
122
|
+
summary: ! '* {Homepage}[http://rubygems.'
|
157
123
|
test_files: []
|
158
|
-
|