deep_test 1.0.4 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +4 -0
- data/README +10 -6
- data/Rakefile +9 -5
- data/lib/deep_test/extensions/object_extension.rb +20 -1
- data/lib/deep_test/rake_tasks.rb +0 -1
- data/lib/deep_test/server.rb +0 -4
- data/lib/deep_test/test_task.rb +27 -10
- data/lib/deep_test/tuple_space_factory.rb +1 -1
- data/lib/deep_test/warlock.rb +59 -0
- data/lib/deep_test.rb +4 -0
- data/test/deep_test/extensions/object_extension_test.rb +37 -0
- data/test/deep_test/warlock_test.rb +21 -0
- data/test/test_helper.rb +0 -1
- data/test/test_task_test.rb +6 -6
- metadata +9 -15
- data/lib/deep_test/start_workers.rb +0 -23
- data/lib/deep_test/tasks/rinda.rake +0 -33
- data/test/deep_test/start_workers_test.rb +0 -9
data/CHANGELOG
ADDED
data/README
CHANGED
@@ -1,10 +1,6 @@
|
|
1
1
|
= DeepTest
|
2
2
|
|
3
|
-
DeepTest enables tests to run in multiple processes.
|
4
|
-
|
5
|
-
== Authors
|
6
|
-
|
7
|
-
anonymous z, Dan[http://www.dcmanges.com/blog] Manges[http://www.dcmanges.com/blog], David Vollbracht
|
3
|
+
DeepTest enables tests to run in parallel using multiple processes.
|
8
4
|
|
9
5
|
== Usage
|
10
6
|
|
@@ -14,10 +10,18 @@ In your Rakefile:
|
|
14
10
|
require "deep_test/rake_tasks"
|
15
11
|
|
16
12
|
# sample DeepTest task
|
13
|
+
|
17
14
|
DeepTest::TestTask.new "task_name" do |t|
|
15
|
+
t.number_of_workers = 2 # optional, defaults to 2
|
18
16
|
t.pattern = "test/**/*_test.rb"
|
19
|
-
t.processes = 2 # optional, defaults to 2
|
20
17
|
end
|
21
18
|
|
19
|
+
== Contributors
|
20
|
+
|
21
|
+
+* anonymous z
|
22
|
+
+* Alex Chaffee
|
23
|
+
+* Dan[http://www.dcmanges.com/blog] Manges[http://www.dcmanges.com/blog]
|
24
|
+
+* David Vollbracht
|
25
|
+
|
22
26
|
== License
|
23
27
|
Released under Ruby's[http://www.ruby-lang.org/en/LICENSE.txt] license[http://www.ruby-lang.org/en/LICENSE.txt]
|
data/Rakefile
CHANGED
@@ -14,8 +14,8 @@ Rake::TestTask.new do |t|
|
|
14
14
|
end
|
15
15
|
|
16
16
|
DeepTest::TestTask.new :deep_test do |t|
|
17
|
+
t.number_of_workers = 2
|
17
18
|
t.pattern = "test/**/*_test.rb"
|
18
|
-
t.processes = 2
|
19
19
|
end
|
20
20
|
|
21
21
|
desc "Generate documentation"
|
@@ -34,22 +34,22 @@ end
|
|
34
34
|
Gem::manage_gems
|
35
35
|
|
36
36
|
specification = Gem::Specification.new do |s|
|
37
|
+
s.platform = Gem::Platform::RUBY
|
37
38
|
s.name = "deep_test"
|
38
39
|
s.summary = "DeepTest runs tests in multiple processes."
|
39
|
-
s.version = "1.0
|
40
|
+
s.version = "1.1.0"
|
40
41
|
s.author = "anonymous z, Dan Manges, David Vollbracht"
|
41
42
|
s.description = s.summary
|
42
43
|
s.email = "daniel.manges@gmail.com"
|
43
44
|
s.homepage = "http://deep-test.rubyforge.org"
|
44
45
|
s.rubyforge_project = "deep-test"
|
45
|
-
s.add_dependency "daemons", ">= 1.0.7"
|
46
46
|
|
47
47
|
s.has_rdoc = true
|
48
|
-
s.extra_rdoc_files = ['README']
|
48
|
+
s.extra_rdoc_files = ['README', 'CHANGELOG']
|
49
49
|
s.rdoc_options << '--title' << "DeepTest" << '--main' << 'README' << '--line-numbers'
|
50
50
|
|
51
51
|
s.autorequire = "deep_test"
|
52
|
-
s.files = FileList['{lib,test}/**/*.{rb,rake}', 'README', 'Rakefile'].to_a
|
52
|
+
s.files = FileList['{lib,test}/**/*.{rb,rake}', 'README', 'CHANGELOG', 'Rakefile'].to_a
|
53
53
|
end
|
54
54
|
|
55
55
|
Rake::GemPackageTask.new(specification) do |package|
|
@@ -59,3 +59,7 @@ end
|
|
59
59
|
|
60
60
|
Rake::Task[:gem].prerequisites.unshift :deep_test
|
61
61
|
Rake::Task[:gem].prerequisites.unshift :test
|
62
|
+
|
63
|
+
task :tar do
|
64
|
+
system "tar zcf pkg/deep_test.tar.gz --exclude=.svn --exclude='*.tar.gz' --exclude='*.gem' --directory=.. deep_test"
|
65
|
+
end
|
@@ -6,7 +6,26 @@ module DeepTest
|
|
6
6
|
yield
|
7
7
|
$stdout.string
|
8
8
|
ensure
|
9
|
-
$stdout = old_stdout
|
9
|
+
$stdout = old_stdout if old_stdout
|
10
|
+
end
|
11
|
+
|
12
|
+
def retrying(description = nil, times = 5)
|
13
|
+
i = 0
|
14
|
+
loop do
|
15
|
+
begin
|
16
|
+
return yield
|
17
|
+
rescue => e
|
18
|
+
i += 1
|
19
|
+
print "#{description} received exception #{e}. "
|
20
|
+
if i < times
|
21
|
+
puts "Retrying..."
|
22
|
+
sleep 0.5
|
23
|
+
else
|
24
|
+
puts "Aborting."
|
25
|
+
raise e
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
10
29
|
end
|
11
30
|
end
|
12
31
|
end
|
data/lib/deep_test/rake_tasks.rb
CHANGED
data/lib/deep_test/server.rb
CHANGED
data/lib/deep_test/test_task.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
module DeepTest
|
2
2
|
class TestTask
|
3
|
-
|
3
|
+
DEFAULT_NUMBER_OF_WORKERS = 2
|
4
|
+
attr_writer :number_of_workers, :pattern
|
4
5
|
|
5
6
|
def initialize(name = :deep_test)
|
6
7
|
@name = name
|
@@ -10,30 +11,46 @@ module DeepTest
|
|
10
11
|
|
11
12
|
def define
|
12
13
|
desc "Run '#{@name}' suite using DeepTest"
|
13
|
-
task @name
|
14
|
+
task @name do
|
14
15
|
begin
|
15
16
|
deep_test_lib = File.expand_path(File.dirname(__FILE__) + "/..")
|
17
|
+
$LOAD_PATH << deep_test_lib
|
18
|
+
require "deep_test"
|
19
|
+
warlock = DeepTest::Warlock.new
|
16
20
|
|
21
|
+
# server
|
22
|
+
warlock.start "server" do
|
23
|
+
DeepTest::Server.start
|
24
|
+
end
|
25
|
+
sleep 0.25
|
26
|
+
|
17
27
|
# workers
|
18
|
-
|
19
|
-
|
28
|
+
number_of_workers.times do |i|
|
29
|
+
warlock.start "worker #{i}" do
|
30
|
+
srand # re-seed random numbers
|
31
|
+
ENV["RAILS_ENV"] = "test"
|
32
|
+
Object.const_set "RAILS_ENV", "test"
|
33
|
+
Dir.glob(pattern).each { |file| load file }
|
34
|
+
blackboard = DeepTest::RindaBlackboard.new
|
35
|
+
DeepTest::Worker.new(blackboard).run
|
36
|
+
end
|
37
|
+
end
|
20
38
|
|
21
39
|
# loader
|
22
40
|
loader = File.expand_path(File.dirname(__FILE__) + "/loader.rb")
|
23
41
|
ruby "-I#{deep_test_lib} #{loader} '#{pattern}'"
|
24
42
|
ensure
|
25
|
-
|
26
|
-
Rake::Task["deep_test:server:stop"].invoke
|
43
|
+
warlock.stop_all if warlock
|
27
44
|
end
|
28
45
|
end
|
29
46
|
end
|
30
47
|
|
48
|
+
def number_of_workers
|
49
|
+
@number_of_workers ? @number_of_workers.to_i : DEFAULT_NUMBER_OF_WORKERS
|
50
|
+
end
|
51
|
+
|
31
52
|
def pattern
|
32
53
|
Dir.pwd + "/" + (@pattern || "test/**/*_test.rb")
|
33
54
|
end
|
34
|
-
|
35
|
-
def processes
|
36
|
-
@processes ? @processes.to_i : 2
|
37
|
-
end
|
38
55
|
end
|
39
56
|
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
module DeepTest
|
2
|
+
class Warlock
|
3
|
+
def initialize
|
4
|
+
@demons = []
|
5
|
+
end
|
6
|
+
|
7
|
+
def start(name, &block)
|
8
|
+
begin
|
9
|
+
pid = Process.fork do
|
10
|
+
Signal.trap("HUP") { exit 0 }
|
11
|
+
yield
|
12
|
+
exit
|
13
|
+
end
|
14
|
+
raise "fatal: fork returned nil" if pid.nil?
|
15
|
+
@demons << [name, pid]
|
16
|
+
puts "Started #{name} (#{pid})"
|
17
|
+
rescue => e
|
18
|
+
puts "exception starting #{name}: #{e}"
|
19
|
+
puts "\t" + e.backtrace.join("\n\t")
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def stop_all
|
24
|
+
@demons.reverse.each do |demon|
|
25
|
+
name, pid = demon
|
26
|
+
if running?(pid)
|
27
|
+
Process.kill("HUP", pid)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
@demons.each do |demon|
|
31
|
+
name, pid = demon
|
32
|
+
begin
|
33
|
+
Process.wait(pid)
|
34
|
+
rescue Errno::ECHILD => e
|
35
|
+
puts e
|
36
|
+
end
|
37
|
+
puts "Stopped #{name} (#{pid})"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
#stolen from daemons
|
42
|
+
def running?(pid)
|
43
|
+
# Check if process is in existence
|
44
|
+
# The simplest way to do this is to send signal '0'
|
45
|
+
# (which is a single system call) that doesn't actually
|
46
|
+
# send a signal
|
47
|
+
begin
|
48
|
+
Process.kill(0, pid)
|
49
|
+
return true
|
50
|
+
rescue Errno::ESRCH
|
51
|
+
return false
|
52
|
+
rescue ::Exception # for example on EPERM (process exists but does not belong to us)
|
53
|
+
return true
|
54
|
+
#rescue Errno::EPERM
|
55
|
+
# return false
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
data/lib/deep_test.rb
CHANGED
@@ -1,8 +1,11 @@
|
|
1
1
|
module DeepTest
|
2
2
|
end
|
3
|
+
require 'rinda/ring'
|
4
|
+
require 'rinda/tuplespace'
|
3
5
|
|
4
6
|
require "test/unit/testresult"
|
5
7
|
require "test/unit/error"
|
8
|
+
require 'test/unit/failure'
|
6
9
|
|
7
10
|
require "deep_test/extensions/testresult"
|
8
11
|
require "deep_test/extensions/error"
|
@@ -16,3 +19,4 @@ require "deep_test/supervised_test_suite"
|
|
16
19
|
require "deep_test/supervisor"
|
17
20
|
require "deep_test/test_task"
|
18
21
|
require "deep_test/worker"
|
22
|
+
require "deep_test/warlock"
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/../../test_helper"
|
2
|
+
|
3
|
+
unit_tests do
|
4
|
+
test "retrying once" do
|
5
|
+
object = Object.new
|
6
|
+
object.expects(:call_it_twice).times(2).raises(RuntimeError).then.returns(:ok)
|
7
|
+
result = nil
|
8
|
+
capture_stdout do
|
9
|
+
result = retrying do
|
10
|
+
object.call_it_twice
|
11
|
+
end
|
12
|
+
end
|
13
|
+
assert_equal :ok, result
|
14
|
+
end
|
15
|
+
|
16
|
+
test "retrying defaults to 5 times" do
|
17
|
+
object = Object.new
|
18
|
+
object.expects(:may_i_please_have_another).times(5).
|
19
|
+
raises(RuntimeError).raises(RuntimeError).raises(RuntimeError).raises(RuntimeError).returns("ok")
|
20
|
+
capture_stdout do
|
21
|
+
retrying do
|
22
|
+
object.may_i_please_have_another
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
test "retrying raises exception if still failing after number of attempts" do
|
28
|
+
my_error = Class.new(StandardError)
|
29
|
+
assert_raises(my_error) do
|
30
|
+
capture_stdout do
|
31
|
+
retrying "", 1 do
|
32
|
+
raise my_error
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
2
|
+
|
3
|
+
unit_tests do
|
4
|
+
test "running? is true if sending kill(0, pid) does not fail" do
|
5
|
+
warlock = DeepTest::Warlock.new
|
6
|
+
Process.expects(:kill).with(0, :pid)
|
7
|
+
assert_equal true, warlock.running?(:pid)
|
8
|
+
end
|
9
|
+
|
10
|
+
test "running? is false if Process.kill(0, pid) raises Errno::ESRCH" do
|
11
|
+
warlock = DeepTest::Warlock.new
|
12
|
+
Process.stubs(:kill).raises(Errno::ESRCH)
|
13
|
+
assert_equal false, warlock.running?(:pid)
|
14
|
+
end
|
15
|
+
|
16
|
+
test "running? is true if Process.kill raises Exception" do
|
17
|
+
warlock = DeepTest::Warlock.new
|
18
|
+
Process.stubs(:kill).raises(Exception)
|
19
|
+
assert_equal true, warlock.running?(:pid)
|
20
|
+
end
|
21
|
+
end
|
data/test/test_helper.rb
CHANGED
data/test/test_task_test.rb
CHANGED
@@ -3,7 +3,7 @@ require File.dirname(__FILE__) + "/test_helper"
|
|
3
3
|
unit_tests do
|
4
4
|
test "defines a rake task with the name passed to the constructor" do
|
5
5
|
DeepTest::TestTask.any_instance.stubs(:desc)
|
6
|
-
DeepTest::TestTask.any_instance.expects(:task).with
|
6
|
+
DeepTest::TestTask.any_instance.expects(:task).with(:my_task_name)
|
7
7
|
DeepTest::TestTask.new :my_task_name do
|
8
8
|
end
|
9
9
|
end
|
@@ -24,18 +24,18 @@ unit_tests do
|
|
24
24
|
assert_equal "test/**/*_test.rb", task.pattern[-"test/**/*_test.rb".size..-1]
|
25
25
|
end
|
26
26
|
|
27
|
-
test "
|
27
|
+
test "number_of_workers defaults to 2" do
|
28
28
|
task = DeepTest::TestTask.new do |t|
|
29
29
|
t.stubs(:define)
|
30
30
|
end
|
31
|
-
assert_equal 2, task.
|
31
|
+
assert_equal 2, task.number_of_workers
|
32
32
|
end
|
33
33
|
|
34
|
-
test "
|
34
|
+
test "number_of_workers can be set" do
|
35
35
|
task = DeepTest::TestTask.new do |t|
|
36
|
-
t.
|
36
|
+
t.number_of_workers = 42
|
37
37
|
t.stubs(:define)
|
38
38
|
end
|
39
|
-
assert_equal 42, task.
|
39
|
+
assert_equal 42, task.number_of_workers
|
40
40
|
end
|
41
41
|
end
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.4
|
|
3
3
|
specification_version: 1
|
4
4
|
name: deep_test
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 1.0
|
7
|
-
date: 2007-12-
|
6
|
+
version: 1.1.0
|
7
|
+
date: 2007-12-23 00:00:00 -05:00
|
8
8
|
summary: DeepTest runs tests in multiple processes.
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -35,16 +35,15 @@ files:
|
|
35
35
|
- lib/deep_test/rinda_blackboard.rb
|
36
36
|
- lib/deep_test/server.rb
|
37
37
|
- lib/deep_test/simple_test_blackboard.rb
|
38
|
-
- lib/deep_test/start_workers.rb
|
39
38
|
- lib/deep_test/supervised_test_suite.rb
|
40
39
|
- lib/deep_test/supervisor.rb
|
41
40
|
- lib/deep_test/test_task.rb
|
42
41
|
- lib/deep_test/tuple_space_factory.rb
|
42
|
+
- lib/deep_test/warlock.rb
|
43
43
|
- lib/deep_test/worker.rb
|
44
44
|
- lib/deep_test/extensions/error.rb
|
45
45
|
- lib/deep_test/extensions/object_extension.rb
|
46
46
|
- lib/deep_test/extensions/testresult.rb
|
47
|
-
- lib/deep_test/tasks/rinda.rake
|
48
47
|
- test/simple_test_blackboard_test.rb
|
49
48
|
- test/supervised_test_suite_test.rb
|
50
49
|
- test/supervisor_test.rb
|
@@ -54,8 +53,10 @@ files:
|
|
54
53
|
- test/worker_test.rb
|
55
54
|
- test/deep_test/loader_test.rb
|
56
55
|
- test/deep_test/rinda_blackboard_test.rb
|
57
|
-
- test/deep_test/
|
56
|
+
- test/deep_test/warlock_test.rb
|
57
|
+
- test/deep_test/extensions/object_extension_test.rb
|
58
58
|
- README
|
59
|
+
- CHANGELOG
|
59
60
|
- Rakefile
|
60
61
|
test_files: []
|
61
62
|
|
@@ -67,19 +68,12 @@ rdoc_options:
|
|
67
68
|
- --line-numbers
|
68
69
|
extra_rdoc_files:
|
69
70
|
- README
|
71
|
+
- CHANGELOG
|
70
72
|
executables: []
|
71
73
|
|
72
74
|
extensions: []
|
73
75
|
|
74
76
|
requirements: []
|
75
77
|
|
76
|
-
dependencies:
|
77
|
-
|
78
|
-
name: daemons
|
79
|
-
version_requirement:
|
80
|
-
version_requirements: !ruby/object:Gem::Version::Requirement
|
81
|
-
requirements:
|
82
|
-
- - ">="
|
83
|
-
- !ruby/object:Gem::Version
|
84
|
-
version: 1.0.7
|
85
|
-
version:
|
78
|
+
dependencies: []
|
79
|
+
|
@@ -1,23 +0,0 @@
|
|
1
|
-
module DeepTest
|
2
|
-
module StartWorkers
|
3
|
-
def self.run(args)
|
4
|
-
processes, pattern = args
|
5
|
-
processes.to_i.times do
|
6
|
-
Daemons.run_proc "deep_test_worker", :multiple => true, :ARGV => ["start"], :backtrace => true, :log_output => true do
|
7
|
-
require "deep_test"
|
8
|
-
ENV["RAILS_ENV"] = "test"
|
9
|
-
Object.const_set "RAILS_ENV", "test"
|
10
|
-
Dir.glob(pattern).each { |file| load file }
|
11
|
-
blackboard = DeepTest::RindaBlackboard.new
|
12
|
-
DeepTest::Worker.new(blackboard).run
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
if __FILE__ == $0
|
20
|
-
require "rubygems"
|
21
|
-
require "daemons"
|
22
|
-
DeepTest::StartWorkers.run ARGV
|
23
|
-
end
|
@@ -1,33 +0,0 @@
|
|
1
|
-
require "rubygems"
|
2
|
-
begin
|
3
|
-
require "daemons"
|
4
|
-
rescue LoadError
|
5
|
-
raise "The daemons gem must be installed to use deep_test"
|
6
|
-
end
|
7
|
-
|
8
|
-
namespace :deep_test do
|
9
|
-
namespace :server do
|
10
|
-
task :start do
|
11
|
-
Daemons.run_proc "deep_test_server", :ARGV => ["start"], :backtrace => true, :log_output => true do
|
12
|
-
require "deep_test"
|
13
|
-
ENV["RAILS_ENV"] = "test"
|
14
|
-
Object.const_set "RAILS_ENV", "test"
|
15
|
-
DeepTest::Server.start
|
16
|
-
end
|
17
|
-
sleep 0.25
|
18
|
-
end
|
19
|
-
task :stop do
|
20
|
-
Daemons.run("deep_test_server", :ARGV => ["stop"])
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
namespace :workers do
|
25
|
-
task :start do
|
26
|
-
raise "deprecated -dan"
|
27
|
-
end
|
28
|
-
|
29
|
-
task :stop do
|
30
|
-
Daemons.run("deep_test_worker", :ARGV => ["stop"])
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|