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
@@ -1,20 +1,22 @@
|
|
1
1
|
require File.dirname(__FILE__) + "/../test_helper"
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
3
|
+
module DeepTest
|
4
|
+
unit_tests do
|
5
|
+
test "forwards methods defined in NullListener to all listeners" do
|
6
|
+
listener_1, listener_2 = mock, mock
|
7
|
+
list = ListenerList.new([listener_1, listener_2])
|
8
|
+
listener_1.expects(:starting).with(:agent)
|
9
|
+
listener_2.expects(:starting).with(:agent)
|
10
|
+
listener_1.expects(:starting_work).with(:agent, :work)
|
11
|
+
listener_2.expects(:starting_work).with(:agent, :work)
|
12
|
+
list.starting(:agent)
|
13
|
+
list.starting_work(:agent, :work)
|
14
|
+
end
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
16
|
+
test "doesn't forward methods not defined in NullListener" do
|
17
|
+
listener = mock
|
18
|
+
listener.expects(:to_s).never
|
19
|
+
ListenerList.new([listener]).to_s
|
20
|
+
end
|
19
21
|
end
|
20
22
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/../test_helper"
|
2
|
+
|
3
|
+
module DeepTest
|
4
|
+
unit_tests do
|
5
|
+
test "number_of_agents is determined by options" do
|
6
|
+
deployment = LocalDeployment.new Options.new(:number_of_agents => 4)
|
7
|
+
assert_equal 4, deployment.number_of_agents
|
8
|
+
end
|
9
|
+
|
10
|
+
test "load_files simply loads each file provided" do
|
11
|
+
deployment = LocalDeployment.new Options.new({})
|
12
|
+
|
13
|
+
deployment.expects(:load).with(:file_1)
|
14
|
+
deployment.expects(:load).with(:file_2)
|
15
|
+
|
16
|
+
deployment.load_files([:file_1, :file_2])
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -1,11 +1,38 @@
|
|
1
1
|
require File.dirname(__FILE__) + "/../test_helper"
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
3
|
+
module DeepTest
|
4
|
+
unit_tests do
|
5
|
+
test "info log level by default" do
|
6
|
+
assert_equal Logger::INFO, DeepTest.logger.level
|
7
|
+
end
|
8
|
+
|
9
|
+
test "formatter uses msg only" do
|
10
|
+
time = Time.parse("2009-09-22 12:01:33")
|
11
|
+
assert_equal "[DeepTest@#{Socket.gethostname}] 2009-09-22 12:01:33 my_msg\n", DeepTest.logger.formatter.call(nil, time, nil, "my_msg")
|
12
|
+
end
|
13
|
+
|
14
|
+
Logger::Severity.constants.each do |severity|
|
15
|
+
test "#{severity.downcase} can not be called with any arguments" do
|
16
|
+
logger = Logger.new stub_everything
|
17
|
+
assert_raises(ArgumentError) { logger.send severity.downcase, "a" }
|
18
|
+
end
|
19
|
+
|
20
|
+
THE_DATE = '\d{4}-\d\d-\d\d \d\d:\d\d:\d\d' unless defined?(THE_DATE)
|
21
|
+
|
22
|
+
test "#{severity.downcase} can be called with a block" do
|
23
|
+
logger = Logger.new(out = StringIO.new)
|
24
|
+
logger.level = Logger.const_get(severity)
|
25
|
+
logger.send(severity.downcase) { "a" }
|
26
|
+
assert_match /\[DeepTest@#{Socket.gethostname}\] #{THE_DATE} a\n/, out.string
|
27
|
+
end
|
28
|
+
|
29
|
+
test "#{severity.downcase} rescues errors from block and logs them" do
|
30
|
+
logger = Logger.new(out = StringIO.new)
|
31
|
+
logger.level = Logger.const_get(severity)
|
32
|
+
logger.send(severity.downcase) { raise Exception, "e" }
|
33
|
+
assert_match /\[DeepTest@#{Socket.gethostname}\] #{THE_DATE} Exception: e occurred logging on #{__FILE__}:#{__LINE__ - 1}:in `send'\n/,
|
34
|
+
out.string
|
35
|
+
end
|
36
|
+
end
|
10
37
|
end
|
11
38
|
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/../test_helper"
|
2
|
+
|
3
|
+
module DeepTest
|
4
|
+
unit_tests do
|
5
|
+
test "shutdown calls done_with_work" do
|
6
|
+
main = Main.new(nil, stub_everything, nil, central_command = mock)
|
7
|
+
central_command.expects(:done_with_work)
|
8
|
+
|
9
|
+
main.shutdown
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -1,44 +1,46 @@
|
|
1
1
|
require File.dirname(__FILE__) + "/../test_helper"
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
3
|
+
module DeepTest
|
4
|
+
unit_tests do
|
5
|
+
test "loading a marshallable exception evals the classname and returns an instance of the original exception" do
|
6
|
+
original = RuntimeError.new "message"
|
7
|
+
original.set_backtrace ['1', '2']
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
|
9
|
+
marshalled = MarshallableExceptionWrapper.new(original)
|
10
|
+
MarshallableExceptionWrapper.any_instance.expects(:eval).
|
11
|
+
with("::RuntimeError").returns(RuntimeError)
|
11
12
|
|
12
|
-
|
13
|
+
loaded = Marshal.load(Marshal.dump(marshalled)).resolve
|
13
14
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
15
|
+
assert_equal original.class, loaded.class
|
16
|
+
assert_equal original.message, loaded.message
|
17
|
+
assert_equal original.backtrace, loaded.backtrace
|
18
|
+
end
|
18
19
|
|
19
|
-
|
20
|
-
|
21
|
-
|
20
|
+
test "loading a marshallable exception when class is not available returns an instance of unloadable exception" do
|
21
|
+
original = RuntimeError.new "message"
|
22
|
+
original.set_backtrace ['1', '2']
|
22
23
|
|
23
|
-
|
24
|
-
|
25
|
-
|
24
|
+
marshalled = MarshallableExceptionWrapper.new(original)
|
25
|
+
MarshallableExceptionWrapper.any_instance.expects(:eval).
|
26
|
+
raises("Eval Error")
|
26
27
|
|
27
|
-
|
28
|
+
loaded = Marshal.load(Marshal.dump(marshalled)).resolve
|
28
29
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
30
|
+
assert_equal UnloadableException, loaded.class
|
31
|
+
assert_equal "RuntimeError: " + original.message, loaded.message
|
32
|
+
assert_equal original.backtrace, loaded.backtrace
|
33
|
+
end
|
33
34
|
|
34
|
-
|
35
|
-
|
35
|
+
test "loading a marshallable exception when class init throws an error returns an unloadable exception" do
|
36
|
+
original = RuntimeError.new "message"
|
36
37
|
|
37
|
-
|
38
|
-
|
38
|
+
marshalled = MarshallableExceptionWrapper.new(original)
|
39
|
+
RuntimeError.expects(:new).raises(StandardError.new)
|
39
40
|
|
40
|
-
|
41
|
+
loaded = Marshal.load(Marshal.dump(marshalled)).resolve
|
41
42
|
|
42
|
-
|
43
|
+
assert_equal UnloadableException, loaded.class
|
44
|
+
end
|
43
45
|
end
|
44
46
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/../../test_helper"
|
2
|
+
|
3
|
+
module DeepTest
|
4
|
+
module Metrics
|
5
|
+
class DataTest < ::Test::Unit::TestCase
|
6
|
+
test "measurements are summarized in report" do
|
7
|
+
data = Data.new
|
8
|
+
data.add Measurement.new("category a", 1, "bytes")
|
9
|
+
data.add Measurement.new("category b", 2, "seconds")
|
10
|
+
data.add Measurement.new("category a", 2, "bytes")
|
11
|
+
data.add Measurement.new("category b", 3, "seconds")
|
12
|
+
|
13
|
+
assert_equal <<-end_text, data.summary
|
14
|
+
Metrics Data
|
15
|
+
------------
|
16
|
+
category a: 1.5 avg / 3 total bytes
|
17
|
+
category b: 2.5 avg / 5 total seconds
|
18
|
+
end_text
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/../../test_helper"
|
2
|
+
|
3
|
+
module DeepTest
|
4
|
+
module Metrics
|
5
|
+
class MeasurementTest < ::Test::Unit::TestCase
|
6
|
+
test "of_time_taken should measure time an operation takes" do
|
7
|
+
measurement = Measurement.of_time_taken("category") do
|
8
|
+
sleep 0.5
|
9
|
+
end
|
10
|
+
|
11
|
+
assert_equal "category", measurement.category
|
12
|
+
assert_in_delta 0.5, measurement.value, 0.1
|
13
|
+
assert_equal "seconds", measurement.units
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
@@ -0,0 +1,104 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/../test_helper"
|
2
|
+
|
3
|
+
module DeepTest
|
4
|
+
unit_tests do
|
5
|
+
test "should write strings to proxy wire" do
|
6
|
+
io = ProxyIO.new(ProxyIO::Stdout, wire = mock)
|
7
|
+
wire.expects(:send_message).with ProxyIO::Stdout::Output.new("my_string")
|
8
|
+
io.write "my_string"
|
9
|
+
end
|
10
|
+
|
11
|
+
test "should call to_s on any received objects" do
|
12
|
+
io = ProxyIO.new(ProxyIO::Stdout, wire = mock)
|
13
|
+
wire.expects(:send_message).with ProxyIO::Stdout::Output.new("some value")
|
14
|
+
io.write mock(:to_s => "some value")
|
15
|
+
end
|
16
|
+
|
17
|
+
test "should clear string buffer after forwarding to wire" do
|
18
|
+
io = ProxyIO.new(ProxyIO::Stdout, wire = mock)
|
19
|
+
wire.expects(:send_message).with ProxyIO::Stdout::Output.new("string 1")
|
20
|
+
wire.expects(:send_message).with ProxyIO::Stdout::Output.new("string 2")
|
21
|
+
io.write "string 1"
|
22
|
+
io.write "string 2"
|
23
|
+
end
|
24
|
+
|
25
|
+
test "should forward flush to the wire" do
|
26
|
+
io = ProxyIO.new(ProxyIO::Stdout, wire = mock)
|
27
|
+
wire.expects(:send_message).with kind_of(ProxyIO::Stdout::Flush)
|
28
|
+
io.flush
|
29
|
+
end
|
30
|
+
|
31
|
+
test "Stdout::Output prints to stdout" do
|
32
|
+
output = ProxyIO::Stdout::Output.new("output")
|
33
|
+
assert_equal "output", capture_stdout { output.execute }
|
34
|
+
end
|
35
|
+
|
36
|
+
test "Stderr::Output prints to stdout" do
|
37
|
+
output = ProxyIO::Stderr::Output.new("output")
|
38
|
+
assert_equal "output", capture_stderr { output.execute }
|
39
|
+
end
|
40
|
+
|
41
|
+
test "Stdout::Flush prints to stdout" do
|
42
|
+
output = ProxyIO::Stdout::Flush.new
|
43
|
+
$stdout.expects :flush
|
44
|
+
output.execute
|
45
|
+
end
|
46
|
+
|
47
|
+
test "Stderr::Flush prints to stdout" do
|
48
|
+
output = ProxyIO::Stderr::Flush.new
|
49
|
+
$stderr.expects :flush
|
50
|
+
output.execute
|
51
|
+
end
|
52
|
+
|
53
|
+
test "replace_stdout_stderr! yields" do
|
54
|
+
yielded = false
|
55
|
+
ProxyIO.replace_stdout_stderr!(mock) { yielded = true }
|
56
|
+
assert yielded, "didn't yield"
|
57
|
+
end
|
58
|
+
|
59
|
+
test "will replace stdout with proxy to wire" do
|
60
|
+
ProxyIO.replace_stdout_stderr!(wire = mock) do
|
61
|
+
wire.expects(:send_message).with ProxyIO::Stdout::Output.new("global string")
|
62
|
+
wire.expects(:send_message).with ProxyIO::Stdout::Output.new("const string")
|
63
|
+
$stdout.write "global string"
|
64
|
+
STDOUT.write "const string"
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
test "will restore stdout after yielding" do
|
69
|
+
old_stdout_global, old_stdout_const = $stdout, STDOUT
|
70
|
+
ProxyIO.replace_stdout_stderr!(mock) { raise "error" } rescue nil
|
71
|
+
assert_equal old_stdout_global, $stdout
|
72
|
+
assert_equal old_stdout_const, STDOUT
|
73
|
+
end
|
74
|
+
|
75
|
+
test "will replace stderr with proxy to wire" do
|
76
|
+
ProxyIO.replace_stdout_stderr!(wire = mock) do
|
77
|
+
wire.expects(:send_message).with ProxyIO::Stderr::Output.new("global string")
|
78
|
+
wire.expects(:send_message).with ProxyIO::Stderr::Output.new("const string")
|
79
|
+
$stderr.write "global string"
|
80
|
+
STDERR.write "const string"
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
test "will restore stderr after yielding" do
|
85
|
+
old_stderr_global, old_stderr_const = $stderr, STDERR
|
86
|
+
ProxyIO.replace_stdout_stderr!(mock) { raise "error" } rescue nil
|
87
|
+
assert_equal old_stderr_global, $stderr
|
88
|
+
assert_equal old_stderr_const, STDERR
|
89
|
+
end
|
90
|
+
|
91
|
+
test "reconnect the logger to the new stdout" do
|
92
|
+
old_stderr_global, old_stderr_const = $stderr, STDERR
|
93
|
+
ProxyIO.replace_stdout_stderr!(mock) do
|
94
|
+
assert_equal $stdout, DeepTest.logger.io_stream
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
test "supress warnings restores verbose" do
|
99
|
+
old_verbose = $VERBOSE
|
100
|
+
ProxyIO.supress_warnings { raise "error" } rescue nil
|
101
|
+
assert_equal old_verbose, $VERBOSE
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
@@ -1,128 +1,128 @@
|
|
1
1
|
require File.dirname(__FILE__) + "/../test_helper"
|
2
2
|
|
3
|
-
|
3
|
+
module DeepTest
|
4
|
+
unit_tests do
|
5
|
+
class FakeResult
|
6
|
+
attr_reader :identifier
|
7
|
+
def initialize(i) @identifier = i; end
|
8
|
+
def ==(other) identifier == other.identifier; end
|
9
|
+
end
|
4
10
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
11
|
+
test "reads all as many results as requested" do
|
12
|
+
central_command = TestCentralCommand.start Options.new({})
|
13
|
+
1.upto(4) {|i| central_command.write_result FakeResult.new(i)}
|
14
|
+
work_units = {1 => "One", 2 => "Two", 3 => "Three"}
|
15
|
+
ResultReader.new(central_command).read(work_units) {}
|
16
|
+
assert_equal FakeResult.new(4), central_command.take_result
|
17
|
+
end
|
10
18
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
19
|
+
test "returns unread tests on NoAgentsRunningError" do
|
20
|
+
central_command = TestCentralCommand.start Options.new({})
|
21
|
+
work_units = {1 => "One"}
|
22
|
+
FailureMessage.expects(:show)
|
23
|
+
ResultReader.new(central_command).read(work_units) {}
|
24
|
+
assert_equal({1 => "One"}, work_units)
|
25
|
+
end
|
18
26
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
+
test "yields each result" do
|
28
|
+
central_command = TestCentralCommand.start Options.new({})
|
29
|
+
1.upto(3) {|i| central_command.write_result FakeResult.new(i)}
|
30
|
+
results = []
|
31
|
+
work_units = {1 => "One", 2 => "Two", 3 => "Three"}
|
32
|
+
ResultReader.new(central_command).read(work_units) {|r| results << r}
|
33
|
+
assert_equal [["One", FakeResult.new(1)],
|
34
|
+
["Two", FakeResult.new(2)],
|
35
|
+
["Three", FakeResult.new(3)]],
|
36
|
+
results
|
37
|
+
end
|
27
38
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
["Three", FakeResult.new(3)]],
|
37
|
-
results
|
38
|
-
end
|
39
|
+
test "keeps attempting to read results when none are available" do
|
40
|
+
central_command = TestCentralCommand.start Options.new({})
|
41
|
+
work_units = {1 => "One", 2 => "Two", 3 => "Three"}
|
42
|
+
t = Thread.new {ResultReader.new(central_command).read(work_units) {}}
|
43
|
+
1.upto(4) {|i| central_command.write_result FakeResult.new(i)}
|
44
|
+
t.join
|
45
|
+
assert_equal FakeResult.new(4), central_command.take_result
|
46
|
+
end
|
39
47
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
+
test "doesn't yield empty results" do
|
49
|
+
central_command = TestCentralCommand.start Options.new({})
|
50
|
+
results = []
|
51
|
+
t = Thread.new {ResultReader.new(central_command).read(1 => "One") {|r| results << r}}
|
52
|
+
central_command.write_result FakeResult.new(1)
|
53
|
+
t.join
|
54
|
+
assert_equal [["One", FakeResult.new(1)]], results
|
55
|
+
end
|
48
56
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
t = Thread.new {DeepTest::ResultReader.new(blackboard).read(1 => "One") {|r| results << r}}
|
53
|
-
blackboard.write_result FakeResult.new(1)
|
54
|
-
t.join
|
55
|
-
assert_equal [["One", FakeResult.new(1)]], results
|
56
|
-
end
|
57
|
+
test "prints output if result has output" do
|
58
|
+
central_command = TestCentralCommand.start Options.new({})
|
59
|
+
central_command.write_result mock(:output => "output", :identifier => 1)
|
57
60
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
+
out = capture_stdout do
|
62
|
+
ResultReader.new(central_command).read(1 => "One") {}
|
63
|
+
end
|
61
64
|
|
62
|
-
|
63
|
-
DeepTest::ResultReader.new(blackboard).read(1 => "One") {}
|
65
|
+
assert_equal "output", out
|
64
66
|
end
|
65
67
|
|
66
|
-
|
67
|
-
|
68
|
+
test "doesn't print any output if output is nil" do
|
69
|
+
central_command = TestCentralCommand.start Options.new({})
|
70
|
+
central_command.write_result mock(:output => nil, :identifier => 1)
|
68
71
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
+
out = capture_stdout do
|
73
|
+
ResultReader.new(central_command).read(1 => "One") {}
|
74
|
+
end
|
72
75
|
|
73
|
-
|
74
|
-
DeepTest::ResultReader.new(blackboard).read(1 => "One") {}
|
76
|
+
assert_equal "", out
|
75
77
|
end
|
76
78
|
|
77
|
-
|
78
|
-
|
79
|
+
test "prints useful error information in case of Agent::Error" do
|
80
|
+
error = RuntimeError.new "message"
|
81
|
+
error.set_backtrace ['a', 'b']
|
79
82
|
|
80
|
-
|
81
|
-
|
82
|
-
error.set_backtrace ['a', 'b']
|
83
|
+
central_command = TestCentralCommand.start Options.new({})
|
84
|
+
central_command.write_result Agent::Error.new("work_unit", error)
|
83
85
|
|
84
|
-
blackboard = DeepTest::SimpleTestBlackboard.new
|
85
|
-
blackboard.write_result DeepTest::Worker::Error.new("work_unit", error)
|
86
86
|
|
87
|
+
out = capture_stdout do
|
88
|
+
ResultReader.new(central_command).read(1 => "One") {}
|
89
|
+
end
|
87
90
|
|
88
|
-
|
89
|
-
DeepTest::ResultReader.new(blackboard).read(1 => "One") {}
|
91
|
+
assert_equal "work_unit: message\na\nb\n", out
|
90
92
|
end
|
91
93
|
|
92
|
-
|
93
|
-
|
94
|
+
test "doesn't yield Agent::Error results" do
|
95
|
+
central_command = TestCentralCommand.start Options.new({})
|
96
|
+
central_command.write_result Agent::Error.new("work_unit", RuntimeError.new)
|
94
97
|
|
95
|
-
test "doesn't yield Worker::Error results" do
|
96
|
-
blackboard = DeepTest::SimpleTestBlackboard.new
|
97
|
-
blackboard.write_result DeepTest::Worker::Error.new("work_unit", RuntimeError.new)
|
98
98
|
|
99
|
+
results = []
|
100
|
+
capture_stdout do
|
101
|
+
ResultReader.new(central_command).read(1 => "One") {|r| results << r}
|
102
|
+
end
|
99
103
|
|
100
|
-
|
101
|
-
capture_stdout do
|
102
|
-
DeepTest::ResultReader.new(blackboard).read(1 => "One") {|r| results << r}
|
104
|
+
assert_equal [], results
|
103
105
|
end
|
104
106
|
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
DeepTest::ResultReader.new(blackboard).read(work_units) {}
|
113
|
-
assert_equal({1 => "One"}, work_units)
|
114
|
-
end
|
107
|
+
test "doesn't modify original work unit hash" do
|
108
|
+
central_command = TestCentralCommand.start Options.new({})
|
109
|
+
central_command.write_result FakeResult.new(1)
|
110
|
+
work_units = {1 => "One"}
|
111
|
+
ResultReader.new(central_command).read(work_units) {}
|
112
|
+
assert_equal({1 => "One"}, work_units)
|
113
|
+
end
|
115
114
|
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
115
|
+
test "returns remaining tests that didn't have errors" do
|
116
|
+
central_command = TestCentralCommand.start Options.new({})
|
117
|
+
central_command.write_result FakeResult.new(1)
|
118
|
+
central_command.write_result Agent::Error.new("work_unit", RuntimeError.new)
|
120
119
|
|
121
|
-
|
120
|
+
work_units = {1 => "One", 2 => "Two"}
|
122
121
|
|
123
|
-
|
124
|
-
|
125
|
-
|
122
|
+
capture_stdout do
|
123
|
+
missing_work_units = ResultReader.new(central_command).read(work_units) {}
|
124
|
+
assert_equal({2 => "Two"}, missing_work_units)
|
125
|
+
end
|
126
126
|
end
|
127
127
|
end
|
128
128
|
end
|