jstorimer-deep-test 1.4.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/README.rdoc +41 -70
- data/Rakefile +47 -119
- data/TODO +2 -2
- data/VERSION +1 -1
- data/infrastructure/dynamic_teardown.rb +22 -0
- data/{test → infrastructure}/fake_deadlock_error.rb +0 -0
- data/infrastructure/load.rb +11 -0
- data/infrastructure/test_central_command.rb +15 -0
- data/infrastructure/test_exception.rb +7 -0
- data/{test → infrastructure}/test_factory.rb +0 -0
- data/infrastructure/test_logger.rb +11 -0
- data/infrastructure/test_operator.rb +15 -0
- data/infrastructure/test_result.rb +15 -0
- data/infrastructure/thread_agent.rb +21 -0
- data/infrastructure/timewarp/Rakefile +14 -0
- data/infrastructure/timewarp/lib/timewarp.rb +21 -0
- data/infrastructure/timewarp/test/timewarp_test.rb +45 -0
- data/lib/deep_test.rb +28 -40
- data/lib/deep_test/agent.rb +108 -0
- data/lib/deep_test/central_command.rb +165 -0
- data/lib/deep_test/cpu_info.rb +22 -0
- data/lib/deep_test/database/mysql_setup_listener.rb +11 -12
- data/lib/deep_test/database/setup_listener.rb +23 -23
- data/lib/deep_test/demon.rb +25 -0
- data/lib/deep_test/distributed/beachhead.rb +104 -0
- data/lib/deep_test/distributed/dispatch_controller.rb +17 -10
- data/lib/deep_test/distributed/establish_beachhead.rb +19 -0
- data/lib/deep_test/distributed/landing_fleet.rb +30 -0
- data/lib/deep_test/distributed/landing_ship.rb +60 -0
- data/lib/deep_test/distributed/remote_deployment.rb +56 -0
- data/lib/deep_test/distributed/rsync.rb +25 -12
- data/lib/deep_test/distributed/shell_environment.rb +50 -0
- data/lib/deep_test/distributed/ssh_client_connection_info.rb +14 -0
- data/lib/deep_test/failure_message.rb +19 -0
- data/lib/deep_test/lib_root.rb +4 -0
- data/lib/deep_test/listener_list.rb +1 -1
- data/lib/deep_test/local_deployment.rb +46 -0
- data/lib/deep_test/logger.rb +17 -2
- data/lib/deep_test/main.rb +41 -0
- data/lib/deep_test/marshallable_exception_wrapper.rb +4 -4
- data/lib/deep_test/metrics/data.rb +34 -0
- data/lib/deep_test/metrics/measurement.rb +39 -0
- data/lib/deep_test/{null_worker_listener.rb → null_listener.rb} +14 -14
- data/lib/deep_test/options.rb +41 -56
- data/lib/deep_test/proxy_io.rb +77 -0
- data/lib/deep_test/rake_tasks.rb +3 -1
- data/lib/deep_test/result_reader.rb +10 -6
- data/lib/deep_test/rspec_detector.rb +1 -1
- data/lib/deep_test/spec.rb +5 -1
- data/lib/deep_test/spec/extensions/example_methods.rb +7 -1
- data/lib/deep_test/spec/extensions/spec_task.rb +3 -2
- data/lib/deep_test/spec/runner.rb +32 -17
- data/lib/deep_test/spec/work_result.rb +2 -0
- data/lib/deep_test/test/run_test_suite.rb +5 -0
- data/lib/deep_test/test/runner.rb +2 -2
- data/lib/deep_test/test/supervised_test_suite.rb +9 -10
- data/lib/deep_test/test/work_result.rb +1 -0
- data/lib/deep_test/test_task.rb +1 -1
- data/lib/deep_test/ui/console.rb +9 -11
- data/lib/deep_test/warlock.rb +37 -25
- data/lib/telegraph.rb +29 -0
- data/lib/telegraph/ack_sequence.rb +14 -0
- data/lib/telegraph/logging.rb +20 -0
- data/lib/telegraph/message.rb +39 -0
- data/lib/telegraph/operator.rb +47 -0
- data/lib/telegraph/switchboard.rb +57 -0
- data/lib/telegraph/wire.rb +73 -0
- data/negative_acceptance_tests/dying_spec.rb +13 -0
- data/negative_acceptance_tests/dying_test.rb +13 -0
- data/negative_acceptance_tests/failing_spec.rb +9 -0
- data/{test/failing.rb → negative_acceptance_tests/failing_test.rb} +3 -1
- data/negative_acceptance_tests/kill_agent_one_on_start_work.rb +16 -0
- data/negative_acceptance_tests/passing_spec.rb +10 -0
- data/negative_acceptance_tests/passing_test.rb +12 -0
- data/negative_acceptance_tests/tasks.rake +87 -0
- data/negative_acceptance_tests/tests.rb +60 -0
- data/sample_rails_project/deep_test.rb +4 -0
- data/sample_rails_project/lib/{foreign_host_worker_simulation_listener.rb → foreign_host_agent_simulation_listener.rb} +6 -4
- data/sample_rails_project/lib/tasks/deep_test.rake +13 -4
- data/spec/deep_test/options_spec.rb +80 -59
- data/spec/deep_test/spec/extensions/example_methods_spec.rb +5 -4
- data/spec/deep_test/spec/extensions/spec_task_spec.rb +4 -6
- data/spec/deep_test/spec/runner_spec.rb +59 -32
- data/spec/spec_helper.rb +14 -6
- data/test/deep_test/agent_test.rb +175 -0
- data/test/deep_test/central_command_test.rb +147 -0
- data/test/deep_test/cpu_info_test.rb +33 -0
- data/test/deep_test/database/mysql_setup_listener_test.rb +13 -9
- data/test/deep_test/demon_test.rb +23 -0
- data/test/deep_test/distributed/beachhead_test.rb +67 -0
- data/test/deep_test/distributed/dispatch_controller_test.rb +130 -177
- data/test/deep_test/distributed/filename_resolver_test.rb +38 -34
- data/test/deep_test/distributed/landing_fleet_test.rb +55 -0
- data/test/deep_test/distributed/landing_ship_test.rb +48 -0
- data/test/deep_test/distributed/remote_deployment_test.rb +134 -0
- data/test/deep_test/distributed/rsync_test.rb +42 -62
- data/test/deep_test/distributed/shell_environment_fixtures/set_bar_to_foo +1 -0
- data/test/deep_test/distributed/shell_environment_fixtures/set_foo_to_bar +1 -0
- data/test/deep_test/distributed/shell_environment_fixtures/set_foo_to_baz +1 -0
- data/test/deep_test/distributed/shell_environment_test.rb +108 -0
- data/test/deep_test/distributed/ssh_client_connection_info_test.rb +34 -0
- data/test/deep_test/listener_list_test.rb +17 -15
- data/test/deep_test/local_deployment_test.rb +19 -0
- data/test/deep_test/logger_test.rb +34 -7
- data/test/deep_test/main_test.rb +12 -0
- data/test/deep_test/marshallable_exception_wrapper_test.rb +31 -29
- data/test/deep_test/metrics/data_test.rb +22 -0
- data/test/deep_test/metrics/measurement_test.rb +18 -0
- data/test/deep_test/proxy_io_test.rb +104 -0
- data/test/deep_test/result_reader_test.rb +95 -95
- data/test/deep_test/test/extensions/error_test.rb +38 -36
- data/test/deep_test/test/runner_test.rb +7 -3
- data/test/deep_test/test/supervised_test_suite_test.rb +89 -61
- data/test/deep_test/test/work_result_test.rb +80 -76
- data/test/deep_test/test/work_unit_test.rb +53 -51
- data/test/deep_test/test_task_test.rb +10 -38
- data/test/deep_test/ui/console_test.rb +8 -4
- data/test/deep_test/warlock_test.rb +33 -31
- data/test/test_helper.rb +20 -5
- data/test/test_task_test.rb +60 -57
- metadata +94 -84
- data/bin/deep_test +0 -15
- data/jstorimer-deep-test-0.1.0.gem +0 -0
- data/jstorimer-deep-test.gemspec +0 -1425
- data/lib/deep_test/distributed/drb_client_connection_info.rb +0 -15
- data/lib/deep_test/distributed/master_test_server.rb +0 -52
- data/lib/deep_test/distributed/multi_test_server_proxy.rb +0 -44
- data/lib/deep_test/distributed/null_work_unit.rb +0 -12
- data/lib/deep_test/distributed/remote_worker_client.rb +0 -54
- data/lib/deep_test/distributed/remote_worker_server.rb +0 -82
- data/lib/deep_test/distributed/show_status.rhtml +0 -41
- data/lib/deep_test/distributed/test_server.rb +0 -78
- data/lib/deep_test/distributed/test_server_status.rb +0 -9
- data/lib/deep_test/distributed/test_server_workers.rb +0 -24
- data/lib/deep_test/distributed/throughput_runner.rb +0 -42
- data/lib/deep_test/distributed/throughput_statistics.rb +0 -26
- data/lib/deep_test/distributed/throughput_worker_client.rb +0 -19
- data/lib/deep_test/extensions/drb_extension.rb +0 -34
- data/lib/deep_test/local_workers.rb +0 -55
- data/lib/deep_test/metrics/gatherer.rb +0 -67
- data/lib/deep_test/metrics/queue_lock_wait_time_measurement.rb +0 -133
- data/lib/deep_test/option.rb +0 -60
- data/lib/deep_test/process_orchestrator.rb +0 -49
- data/lib/deep_test/server.rb +0 -75
- data/lib/deep_test/spec/extensions/reporter.rb +0 -29
- data/lib/deep_test/worker.rb +0 -57
- data/script/internal/run_test_suite.rb +0 -7
- data/script/public/master_test_server.rb +0 -24
- data/script/public/test_server.rb +0 -18
- data/script/public/test_throughput.rb +0 -29
- data/spec/deep_test/option_spec.rb +0 -33
- data/spec/thread_worker.rb +0 -25
- data/test/deep_test/distributed/drb_client_connection_info_test.rb +0 -42
- data/test/deep_test/distributed/master_test_server_test.rb +0 -32
- data/test/deep_test/distributed/multi_test_server_proxy_test.rb +0 -96
- data/test/deep_test/distributed/remote_worker_client_test.rb +0 -180
- data/test/deep_test/distributed/remote_worker_server_test.rb +0 -99
- data/test/deep_test/distributed/test_server_test.rb +0 -94
- data/test/deep_test/distributed/test_server_workers_test.rb +0 -26
- data/test/deep_test/distributed/throughput_runner_test.rb +0 -68
- data/test/deep_test/distributed/throughput_worker_client_test.rb +0 -28
- data/test/deep_test/local_workers_test.rb +0 -22
- data/test/deep_test/metrics/gatherer_test.rb +0 -66
- data/test/deep_test/process_orchestrator_test.rb +0 -11
- data/test/deep_test/server_test.rb +0 -58
- data/test/deep_test/worker_test.rb +0 -94
- data/test/failing.rake +0 -11
- data/test/simple_test_blackboard.rb +0 -45
- data/test/simple_test_blackboard_test.rb +0 -33
data/lib/deep_test/rake_tasks.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
require "socket"
|
2
|
+
require "base64"
|
2
3
|
|
3
|
-
require File.dirname(__FILE__) + "/option"
|
4
4
|
require File.dirname(__FILE__) + "/options"
|
5
|
+
require File.dirname(__FILE__) + "/cpu_info"
|
5
6
|
require File.dirname(__FILE__) + "/test_task"
|
6
7
|
require File.dirname(__FILE__) + "/rspec_detector"
|
7
8
|
|
@@ -9,3 +10,4 @@ DeepTest::RSpecDetector.if_rspec_available do
|
|
9
10
|
require 'spec/rake/spectask'
|
10
11
|
require File.dirname(__FILE__) + "/spec/extensions/spec_task"
|
11
12
|
end
|
13
|
+
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module DeepTest
|
2
2
|
class ResultReader
|
3
|
-
def initialize(
|
4
|
-
@
|
3
|
+
def initialize(central_command)
|
4
|
+
@central_command = central_command
|
5
5
|
end
|
6
6
|
|
7
7
|
def read(original_work_units_by_id)
|
@@ -11,10 +11,10 @@ module DeepTest
|
|
11
11
|
begin
|
12
12
|
until errors == work_units_by_id.size
|
13
13
|
Thread.pass
|
14
|
-
result = @
|
14
|
+
result = @central_command.take_result
|
15
15
|
next if result.nil?
|
16
16
|
|
17
|
-
if
|
17
|
+
if Agent::Error === result
|
18
18
|
puts result
|
19
19
|
errors += 1
|
20
20
|
else
|
@@ -26,8 +26,12 @@ module DeepTest
|
|
26
26
|
yield [work_unit, result]
|
27
27
|
end
|
28
28
|
end
|
29
|
-
rescue
|
30
|
-
|
29
|
+
rescue CentralCommand::NoAgentsRunningError
|
30
|
+
FailureMessage.show "DeepTest Agents Are Not Running", <<-end_msg
|
31
|
+
DeepTest's test running agents have not contacted the
|
32
|
+
server to indicate they are still running.
|
33
|
+
Shutting down the test run on the assumption that they have died.
|
34
|
+
end_msg
|
31
35
|
end
|
32
36
|
|
33
37
|
work_units_by_id
|
data/lib/deep_test/spec.rb
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'spec/runner/example_group_runner'
|
3
|
+
if ::Spec::VERSION::MAJOR == 1 &&
|
4
|
+
::Spec::VERSION::MINOR == 1 &&
|
5
|
+
::Spec::VERSION::TINY >= 12
|
6
|
+
require 'spec/example/before_and_after_hooks'
|
7
|
+
end
|
3
8
|
require 'spec/example/example_group_methods'
|
4
9
|
require 'spec/rake/spectask'
|
5
10
|
|
@@ -7,7 +12,6 @@ require File.dirname(__FILE__) + "/spec/extensions/example_group_methods"
|
|
7
12
|
require File.dirname(__FILE__) + "/spec/extensions/example_methods"
|
8
13
|
require File.dirname(__FILE__) + "/spec/extensions/spec_task"
|
9
14
|
require File.dirname(__FILE__) + "/spec/extensions/options"
|
10
|
-
require File.dirname(__FILE__) + "/spec/extensions/reporter"
|
11
15
|
require File.dirname(__FILE__) + "/spec/runner"
|
12
16
|
require File.dirname(__FILE__) + "/spec/work_unit"
|
13
17
|
require File.dirname(__FILE__) + "/spec/work_result"
|
@@ -2,7 +2,13 @@ module Spec
|
|
2
2
|
module Example
|
3
3
|
module ExampleMethods
|
4
4
|
def identifier
|
5
|
-
|
5
|
+
if ::Spec::VERSION::MAJOR == 1 &&
|
6
|
+
::Spec::VERSION::MINOR == 1 &&
|
7
|
+
::Spec::VERSION::TINY >= 12
|
8
|
+
file, line = eval("caller", @_implementation).first.split(/:/)
|
9
|
+
else
|
10
|
+
file, line = implementation_backtrace.first.split(/:/)
|
11
|
+
end
|
6
12
|
Identifier.new(file, line.to_i, self.class.description, description)
|
7
13
|
end
|
8
14
|
|
@@ -1,10 +1,11 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/../../lib_root"
|
2
|
+
|
1
3
|
module Spec
|
2
4
|
module Rake
|
3
5
|
class SpecTask
|
4
6
|
def deep_test(options)
|
5
7
|
deep_test_options = DeepTest::Options.new(options)
|
6
|
-
deep_test_path = File.expand_path(
|
7
|
-
"/../../../deep_test")
|
8
|
+
deep_test_path = File.expand_path(DeepTest::LIB_ROOT + "/deep_test")
|
8
9
|
@deep_test_spec_opts = [
|
9
10
|
"--require #{deep_test_path}",
|
10
11
|
"--runner 'DeepTest::Spec::Runner:#{deep_test_options.to_command_line}'"
|
@@ -1,51 +1,66 @@
|
|
1
1
|
module DeepTest
|
2
2
|
module Spec
|
3
3
|
class Runner < ::Spec::Runner::ExampleGroupRunner
|
4
|
-
def initialize(options, deep_test_options
|
4
|
+
def initialize(options, deep_test_options)
|
5
5
|
super(options)
|
6
|
+
if ::Spec::VERSION::MAJOR == 1 &&
|
7
|
+
::Spec::VERSION::MINOR == 1 &&
|
8
|
+
::Spec::VERSION::TINY >= 12
|
9
|
+
@runner_options = options # added to make work with 1.1.12
|
10
|
+
end
|
6
11
|
@deep_test_options = DeepTest::Options.from_command_line(deep_test_options)
|
7
|
-
DeepTest.init(@deep_test_options)
|
8
|
-
@blackboard = blackboard
|
9
|
-
@workers = @deep_test_options.new_workers
|
10
12
|
end
|
11
13
|
|
12
|
-
def
|
13
|
-
|
14
|
-
|
14
|
+
def main
|
15
|
+
@main ||= Main.new @deep_test_options, @deep_test_options.new_deployment, self
|
16
|
+
end
|
17
|
+
|
18
|
+
def central_command
|
19
|
+
# Can't create central_command as default argument to initialize
|
20
|
+
# because Main hasn't been invoked at
|
15
21
|
# instantiation time
|
16
|
-
@
|
22
|
+
@central_command ||= main.central_command
|
17
23
|
end
|
18
24
|
|
19
25
|
def load_files(files)
|
20
|
-
|
26
|
+
main.load_files files
|
21
27
|
end
|
22
28
|
|
23
29
|
def run
|
24
|
-
|
30
|
+
main.run
|
25
31
|
end
|
26
32
|
|
27
|
-
def process_work_units
|
33
|
+
def process_work_units(central_command)
|
28
34
|
prepare
|
29
35
|
|
30
|
-
examples = example_groups.map
|
36
|
+
examples = (example_groups.map do |g|
|
37
|
+
if ::Spec::VERSION::MAJOR == 1 &&
|
38
|
+
::Spec::VERSION::MINOR == 1 &&
|
39
|
+
::Spec::VERSION::TINY >= 12
|
40
|
+
g.send(:examples_to_run, @runner_options) # added @runner_options to make wiork with 1.1.12
|
41
|
+
else
|
42
|
+
g.send(:examples_to_run)
|
43
|
+
end
|
44
|
+
end).flatten
|
31
45
|
examples_by_location = {}
|
32
46
|
examples.each do |example|
|
33
47
|
raise "duplicate example: #{example.identifier}" if examples_by_location[example.identifier]
|
34
48
|
examples_by_location[example.identifier] = example
|
35
|
-
|
49
|
+
central_command.write_work Spec::WorkUnit.new(example.identifier)
|
36
50
|
end
|
37
51
|
|
38
52
|
success = true
|
39
53
|
|
40
|
-
|
54
|
+
missing_examples = ResultReader.new(central_command).read(examples_by_location) do |example, result|
|
41
55
|
@options.reporter.example_finished(example, result.error)
|
42
56
|
success &= result.success?
|
43
57
|
end
|
44
58
|
|
45
|
-
success &=
|
59
|
+
success &= missing_examples.empty?
|
46
60
|
|
47
|
-
|
48
|
-
@options.reporter.example_finished(
|
61
|
+
if missing_examples.any?
|
62
|
+
@options.reporter.example_finished(examples_by_location[missing_examples.keys.first],
|
63
|
+
IncompleteTestRunError.new(missing_examples.size))
|
49
64
|
end
|
50
65
|
|
51
66
|
success
|
@@ -12,9 +12,9 @@ module DeepTest
|
|
12
12
|
@options = options
|
13
13
|
end
|
14
14
|
|
15
|
-
def process_work_units
|
15
|
+
def process_work_units(central_command)
|
16
16
|
suite = ::Test::Unit::AutoRunner::COLLECTORS[:objectspace].call NO_FILTERS
|
17
|
-
supervised_suite = DeepTest::Test::SupervisedTestSuite.new(suite,
|
17
|
+
supervised_suite = DeepTest::Test::SupervisedTestSuite.new(suite, central_command)
|
18
18
|
require 'test/unit/ui/console/testrunner'
|
19
19
|
result = ::Test::Unit::UI::Console::TestRunner.run(supervised_suite, ::Test::Unit::UI::NORMAL)
|
20
20
|
result.passed?
|
@@ -1,9 +1,9 @@
|
|
1
1
|
module DeepTest
|
2
2
|
module Test
|
3
3
|
class SupervisedTestSuite
|
4
|
-
def initialize(suite,
|
4
|
+
def initialize(suite, central_command)
|
5
5
|
@suite = suite
|
6
|
-
@
|
6
|
+
@central_command = central_command
|
7
7
|
end
|
8
8
|
|
9
9
|
def run(result, &progress_block)
|
@@ -25,24 +25,23 @@ module DeepTest
|
|
25
25
|
end
|
26
26
|
else
|
27
27
|
tests_by_name[test_suite.name] = test_suite
|
28
|
-
@
|
28
|
+
@central_command.write_work Test::WorkUnit.new(test_suite)
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
32
|
def read_results(result, tests_by_name)
|
33
|
-
DeepTest.logger.debug
|
34
|
-
|
35
|
-
|
36
|
-
ResultReader.new(@blackboard).read(tests_by_name) do |test, remote_result|
|
33
|
+
DeepTest.logger.debug { "SupervisedTestSuite: going to read #{tests_by_name.size} results" }
|
34
|
+
missing_tests =
|
35
|
+
ResultReader.new(@central_command).read(tests_by_name) do |test, remote_result|
|
37
36
|
remote_result.add_to result
|
38
37
|
yield ::Test::Unit::TestCase::FINISHED, test.name if block_given?
|
39
38
|
end
|
40
39
|
|
41
|
-
missing_tests.
|
42
|
-
result.add_error ::Test::Unit::Error.new(
|
40
|
+
if missing_tests.any?
|
41
|
+
result.add_error ::Test::Unit::Error.new("DeepTest Test Run", IncompleteTestRunError.new(missing_tests.size))
|
43
42
|
end
|
44
43
|
ensure
|
45
|
-
DeepTest.logger.debug
|
44
|
+
DeepTest.logger.debug { "SupervisedTestSuite: exiting with #{missing_tests.size} results left" }
|
46
45
|
end
|
47
46
|
end
|
48
47
|
end
|
data/lib/deep_test/test_task.rb
CHANGED
data/lib/deep_test/ui/console.rb
CHANGED
@@ -5,20 +5,18 @@ module DeepTest
|
|
5
5
|
end
|
6
6
|
|
7
7
|
METHOD_DESCRIPTIONS = {
|
8
|
-
:
|
9
|
-
:
|
10
|
-
:load_files => "Loading test files for
|
11
|
-
:
|
12
|
-
:stop_all => "Stopping workers"
|
8
|
+
:push_code => "Synchronizing working copies on distributed machines",
|
9
|
+
:establish_beachhead => "Spawning test environment processes",
|
10
|
+
:load_files => "Loading test files for agents",
|
11
|
+
:deploy_agents => "Deploying agents",
|
13
12
|
} unless defined?(METHOD_DESCRIPTIONS)
|
14
13
|
|
15
14
|
def distributed_failover_to_local(method, exception)
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
puts "*" * width
|
15
|
+
FailureMessage.show "Distributed DeepTest Failure", <<-end_msg
|
16
|
+
Failed during #{method}
|
17
|
+
#{exception.message}
|
18
|
+
Failing over to local run
|
19
|
+
end_msg
|
22
20
|
end
|
23
21
|
|
24
22
|
def dispatch_starting(method_name)
|
data/lib/deep_test/warlock.rb
CHANGED
@@ -1,20 +1,21 @@
|
|
1
1
|
module DeepTest
|
2
2
|
class Warlock
|
3
|
-
def initialize
|
3
|
+
def initialize(options)
|
4
|
+
@options = options
|
4
5
|
@demons_semaphore = Mutex.new
|
5
6
|
@demons = []
|
6
7
|
@reapers = []
|
7
8
|
end
|
8
9
|
|
9
|
-
def start(name,
|
10
|
+
def start(name, demon, *demon_args)
|
10
11
|
# Not synchronizing for the fork seems to cause
|
11
12
|
# random errors (Bus Error, Segfault, and GC non-object)
|
12
|
-
# in
|
13
|
+
# in Beachhead processes.
|
13
14
|
#
|
14
15
|
begin
|
15
16
|
pid = nil
|
16
17
|
@demons_semaphore.synchronize do
|
17
|
-
pid =
|
18
|
+
pid = fork do
|
18
19
|
# Fork leaves the semaphore locked and we'll never make it
|
19
20
|
# to end of synchronize block.
|
20
21
|
#
|
@@ -24,12 +25,8 @@ module DeepTest
|
|
24
25
|
#
|
25
26
|
@demons_semaphore.unlock if @demons_semaphore.locked?
|
26
27
|
|
27
|
-
|
28
|
-
|
29
|
-
rescue Exception => e
|
30
|
-
DeepTest.logger.debug "Exception in #{name} (#{Process.pid}): #{e.message}"
|
31
|
-
raise
|
32
|
-
end
|
28
|
+
close_open_network_connections
|
29
|
+
demon.forked name, @options, demon_args
|
33
30
|
|
34
31
|
exit
|
35
32
|
end
|
@@ -46,14 +43,23 @@ module DeepTest
|
|
46
43
|
end
|
47
44
|
end
|
48
45
|
|
46
|
+
def close_open_network_connections
|
47
|
+
ObjectSpace.each_object(BasicSocket) do |sock|
|
48
|
+
begin
|
49
|
+
sock.close
|
50
|
+
rescue IOError
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
49
55
|
def demon_count
|
50
56
|
@demons_semaphore.synchronize do
|
51
57
|
@demons.size
|
52
58
|
end
|
53
59
|
end
|
54
60
|
|
55
|
-
def
|
56
|
-
DeepTest.logger.debug
|
61
|
+
def stop_demons
|
62
|
+
DeepTest.logger.debug { "stopping all demons" }
|
57
63
|
receivers = @demons_semaphore.synchronize do
|
58
64
|
@demons.reverse
|
59
65
|
end
|
@@ -61,25 +67,31 @@ module DeepTest
|
|
61
67
|
receivers.reverse.each do |demon|
|
62
68
|
name, pid = demon
|
63
69
|
if running?(pid)
|
64
|
-
DeepTest.logger.debug
|
70
|
+
DeepTest.logger.debug { "Sending SIGTERM to #{name}, #{pid}" }
|
65
71
|
Process.kill("TERM", pid)
|
66
72
|
end
|
67
73
|
end
|
68
|
-
DeepTest.logger.debug
|
74
|
+
DeepTest.logger.debug { "Warlock: Stopped all receivers" }
|
69
75
|
|
70
|
-
DeepTest.logger.debug
|
76
|
+
DeepTest.logger.debug { "waiting for reapers" }
|
71
77
|
@reapers.each {|r| r.join}
|
72
78
|
|
73
|
-
DeepTest.logger.debug
|
79
|
+
DeepTest.logger.debug { "Warlock: done reaping processes" }
|
74
80
|
end
|
75
81
|
|
76
82
|
def exit_when_none_running
|
77
83
|
Thread.new do
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
84
|
+
wait_for_all_to_finish
|
85
|
+
DeepTest.logger.debug { "exiting #{Process.pid} with all demons finished" }
|
86
|
+
exit(0)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def wait_for_all_to_finish
|
91
|
+
loop do
|
92
|
+
Thread.pass
|
93
|
+
return unless any_running?
|
94
|
+
sleep(0.01)
|
83
95
|
end
|
84
96
|
end
|
85
97
|
|
@@ -110,22 +122,22 @@ module DeepTest
|
|
110
122
|
protected
|
111
123
|
|
112
124
|
def add_demon(name, pid)
|
113
|
-
DeepTest.logger.debug "Started: #{name} (#{pid})"
|
125
|
+
DeepTest.logger.debug { "Started: #{name} (#{pid})" }
|
114
126
|
@demons << [name, pid]
|
115
127
|
end
|
116
128
|
|
117
129
|
def remove_demon(name, pid)
|
118
130
|
@demons.delete [name, pid]
|
119
|
-
DeepTest.logger.debug "Stopped: #{name} (#{pid})"
|
131
|
+
DeepTest.logger.debug { "Stopped: #{name} (#{pid})" }
|
120
132
|
end
|
121
133
|
|
122
134
|
|
123
135
|
def launch_reaper_thread(name, pid)
|
124
136
|
@reapers << Thread.new do
|
125
137
|
Process.detach(pid).join
|
126
|
-
DeepTest.logger.debug
|
138
|
+
DeepTest.logger.debug { "#{name} (#{pid}) reaped" }
|
127
139
|
@demons_semaphore.synchronize do
|
128
|
-
DeepTest.logger.debug
|
140
|
+
DeepTest.logger.debug { "Warlock Reaper: removing #{name} (#{pid}) from demon list" }
|
129
141
|
remove_demon name, pid
|
130
142
|
end
|
131
143
|
end
|