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/TODO
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
2.0.0
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module DynamicTeardown
|
2
|
+
class <<self
|
3
|
+
def setup
|
4
|
+
stack.push []
|
5
|
+
end
|
6
|
+
|
7
|
+
def stack
|
8
|
+
@stack ||= []
|
9
|
+
end
|
10
|
+
|
11
|
+
def on_teardown(&block)
|
12
|
+
stack.last << block
|
13
|
+
end
|
14
|
+
|
15
|
+
def teardown
|
16
|
+
teardowns = stack.pop
|
17
|
+
while td = teardowns.shift
|
18
|
+
td.call rescue nil
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
File without changes
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/timewarp/lib/timewarp"
|
2
|
+
require File.dirname(__FILE__) + "/fake_deadlock_error"
|
3
|
+
require File.dirname(__FILE__) + "/test_central_command"
|
4
|
+
require File.dirname(__FILE__) + "/test_factory"
|
5
|
+
require File.dirname(__FILE__) + "/test_logger"
|
6
|
+
require File.dirname(__FILE__) + "/test_exception"
|
7
|
+
require File.dirname(__FILE__) + "/test_result"
|
8
|
+
require File.dirname(__FILE__) + "/test_operator"
|
9
|
+
require File.dirname(__FILE__) + "/dynamic_teardown"
|
10
|
+
require File.dirname(__FILE__) + "/thread_agent"
|
11
|
+
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module DeepTest
|
2
|
+
class TestCentralCommand < CentralCommand
|
3
|
+
def self.start(options)
|
4
|
+
central_command = super
|
5
|
+
DynamicTeardown.on_teardown { central_command.stop }
|
6
|
+
central_command
|
7
|
+
end
|
8
|
+
|
9
|
+
def remaining_result_count
|
10
|
+
@results_mutex.synchronize do
|
11
|
+
@results.size
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
File without changes
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module DeepTest
|
2
|
+
class TestOperator < Telegraph::Operator
|
3
|
+
def self.listen(options = nil)
|
4
|
+
operator = super("localhost", 0, Telegraph::Switchboard.new)
|
5
|
+
DynamicTeardown.on_teardown { operator = shutdown }
|
6
|
+
options.server_port = operator.port if options
|
7
|
+
operator
|
8
|
+
end
|
9
|
+
|
10
|
+
def next_message
|
11
|
+
@switchboard.next_message(:timeout => 0.1)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module DeepTest
|
2
|
+
class ThreadAgent < Agent
|
3
|
+
attr_reader :work_done
|
4
|
+
|
5
|
+
def initialize(options)
|
6
|
+
super(0, options, ListenerList.new([]))
|
7
|
+
@thread = Thread.new { execute(StringIO.new, StringIO.new) }
|
8
|
+
@work_done = 0
|
9
|
+
end
|
10
|
+
|
11
|
+
def wait_until_done
|
12
|
+
Timeout.timeout(5) {@thread.join}
|
13
|
+
@thread.kill if @thread.alive?
|
14
|
+
end
|
15
|
+
|
16
|
+
def send_result(*args)
|
17
|
+
super
|
18
|
+
@work_done += 1
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'time'
|
2
|
+
|
3
|
+
module Timewarp
|
4
|
+
def self.freeze(time, &block)
|
5
|
+
frozen_time = time.is_a?(String) ? Time.parse(time) : time
|
6
|
+
control_timeline proc {frozen_time}, &block
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.control_timeline(timeline_proc)
|
10
|
+
(class <<Time; self; end).class_eval do
|
11
|
+
alias original_now now
|
12
|
+
define_method(:now) { timeline_proc.call }
|
13
|
+
end
|
14
|
+
yield
|
15
|
+
ensure
|
16
|
+
(class <<Time; self; end).class_eval do
|
17
|
+
alias now original_now
|
18
|
+
remove_method :original_now
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
$LOAD_PATH << File.dirname(__FILE__) + "/../lib"
|
2
|
+
require 'test/unit'
|
3
|
+
require 'timewarp'
|
4
|
+
require 'rubygems'
|
5
|
+
require 'shoulda'
|
6
|
+
|
7
|
+
class TimewarpTest < Test::Unit::TestCase
|
8
|
+
context "control_timeline" do
|
9
|
+
should "yield" do
|
10
|
+
assert_equal :foo, Timewarp.control_timeline(proc {}) {:foo}
|
11
|
+
end
|
12
|
+
|
13
|
+
should "repeatedly call supplied proc every time Time.now is called" do
|
14
|
+
time_values = [:timepoint_1, :timepoint_2]
|
15
|
+
Timewarp.control_timeline(proc {time_values.shift}) do
|
16
|
+
assert_equal :timepoint_1, Time.now
|
17
|
+
assert_equal :timepoint_2, Time.now
|
18
|
+
assert_equal nil, Time.now
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
should "restorte the normal flow of time even if exception occurs" do
|
23
|
+
Timewarp.control_timeline(proc {}) {raise "error"} rescue nil
|
24
|
+
time_1 = Time.now
|
25
|
+
sleep 0.01
|
26
|
+
time_2 = Time.now
|
27
|
+
|
28
|
+
assert time_1 < time_2
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context "freeze" do
|
33
|
+
should "yield" do
|
34
|
+
assert_equal :foo, Timewarp.freeze(:frozen_time) {:foo}
|
35
|
+
end
|
36
|
+
|
37
|
+
should "return a constant time" do
|
38
|
+
assert_equal :frozen_time, Timewarp.freeze(:frozen_time) {Time.now}
|
39
|
+
end
|
40
|
+
|
41
|
+
should "parse the time if it is a string" do
|
42
|
+
assert_equal Time.parse("2009-07-01 12:01:01"), Timewarp.freeze("2009-07-01 12:01:01") {Time.now}
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
data/lib/deep_test.rb
CHANGED
@@ -3,27 +3,15 @@ module DeepTest
|
|
3
3
|
def logger
|
4
4
|
@logger ||= DeepTest::Logger.new($stdout)
|
5
5
|
end
|
6
|
-
end
|
7
|
-
|
8
|
-
# Fork in a separate thread. If we fork from a DRb thread
|
9
|
-
# (a thread handling a method call invoked over drb),
|
10
|
-
# DRb still thinks the current object is the DRb Front Object,
|
11
|
-
# and reports its uri as the same as in the parent process, even
|
12
|
-
# if you restart DRb service.
|
13
|
-
#
|
14
|
-
def self.drb_safe_fork(&block)
|
15
|
-
Thread.new {Process.fork(&block)}.value
|
16
|
-
end
|
17
6
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
end
|
7
|
+
def logger=(logger)
|
8
|
+
@logger = logger
|
9
|
+
end
|
10
|
+
end
|
23
11
|
|
24
|
-
class
|
25
|
-
def initialize
|
26
|
-
super "
|
12
|
+
class IncompleteTestRunError < StandardError
|
13
|
+
def initialize(count)
|
14
|
+
super "#{count} tests were not run because the DeepTest Agents died"
|
27
15
|
end
|
28
16
|
|
29
17
|
def backtrace
|
@@ -33,53 +21,52 @@ module DeepTest
|
|
33
21
|
end
|
34
22
|
|
35
23
|
require "logger"
|
36
|
-
require "drb"
|
37
24
|
require "timeout"
|
38
25
|
require "thread"
|
39
26
|
require "socket"
|
40
27
|
require "webrick"
|
41
28
|
require "timeout"
|
29
|
+
require "base64"
|
42
30
|
|
31
|
+
require File.dirname(__FILE__) + "/telegraph"
|
32
|
+
require File.dirname(__FILE__) + "/deep_test/lib_root"
|
43
33
|
require File.dirname(__FILE__) + "/deep_test/extensions/object_extension"
|
44
|
-
require File.dirname(__FILE__) + "/deep_test/extensions/drb_extension"
|
45
34
|
|
35
|
+
require File.dirname(__FILE__) + "/deep_test/demon"
|
46
36
|
require File.dirname(__FILE__) + "/deep_test/deadlock_detector"
|
47
|
-
require File.dirname(__FILE__) + "/deep_test/
|
37
|
+
require File.dirname(__FILE__) + "/deep_test/local_deployment"
|
48
38
|
require File.dirname(__FILE__) + "/deep_test/logger"
|
49
39
|
|
50
40
|
require File.dirname(__FILE__) + "/deep_test/marshallable_exception_wrapper"
|
51
|
-
require File.dirname(__FILE__) + "/deep_test/
|
41
|
+
require File.dirname(__FILE__) + "/deep_test/null_listener"
|
52
42
|
require File.dirname(__FILE__) + "/deep_test/listener_list"
|
53
|
-
require File.dirname(__FILE__) + "/deep_test/
|
43
|
+
require File.dirname(__FILE__) + "/deep_test/cpu_info"
|
44
|
+
require File.dirname(__FILE__) + "/deep_test/failure_message"
|
54
45
|
require File.dirname(__FILE__) + "/deep_test/options"
|
55
|
-
require File.dirname(__FILE__) + "/deep_test/
|
46
|
+
require File.dirname(__FILE__) + "/deep_test/main"
|
56
47
|
require File.dirname(__FILE__) + "/deep_test/result_reader"
|
57
48
|
require File.dirname(__FILE__) + "/deep_test/rspec_detector"
|
58
|
-
require File.dirname(__FILE__) + "/deep_test/
|
49
|
+
require File.dirname(__FILE__) + "/deep_test/central_command"
|
50
|
+
require File.dirname(__FILE__) + "/deep_test/proxy_io"
|
59
51
|
require File.dirname(__FILE__) + "/deep_test/test_task"
|
60
|
-
require File.dirname(__FILE__) + "/deep_test/
|
52
|
+
require File.dirname(__FILE__) + "/deep_test/agent"
|
61
53
|
require File.dirname(__FILE__) + "/deep_test/warlock"
|
62
54
|
|
63
55
|
require File.dirname(__FILE__) + "/deep_test/database/setup_listener"
|
64
56
|
require File.dirname(__FILE__) + "/deep_test/database/mysql_setup_listener"
|
65
57
|
|
58
|
+
require File.dirname(__FILE__) + "/deep_test/distributed/shell_environment"
|
59
|
+
require File.dirname(__FILE__) + "/deep_test/distributed/landing_ship"
|
66
60
|
require File.dirname(__FILE__) + "/deep_test/distributed/dispatch_controller"
|
67
|
-
require File.dirname(__FILE__) + "/deep_test/distributed/
|
61
|
+
require File.dirname(__FILE__) + "/deep_test/distributed/ssh_client_connection_info"
|
68
62
|
require File.dirname(__FILE__) + "/deep_test/distributed/filename_resolver"
|
69
|
-
require File.dirname(__FILE__) + "/deep_test/distributed/
|
70
|
-
require File.dirname(__FILE__) + "/deep_test/distributed/
|
71
|
-
require File.dirname(__FILE__) + "/deep_test/distributed/
|
72
|
-
require File.dirname(__FILE__) + "/deep_test/distributed/test_server_workers"
|
73
|
-
require File.dirname(__FILE__) + "/deep_test/distributed/multi_test_server_proxy"
|
74
|
-
require File.dirname(__FILE__) + "/deep_test/distributed/null_work_unit"
|
75
|
-
require File.dirname(__FILE__) + "/deep_test/distributed/remote_worker_client"
|
76
|
-
require File.dirname(__FILE__) + "/deep_test/distributed/remote_worker_server"
|
63
|
+
require File.dirname(__FILE__) + "/deep_test/distributed/landing_fleet"
|
64
|
+
require File.dirname(__FILE__) + "/deep_test/distributed/remote_deployment"
|
65
|
+
require File.dirname(__FILE__) + "/deep_test/distributed/beachhead"
|
77
66
|
require File.dirname(__FILE__) + "/deep_test/distributed/rsync"
|
78
|
-
require File.dirname(__FILE__) + "/deep_test/distributed/throughput_runner"
|
79
|
-
require File.dirname(__FILE__) + "/deep_test/distributed/throughput_statistics"
|
80
|
-
require File.dirname(__FILE__) + "/deep_test/distributed/throughput_worker_client"
|
81
67
|
|
82
|
-
require File.dirname(__FILE__) + "/deep_test/metrics/
|
68
|
+
require File.dirname(__FILE__) + "/deep_test/metrics/data"
|
69
|
+
require File.dirname(__FILE__) + "/deep_test/metrics/measurement"
|
83
70
|
|
84
71
|
DeepTest::RSpecDetector.if_rspec_available do
|
85
72
|
require File.dirname(__FILE__) + "/deep_test/spec"
|
@@ -88,3 +75,4 @@ require File.dirname(__FILE__) + "/deep_test/test"
|
|
88
75
|
|
89
76
|
require File.dirname(__FILE__) + "/deep_test/ui/console"
|
90
77
|
require File.dirname(__FILE__) + "/deep_test/ui/null"
|
78
|
+
|
@@ -0,0 +1,108 @@
|
|
1
|
+
module DeepTest
|
2
|
+
class Agent
|
3
|
+
include Demon
|
4
|
+
attr_reader :number
|
5
|
+
|
6
|
+
def initialize(number, options, listener)
|
7
|
+
@number = number
|
8
|
+
@listener = listener
|
9
|
+
@options = options
|
10
|
+
end
|
11
|
+
|
12
|
+
def connect(stream_to_parent_process)
|
13
|
+
DeepTest.logger.debug { "Agent: Connecting to #{@options.origin_hostname}:#{@options.server_port}" }
|
14
|
+
@options.connect_to_central_command do |wire|
|
15
|
+
stream_to_parent_process.puts "Connected"
|
16
|
+
stream_to_parent_process.close rescue nil
|
17
|
+
yield wire
|
18
|
+
end
|
19
|
+
ensure
|
20
|
+
stream_to_parent_process.close unless stream_to_parent_process.closed?
|
21
|
+
end
|
22
|
+
|
23
|
+
def execute(stream_from_child_process, stream_to_parent_process)
|
24
|
+
stream_from_child_process.close
|
25
|
+
connect(stream_to_parent_process) do |wire|
|
26
|
+
reseed_random_numbers
|
27
|
+
reconnect_to_database
|
28
|
+
|
29
|
+
@listener.starting(self)
|
30
|
+
wire.send_message CentralCommand::NeedWork
|
31
|
+
|
32
|
+
while work_unit_message = next_work_unit_message(wire)
|
33
|
+
@listener.starting_work(self, work_unit_message.body)
|
34
|
+
|
35
|
+
result = begin
|
36
|
+
Metrics::Measurement.send_home("Agents Performing Work", wire, @options) do
|
37
|
+
work_unit_message.body.run
|
38
|
+
end
|
39
|
+
rescue Exception => error
|
40
|
+
Error.new(work_unit_message.body, error)
|
41
|
+
end
|
42
|
+
|
43
|
+
@listener.finished_work(self, work_unit_message.body, result)
|
44
|
+
send_result wire, work_unit_message, result
|
45
|
+
end
|
46
|
+
end
|
47
|
+
rescue CentralCommand::NoWorkUnitsRemainingError
|
48
|
+
DeepTest.logger.debug { "Agent #{number}: no more work to do" }
|
49
|
+
end
|
50
|
+
|
51
|
+
def next_work_unit_message(wire)
|
52
|
+
Metrics::Measurement.send_home("Agents Retrieving Work", wire, @options) do
|
53
|
+
begin
|
54
|
+
message = wire.next_message(:timeout => 2)
|
55
|
+
next message.body == CentralCommand::NoMoreWork ? nil : message
|
56
|
+
rescue Telegraph::NoMessageAvailable
|
57
|
+
DeepTest.logger.debug { "Agent: NoMessageAvailable" }
|
58
|
+
retry
|
59
|
+
rescue Telegraph::LineDead
|
60
|
+
DeepTest.logger.debug { "Agent: LineDead" }
|
61
|
+
next nil
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def send_result(wire, work_unit_message, result)
|
67
|
+
wire.send_message result, :ack => work_unit_message
|
68
|
+
end
|
69
|
+
|
70
|
+
def reconnect_to_database
|
71
|
+
ActiveRecord::Base.connection.reconnect! if defined?(ActiveRecord::Base)
|
72
|
+
end
|
73
|
+
|
74
|
+
def reseed_random_numbers
|
75
|
+
srand
|
76
|
+
end
|
77
|
+
|
78
|
+
|
79
|
+
class Error
|
80
|
+
include CentralCommand::Result
|
81
|
+
|
82
|
+
attr_accessor :work_unit, :error
|
83
|
+
|
84
|
+
def initialize(work_unit, error)
|
85
|
+
@work_unit, @error = work_unit, error
|
86
|
+
end
|
87
|
+
|
88
|
+
def _dump(limit)
|
89
|
+
Marshal.dump([@work_unit, @error], limit)
|
90
|
+
rescue
|
91
|
+
Marshal.dump(["<< Undumpable >>", @error], limit)
|
92
|
+
end
|
93
|
+
|
94
|
+
def self._load(string)
|
95
|
+
new *Marshal.load(string)
|
96
|
+
end
|
97
|
+
|
98
|
+
def ==(other)
|
99
|
+
work_unit == other.work_unit &&
|
100
|
+
error == other.error
|
101
|
+
end
|
102
|
+
|
103
|
+
def to_s
|
104
|
+
"#{@work_unit}: #{@error}\n" + (@error.backtrace || []).join("\n")
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|