deep_test_pre 2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (98) hide show
  1. data/CHANGELOG +47 -0
  2. data/README.rdoc +199 -0
  3. data/Rakefile +137 -0
  4. data/lib/deep_test.rb +78 -0
  5. data/lib/deep_test/agent.rb +108 -0
  6. data/lib/deep_test/central_command.rb +165 -0
  7. data/lib/deep_test/cpu_info.rb +22 -0
  8. data/lib/deep_test/database/mysql_setup_listener.rb +112 -0
  9. data/lib/deep_test/database/setup_listener.rb +116 -0
  10. data/lib/deep_test/deadlock_detector.rb +7 -0
  11. data/lib/deep_test/demon.rb +25 -0
  12. data/lib/deep_test/distributed/beachhead.rb +104 -0
  13. data/lib/deep_test/distributed/dispatch_controller.rb +60 -0
  14. data/lib/deep_test/distributed/establish_beachhead.rb +19 -0
  15. data/lib/deep_test/distributed/filename_resolver.rb +40 -0
  16. data/lib/deep_test/distributed/landing_fleet.rb +30 -0
  17. data/lib/deep_test/distributed/landing_ship.rb +60 -0
  18. data/lib/deep_test/distributed/remote_deployment.rb +56 -0
  19. data/lib/deep_test/distributed/rsync.rb +50 -0
  20. data/lib/deep_test/distributed/shell_environment.rb +50 -0
  21. data/lib/deep_test/distributed/ssh_client_connection_info.rb +14 -0
  22. data/lib/deep_test/extensions/object_extension.rb +40 -0
  23. data/lib/deep_test/failure_message.rb +19 -0
  24. data/lib/deep_test/lib_root.rb +4 -0
  25. data/lib/deep_test/listener_list.rb +17 -0
  26. data/lib/deep_test/local_deployment.rb +46 -0
  27. data/lib/deep_test/logger.rb +32 -0
  28. data/lib/deep_test/main.rb +41 -0
  29. data/lib/deep_test/marshallable_exception_wrapper.rb +44 -0
  30. data/lib/deep_test/metrics/data.rb +34 -0
  31. data/lib/deep_test/metrics/measurement.rb +39 -0
  32. data/lib/deep_test/null_listener.rb +62 -0
  33. data/lib/deep_test/options.rb +113 -0
  34. data/lib/deep_test/proxy_io.rb +77 -0
  35. data/lib/deep_test/rake_tasks.rb +13 -0
  36. data/lib/deep_test/result_reader.rb +40 -0
  37. data/lib/deep_test/rspec_detector.rb +21 -0
  38. data/lib/deep_test/spec.rb +17 -0
  39. data/lib/deep_test/spec/extensions/example_group_methods.rb +64 -0
  40. data/lib/deep_test/spec/extensions/example_methods.rb +52 -0
  41. data/lib/deep_test/spec/extensions/options.rb +43 -0
  42. data/lib/deep_test/spec/extensions/spec_task.rb +21 -0
  43. data/lib/deep_test/spec/runner.rb +72 -0
  44. data/lib/deep_test/spec/work_result.rb +35 -0
  45. data/lib/deep_test/spec/work_unit.rb +59 -0
  46. data/lib/deep_test/test.rb +10 -0
  47. data/lib/deep_test/test/extensions/error.rb +14 -0
  48. data/lib/deep_test/test/run_test_suite.rb +5 -0
  49. data/lib/deep_test/test/runner.rb +24 -0
  50. data/lib/deep_test/test/supervised_test_suite.rb +48 -0
  51. data/lib/deep_test/test/work_result.rb +35 -0
  52. data/lib/deep_test/test/work_unit.rb +40 -0
  53. data/lib/deep_test/test_task.rb +47 -0
  54. data/lib/deep_test/ui/console.rb +74 -0
  55. data/lib/deep_test/ui/null.rb +17 -0
  56. data/lib/deep_test/warlock.rb +146 -0
  57. data/lib/telegraph.rb +29 -0
  58. data/lib/telegraph/ack_sequence.rb +14 -0
  59. data/lib/telegraph/logging.rb +20 -0
  60. data/lib/telegraph/message.rb +39 -0
  61. data/lib/telegraph/operator.rb +47 -0
  62. data/lib/telegraph/switchboard.rb +57 -0
  63. data/lib/telegraph/wire.rb +73 -0
  64. data/test/deep_test/agent_test.rb +175 -0
  65. data/test/deep_test/central_command_test.rb +147 -0
  66. data/test/deep_test/cpu_info_test.rb +33 -0
  67. data/test/deep_test/database/mysql_setup_listener_test.rb +18 -0
  68. data/test/deep_test/demon_test.rb +23 -0
  69. data/test/deep_test/distributed/beachhead_test.rb +67 -0
  70. data/test/deep_test/distributed/dispatch_controller_test.rb +162 -0
  71. data/test/deep_test/distributed/filename_resolver_test.rb +56 -0
  72. data/test/deep_test/distributed/landing_fleet_test.rb +55 -0
  73. data/test/deep_test/distributed/landing_ship_test.rb +48 -0
  74. data/test/deep_test/distributed/remote_deployment_test.rb +134 -0
  75. data/test/deep_test/distributed/rsync_test.rb +47 -0
  76. data/test/deep_test/distributed/shell_environment_test.rb +108 -0
  77. data/test/deep_test/distributed/ssh_client_connection_info_test.rb +34 -0
  78. data/test/deep_test/extensions/object_extension_test.rb +37 -0
  79. data/test/deep_test/listener_list_test.rb +22 -0
  80. data/test/deep_test/local_deployment_test.rb +19 -0
  81. data/test/deep_test/logger_test.rb +38 -0
  82. data/test/deep_test/main_test.rb +12 -0
  83. data/test/deep_test/marshallable_exception_wrapper_test.rb +46 -0
  84. data/test/deep_test/metrics/data_test.rb +22 -0
  85. data/test/deep_test/metrics/measurement_test.rb +18 -0
  86. data/test/deep_test/proxy_io_test.rb +104 -0
  87. data/test/deep_test/result_reader_test.rb +128 -0
  88. data/test/deep_test/test/extensions/error_test.rb +42 -0
  89. data/test/deep_test/test/runner_test.rb +11 -0
  90. data/test/deep_test/test/supervised_test_suite_test.rb +107 -0
  91. data/test/deep_test/test/work_result_test.rb +85 -0
  92. data/test/deep_test/test/work_unit_test.rb +63 -0
  93. data/test/deep_test/test_task_test.rb +15 -0
  94. data/test/deep_test/ui/console_test.rb +13 -0
  95. data/test/deep_test/warlock_test.rb +40 -0
  96. data/test/test_helper.rb +30 -0
  97. data/test/test_task_test.rb +75 -0
  98. metadata +156 -0
@@ -0,0 +1,128 @@
1
+ require File.dirname(__FILE__) + "/../test_helper"
2
+
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
10
+
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
18
+
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
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
38
+
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
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
56
+
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)
60
+
61
+ out = capture_stdout do
62
+ ResultReader.new(central_command).read(1 => "One") {}
63
+ end
64
+
65
+ assert_equal "output", out
66
+ end
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)
71
+
72
+ out = capture_stdout do
73
+ ResultReader.new(central_command).read(1 => "One") {}
74
+ end
75
+
76
+ assert_equal "", out
77
+ end
78
+
79
+ test "prints useful error information in case of Agent::Error" do
80
+ error = RuntimeError.new "message"
81
+ error.set_backtrace ['a', 'b']
82
+
83
+ central_command = TestCentralCommand.start Options.new({})
84
+ central_command.write_result Agent::Error.new("work_unit", error)
85
+
86
+
87
+ out = capture_stdout do
88
+ ResultReader.new(central_command).read(1 => "One") {}
89
+ end
90
+
91
+ assert_equal "work_unit: message\na\nb\n", out
92
+ end
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)
97
+
98
+
99
+ results = []
100
+ capture_stdout do
101
+ ResultReader.new(central_command).read(1 => "One") {|r| results << r}
102
+ end
103
+
104
+ assert_equal [], results
105
+ end
106
+
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
114
+
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)
119
+
120
+ work_units = {1 => "One", 2 => "Two"}
121
+
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
+ end
127
+ end
128
+ end
@@ -0,0 +1,42 @@
1
+ require File.dirname(__FILE__) + "/../../../test_helper"
2
+
3
+ module DeepTest
4
+ unit_tests do
5
+ test "make_exception_marshallable wraps exception in a mashallable exception" do
6
+ error = ::Test::Unit::Error.new "test_name", Exception.new("message")
7
+ error.make_exception_marshallable
8
+
9
+ assert_kind_of MarshallableExceptionWrapper, error.exception
10
+ end
11
+
12
+ test "calling make_exception_marshallable twice only wraps exception once" do
13
+ error = ::Test::Unit::Error.new "test_name", Exception.new("message")
14
+ error.make_exception_marshallable
15
+ error.make_exception_marshallable
16
+
17
+ assert_kind_of MarshallableExceptionWrapper, error.exception
18
+ end
19
+
20
+ test "error is accessible as normal when it has not been made marshallable" do
21
+ error = ::Test::Unit::Error.new "test_name", e = Exception.new("message")
22
+ assert_equal e, error.exception
23
+ end
24
+
25
+ test "resolve_marshallable_exception restores the original exception" do
26
+ error = ::Test::Unit::Error.new "test_name", Exception.new("message")
27
+ error.make_exception_marshallable
28
+ error.resolve_marshallable_exception
29
+
30
+ assert_kind_of Exception, error.exception
31
+ assert_equal 'message', error.exception.message
32
+ end
33
+
34
+ test "resolve_marshallable_exception does not fail when exception has not been made marshallable" do
35
+ error = ::Test::Unit::Error.new "test_name", Exception.new("message")
36
+ error.resolve_marshallable_exception
37
+
38
+ assert_kind_of Exception, error.exception
39
+ assert_equal 'message', error.exception.message
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,11 @@
1
+ require File.dirname(__FILE__) + "/../../test_helper"
2
+
3
+ module DeepTest
4
+ module Test
5
+ unit_tests do
6
+ test "no filters constant has empty filters" do
7
+ assert_equal [], Runner::NO_FILTERS.filters
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,107 @@
1
+ require File.dirname(__FILE__) + "/../../test_helper"
2
+
3
+ module DeepTest
4
+ module Test
5
+ unit_tests do
6
+ test "run yields name for start and finished of underlying suite" do
7
+ options = Options.new({})
8
+ suite = ::Test::Unit::TestSuite.new("name")
9
+ supervised_suite = SupervisedTestSuite.new(suite, TestCentralCommand.start(options))
10
+
11
+ yielded = []
12
+ supervised_suite.run(stub_everything) do |channel,name|
13
+ yielded << [channel,name]
14
+ end
15
+
16
+ assert_equal [[::Test::Unit::TestSuite::STARTED, "name"],
17
+ [::Test::Unit::TestSuite::FINISHED, "name"]], yielded
18
+ end
19
+
20
+ test "run adds tests to central_command and reads results" do
21
+ options = Options.new({})
22
+ class AddTestsTestCase < ::Test::Unit::TestCase
23
+ test("1") {}
24
+ test("2") {assert_equal true, false}
25
+ end
26
+ central_command = TestCentralCommand.start options
27
+ supervised_suite = SupervisedTestSuite.new(AddTestsTestCase.suite, central_command)
28
+ result = ::Test::Unit::TestResult.new
29
+
30
+ agent = ThreadAgent.new options
31
+ Timeout.timeout(5) do
32
+ supervised_suite.run(result) {}
33
+ end
34
+ central_command.done_with_work
35
+ agent.wait_until_done
36
+
37
+ assert_equal 2, result.run_count
38
+ assert_equal 1, result.failure_count
39
+ end
40
+
41
+ test "agent errors are counted as errors" do
42
+ options = Options.new({})
43
+ class AgentErrorTestCase < ::Test::Unit::TestCase
44
+ test("1") {}
45
+ end
46
+
47
+ central_command = TestCentralCommand.start options
48
+ supervised_suite = SupervisedTestSuite.new(AgentErrorTestCase.suite, central_command)
49
+ result = ::Test::Unit::TestResult.new
50
+
51
+ central_command.write_result Agent::Error.new(AgentErrorTestCase.new("test_1"), RuntimeError.new)
52
+ capture_stdout {supervised_suite.run(result) {}}
53
+
54
+ assert_equal 1, result.error_count
55
+ end
56
+
57
+ test "multiple agent errors are consolidated to be one error" do
58
+ options = Options.new({})
59
+ class MultipleAgentErrorTestCase < ::Test::Unit::TestCase
60
+ test("1") {}; test("2") {}
61
+ end
62
+ central_command = TestCentralCommand.start options
63
+ supervised_suite = SupervisedTestSuite.new(MultipleAgentErrorTestCase.suite, central_command)
64
+ result = ::Test::Unit::TestResult.new
65
+
66
+ central_command.write_result Agent::Error.new(MultipleAgentErrorTestCase.new("test_1"), RuntimeError.new)
67
+ central_command.write_result Agent::Error.new(MultipleAgentErrorTestCase.new("test_2"), RuntimeError.new)
68
+ capture_stdout {supervised_suite.run(result) {}}
69
+
70
+ assert_equal 1, result.error_count
71
+ end
72
+
73
+ test "run yields test case finished events" do
74
+ options = Options.new({})
75
+ class RunYieldsTestCase < ::Test::Unit::TestCase
76
+ test("1") {}
77
+ end
78
+ test_case = RunYieldsTestCase.new("test_1")
79
+
80
+ central_command = TestCentralCommand.start options
81
+ supervised_suite = SupervisedTestSuite.new(test_case, central_command)
82
+
83
+ yielded = []
84
+
85
+ agent = ThreadAgent.new options
86
+ Timeout.timeout(5) do
87
+ supervised_suite.run(stub_everything) do |channel,name|
88
+ yielded << [channel, name]
89
+ end
90
+ end
91
+ central_command.done_with_work
92
+ agent.wait_until_done
93
+
94
+ assert_equal true, yielded.include?([::Test::Unit::TestCase::FINISHED, test_case.name])
95
+ end
96
+
97
+ test "has same size as underlying suite" do
98
+ options = Options.new({})
99
+ suite = ::Test::Unit::TestSuite.new("name")
100
+ suite << "test"
101
+ supervised_suite = SupervisedTestSuite.new(suite, TestCentralCommand.start(options))
102
+
103
+ assert_equal suite.size, supervised_suite.size
104
+ end
105
+ end
106
+ end
107
+ end
@@ -0,0 +1,85 @@
1
+ require File.dirname(__FILE__) + "/../../test_helper"
2
+
3
+ module DeepTest
4
+ module Test
5
+ unit_tests do
6
+ test "add_to adds correct run_count" do
7
+ result_1 = WorkResult.new "test_name"
8
+ result_1.add_run
9
+ result_1.add_run
10
+
11
+ result_2 = ::Test::Unit::TestResult.new
12
+ result_1.add_to result_2
13
+
14
+ assert_equal 2, result_2.run_count
15
+ end
16
+
17
+ test "add_to adds correct assertion_count" do
18
+ result_1 = WorkResult.new "test_name"
19
+ result_1.add_assertion
20
+ result_1.add_assertion
21
+
22
+ result_2 = ::Test::Unit::TestResult.new
23
+ result_1.add_to result_2
24
+
25
+ assert_equal 2, result_2.assertion_count
26
+ end
27
+
28
+ test "add_to adds correct errors" do
29
+ result_1 = WorkResult.new "test_name"
30
+ result_1.add_error(e = ::Test::Unit::Error.new("test_name", Exception.new))
31
+
32
+ result_2 = ::Test::Unit::TestResult.new
33
+ result_1.add_to result_2
34
+
35
+ assert_equal [e], result_2.instance_variable_get(:@errors)
36
+ end
37
+
38
+
39
+ test "add_to adds correct failures" do
40
+ result_1 = WorkResult.new "test_name"
41
+ result_1.add_failure(:failure)
42
+
43
+ result_2 = ::Test::Unit::TestResult.new
44
+ result_1.add_to result_2
45
+
46
+ assert_equal [:failure], result_2.instance_variable_get(:@failures)
47
+ end
48
+
49
+ test "add_error wraps exceptions" do
50
+ result = WorkResult.new "test_name"
51
+ result.add_error ::Test::Unit::Error.new(
52
+ "test_wraps_exceptions",
53
+ SomeCustomException.new("the exception message")
54
+ )
55
+
56
+ error = result.instance_variable_get("@errors").last
57
+ assert_kind_of MarshallableExceptionWrapper, error.exception
58
+ end
59
+
60
+ test "add_to unwraps exception" do
61
+ work_result = WorkResult.new "test_name"
62
+ work_result.add_error ::Test::Unit::Error.new(
63
+ "test_wraps_exceptions",
64
+ SomeCustomException.new("the exception message")
65
+ )
66
+
67
+ test_result = ::Test::Unit::TestResult.new
68
+ work_result.add_to(test_result)
69
+
70
+ error = test_result.instance_variable_get("@errors").last
71
+ assert_kind_of SomeCustomException, error.exception
72
+ end
73
+
74
+ test "failed due to deadlock" do
75
+ result = WorkResult.new "test_name"
76
+ begin
77
+ raise FakeDeadlockError.new
78
+ rescue => ex
79
+ result.add_error ::Test::Unit::Error.new("test_", ex)
80
+ end
81
+ assert_equal true, result.failed_due_to_deadlock?
82
+ end
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,63 @@
1
+ require File.dirname(__FILE__) + "/../../test_helper"
2
+
3
+ module DeepTest
4
+ module Test
5
+ unit_tests do
6
+ test "returns passed result for passing test" do
7
+ work_unit = WorkUnit.new TestFactory.passing_test
8
+ assert_equal true, work_unit.run.passed?
9
+ end
10
+
11
+ test "returns failed result for failing test" do
12
+ work_unit = WorkUnit.new TestFactory.failing_test
13
+ assert_equal false, work_unit.run.passed?
14
+ end
15
+
16
+ test "returns result with identifier of test name" do
17
+ test = TestFactory.passing_test
18
+ work_unit = WorkUnit.new test
19
+ assert_equal test.name, work_unit.run.identifier
20
+ end
21
+
22
+ test "capturing stdout" do
23
+ work_unit = WorkUnit.new TestFactory.passing_test_with_stdout
24
+ assert_equal "message printed to stdout", work_unit.run.output
25
+ end
26
+
27
+ test "retry on deadlock" do
28
+ work_unit = WorkUnit.new TestFactory.deadlock_once_test
29
+ result = work_unit.run
30
+ assert_equal 0, result.error_count
31
+ assert_equal 0, result.failure_count
32
+ assert_equal 1, result.assertion_count
33
+ end
34
+
35
+ test "skip on deadlock twice" do
36
+ work_unit = WorkUnit.new TestFactory.deadlock_always_test
37
+ result = work_unit.run
38
+ assert_equal 0, result.error_count
39
+ assert_equal 0, result.failure_count
40
+ assert_equal 0, result.assertion_count
41
+ end
42
+
43
+ test "set test_name as identifier on deadlock" do
44
+ test = TestFactory.deadlock_always_test
45
+ work_unit = WorkUnit.new test
46
+ assert_equal test.name, work_unit.run.identifier
47
+ end
48
+
49
+ test "equality is based on test_case" do
50
+ test_case_1 = TestFactory.passing_test
51
+ test_case_2 = TestFactory.failing_test
52
+ assert_equal WorkUnit.new(test_case_1), WorkUnit.new(test_case_1)
53
+
54
+ assert_not_equal WorkUnit.new(test_case_1), WorkUnit.new(test_case_2)
55
+ end
56
+
57
+ test "to_s is delegated to test case" do
58
+ test_case = TestFactory.passing_test
59
+ assert_equal test_case.to_s, WorkUnit.new(test_case).to_s
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,15 @@
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+
3
+ module DeepTest
4
+ unit_tests do
5
+ test "should support listener" do
6
+ t = TestTask.new :deep_test do |t|
7
+ t.stubs(:desc)
8
+ t.stubs(:task)
9
+ t.listener = "A"
10
+ end
11
+ assert_equal "A", t.instance_variable_get(:@options).listener
12
+ assert_equal "A", t.listener
13
+ end
14
+ end
15
+ end