gorgon 0.11.0 → 0.11.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +0 -2
- data/.rspec +2 -0
- data/.travis.yml +10 -0
- data/Dockerfile +25 -0
- data/Gemfile.lock +20 -15
- data/README.md +33 -6
- data/Rakefile +5 -0
- data/architecture.md +2 -2
- data/bin/gorgon +2 -114
- data/daemon_with_upstart_and_rvm.md +1 -1
- data/docker-compose.yml +28 -0
- data/file_server/Dockerfile +8 -0
- data/file_server/test_gorgon.pem.pub +1 -0
- data/gorgon.gemspec +2 -2
- data/gorgon_secret.json.sample +5 -0
- data/lib/gorgon/amqp_service.rb +28 -26
- data/lib/gorgon/callback_handler.rb +28 -26
- data/lib/gorgon/colors.rb +6 -4
- data/lib/gorgon/command.rb +145 -0
- data/lib/gorgon/configuration.rb +45 -5
- data/lib/gorgon/core_ext/hash/deep_merge.rb +21 -0
- data/lib/gorgon/crash_reporter.rb +15 -13
- data/lib/gorgon/failures_printer.rb +27 -26
- data/lib/gorgon/g_logger.rb +19 -17
- data/lib/gorgon/gem_command_handler.rb +41 -39
- data/lib/gorgon/gem_service.rb +60 -57
- data/lib/gorgon/host_state.rb +23 -21
- data/lib/gorgon/job.rb +19 -17
- data/lib/gorgon/job_definition.rb +23 -21
- data/lib/gorgon/job_state.rb +93 -90
- data/lib/gorgon/listener.rb +137 -146
- data/lib/gorgon/listener_installer.rb +98 -96
- data/lib/gorgon/originator.rb +170 -167
- data/lib/gorgon/originator_logger.rb +30 -28
- data/lib/gorgon/originator_protocol.rb +85 -83
- data/lib/gorgon/ping_service.rb +44 -42
- data/lib/gorgon/pipe_forker.rb +17 -15
- data/lib/gorgon/progress_bar_view.rb +109 -107
- data/lib/gorgon/rsync_daemon.rb +56 -54
- data/lib/gorgon/runtime_file_reader.rb +28 -27
- data/lib/gorgon/runtime_recorder.rb +27 -26
- data/lib/gorgon/settings/files_content.rb +27 -25
- data/lib/gorgon/settings/initial_files_creator.rb +58 -56
- data/lib/gorgon/settings/rails_project_files_content.rb +33 -31
- data/lib/gorgon/settings/simple_project_files_content.rb +11 -9
- data/lib/gorgon/shutdown_manager.rb +20 -18
- data/lib/gorgon/source_tree_syncer.rb +108 -69
- data/lib/gorgon/version.rb +1 -1
- data/lib/gorgon/worker.rb +130 -128
- data/lib/gorgon/worker_manager.rb +139 -137
- data/lib/gorgon_amq-protocol/.rspec +3 -0
- data/run_dev_environment.sh +3 -0
- data/run_gorgon.sh +3 -0
- data/run_listener.sh +3 -0
- data/run_test.sh +3 -0
- data/spec/callback_handler_spec.rb +10 -10
- data/spec/command_spec.rb +172 -0
- data/spec/configuration_spec.rb +62 -0
- data/spec/core_ext/hash/deep_merge_spec.rb +11 -0
- data/spec/crash_reporter_spec.rb +10 -10
- data/spec/dummy/.gitignore +3 -0
- data/spec/dummy/Gemfile +11 -0
- data/spec/dummy/Gemfile.lock +76 -0
- data/spec/dummy/README.md +23 -0
- data/spec/dummy/gorgon.json +30 -0
- data/spec/dummy/gorgon_callbacks.rb +68 -0
- data/spec/dummy/gorgon_listener.json +8 -0
- data/spec/dummy/integration_spec.rb +51 -0
- data/spec/{support/mock_app/app/mailers → dummy/log}/.gitkeep +0 -0
- data/spec/dummy/rspec_runner.rb +8 -0
- data/spec/dummy/spec/1_syntax_error_spec.rb +1 -0
- data/spec/dummy/spec/exception_spec.rb +5 -0
- data/spec/dummy/spec/failing_spec.rb +11 -0
- data/spec/dummy/spec/keeping_rspec_config_spec.rb +5 -0
- data/spec/dummy/spec/spec_helper.rb +13 -0
- data/spec/dummy/spec/successful_spec.rb +9 -0
- data/spec/dummy/spec/using_shared_example_spec.rb +3 -0
- data/spec/dummy/test/.rb +15 -0
- data/spec/dummy/test/minitest/mini1_test.rb +11 -0
- data/spec/dummy/test/minitest/mini2_test.rb +25 -0
- data/spec/dummy/test/unit/1_syntax_error_test.rb +9 -0
- data/spec/dummy/test/unit/exception_test.rb +14 -0
- data/spec/dummy/test/unit/failing_test.rb +17 -0
- data/spec/dummy/test/unit/successful_test.rb +9 -0
- data/spec/dummy/test_gorgon.pem +27 -0
- data/spec/end_to_end_spec.rb +142 -0
- data/spec/failures_printer_spec.rb +20 -20
- data/spec/gem_command_handler_spec.rb +24 -24
- data/spec/gem_service_spec.rb +18 -18
- data/spec/gorgon_rspec_formatter_spec.rb +12 -12
- data/spec/host_state_spec.rb +8 -8
- data/spec/job_definition_spec.rb +3 -3
- data/spec/job_state_spec.rb +46 -46
- data/spec/listener_spec.rb +67 -73
- data/spec/mini_test_runner_spec.rb +7 -7
- data/spec/originator_logger_spec.rb +6 -6
- data/spec/originator_protocol_spec.rb +38 -38
- data/spec/originator_spec.rb +78 -69
- data/spec/ping_service_spec.rb +14 -14
- data/spec/pipe_forker_spec.rb +13 -13
- data/spec/progress_bar_view_spec.rb +32 -32
- data/spec/rspec_runner_spec.rb +12 -12
- data/spec/rsync_daemon_spec.rb +18 -16
- data/spec/runtime_file_reader_spec.rb +12 -12
- data/spec/runtime_recorder_spec.rb +19 -19
- data/spec/shutdown_manager_spec.rb +9 -9
- data/spec/source_tree_syncer_spec.rb +148 -61
- data/spec/spec_helper.rb +3 -0
- data/spec/support/end_to_end_helpers.rb +16 -0
- data/spec/support/stream_helpers.rb +23 -0
- data/spec/unknown_runner_spec.rb +1 -1
- data/spec/worker_manager_spec.rb +23 -23
- data/spec/worker_spec.rb +70 -70
- metadata +84 -113
- data/spec/acceptance_spec_helper.rb +0 -7
- data/spec/support/mock_app/.gitignore +0 -15
- data/spec/support/mock_app/Gemfile +0 -39
- data/spec/support/mock_app/Gemfile.lock +0 -135
- data/spec/support/mock_app/README.rdoc +0 -261
- data/spec/support/mock_app/Rakefile +0 -7
- data/spec/support/mock_app/app/assets/images/rails.png +0 -0
- data/spec/support/mock_app/app/assets/javascripts/application.js +0 -15
- data/spec/support/mock_app/app/assets/stylesheets/application.css +0 -13
- data/spec/support/mock_app/app/controllers/application_controller.rb +0 -3
- data/spec/support/mock_app/app/helpers/application_helper.rb +0 -2
- data/spec/support/mock_app/app/models/.gitkeep +0 -0
- data/spec/support/mock_app/app/views/layouts/application.html.erb +0 -14
- data/spec/support/mock_app/config.ru +0 -4
- data/spec/support/mock_app/config/application.rb +0 -62
- data/spec/support/mock_app/config/boot.rb +0 -6
- data/spec/support/mock_app/config/database.yml +0 -25
- data/spec/support/mock_app/config/environment.rb +0 -5
- data/spec/support/mock_app/config/environments/development.rb +0 -37
- data/spec/support/mock_app/config/environments/production.rb +0 -67
- data/spec/support/mock_app/config/environments/test.rb +0 -37
- data/spec/support/mock_app/config/initializers/backtrace_silencers.rb +0 -7
- data/spec/support/mock_app/config/initializers/inflections.rb +0 -15
- data/spec/support/mock_app/config/initializers/mime_types.rb +0 -5
- data/spec/support/mock_app/config/initializers/secret_token.rb +0 -7
- data/spec/support/mock_app/config/initializers/session_store.rb +0 -8
- data/spec/support/mock_app/config/initializers/wrap_parameters.rb +0 -14
- data/spec/support/mock_app/config/locales/en.yml +0 -5
- data/spec/support/mock_app/config/routes.rb +0 -58
- data/spec/support/mock_app/db/seeds.rb +0 -7
- data/spec/support/mock_app/doc/README_FOR_APP +0 -2
- data/spec/support/mock_app/lib/assets/.gitkeep +0 -0
- data/spec/support/mock_app/lib/tasks/.gitkeep +0 -0
- data/spec/support/mock_app/log/.gitkeep +0 -0
- data/spec/support/mock_app/public/404.html +0 -26
- data/spec/support/mock_app/public/422.html +0 -26
- data/spec/support/mock_app/public/500.html +0 -25
- data/spec/support/mock_app/public/favicon.ico +0 -0
- data/spec/support/mock_app/public/index.html +0 -241
- data/spec/support/mock_app/public/robots.txt +0 -5
- data/spec/support/mock_app/script/rails +0 -6
- data/spec/support/mock_app/test/fixtures/.gitkeep +0 -0
- data/spec/support/mock_app/test/functional/.gitkeep +0 -0
- data/spec/support/mock_app/test/integration/.gitkeep +0 -0
- data/spec/support/mock_app/test/performance/browsing_test.rb +0 -12
- data/spec/support/mock_app/test/test_helper.rb +0 -13
- data/spec/support/mock_app/test/unit/.gitkeep +0 -0
- data/spec/support/mock_app/test/unit/passing_test.rb +0 -7
- data/spec/support/mock_app/vendor/assets/javascripts/.gitkeep +0 -0
- data/spec/support/mock_app/vendor/assets/stylesheets/.gitkeep +0 -0
- data/spec/support/mock_app/vendor/plugins/.gitkeep +0 -0
- data/spec/support/originator_handler.rb +0 -8
data/spec/dummy/test/.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'minitest/unit'
|
2
|
+
|
3
|
+
class GorgonMini2Test < MiniTest::Unit::TestCase
|
4
|
+
def test_pass
|
5
|
+
assert true
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_fails
|
9
|
+
assert false
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
class OtherCaseTest < MiniTest::Unit::TestCase
|
14
|
+
def test_pass
|
15
|
+
assert true
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_fails
|
19
|
+
assert false
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_that_will_be_skipped
|
23
|
+
skip "test this later"
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
-----BEGIN RSA PRIVATE KEY-----
|
2
|
+
MIIEpAIBAAKCAQEAtXfCXWX3qlOLErhwX9OVEFK2nYFnbNVulBZE5vPWbDwBUyTS
|
3
|
+
zuNAOtN7cmF/5GFnWJm2UHr+BMc5yKWQwoXak6I44z9apxREr/TXAVBER6NyO/Zq
|
4
|
+
dj2p0HxZy9FZHCcPV2wwGSE3O5U8mcphmWS9xYhjVhoopN5vjobgXm6ie7IYVJvY
|
5
|
+
vtZOCxCBKmDxETDl9HYphySwsNhc4fvPaYmDP8jk2SGN7Z3g2kD8FOme8rUUdYNQ
|
6
|
+
fni2l7Aq4oRNUnl48v6aMGKqW89RAd+Lg/mjPVcIsm/67XH5E0FgOvVAPTYqne06
|
7
|
+
bBpZckHru42xUPNlkHthiL9PbpBuYVYNKQ9gWwIDAQABAoIBAQCG0RdcbjHmn7SV
|
8
|
+
zuLlvnpjKyAyuf3NlG9Xo4fDEWq+9IGDdLsNKzX/vjhbTOZIFLlD0Mbq2cU4ZY6f
|
9
|
+
a6m1at5tijq7UckWke9JzhuiBTEFDAAFXlfPypYLpybLTpfmW3qBV4YQVWYEZSYl
|
10
|
+
l36VCIwYYfBy+nIxsnOsrrWoUodyXyhetYGUrbn6dspgC5K7dPhDDEtK2YQEWVrH
|
11
|
+
d8XFyl3/RTB55BPo/PUlqYfeRCdOWMtqOzW/nVvNgRVVNubr+TP8Y9nhs2XovsHD
|
12
|
+
IGmjItrMl1pbTC7O2mHAd5gGkFlq3jEr8EXK87KN/BKDUBCVDMaZYwUliFgnpQbT
|
13
|
+
Ik/7RG45AoGBAN4lRvdkZlB4ADKM2ocGjBIDDszf/7NDD6Y+/iJSlo/LPCDoxGjf
|
14
|
+
ZhCHzvqeZl7SbWr2XUhn6vVGZS4WJYb3ys/QNLKtK/XI5JYtoTFOysQY3RYttyYG
|
15
|
+
twuSI7M+lgVXvpAPoX2/dlSd7whalRDWZSLPUXrBdX6YvrmRYpOfvdklAoGBANEf
|
16
|
+
fYLyiQZmwx4F5i1EC6WYR7PakUABLPrr5L35lUiHhO1gLgu+bOgseDEBbjdOV/ES
|
17
|
+
YZO0zeTC8ou+An+nBT9S1fxIkOfxRAbSUXn5DTYOztNEfpA/zB9/NJug+P21oMMW
|
18
|
+
h6rixz/G5ayvOz6ZCJzvwBWPXPdu6U5uLjBNRtt/AoGAJ42xnhkFUqybNGT5//K9
|
19
|
+
e/OJbhcwOyXkonAy5b+YyU+hjCaF2jp0vNrBksQjbBzBmLr3Dw5ZuoRnPZZ55hc2
|
20
|
+
yFvFFk9ZNXEoqkjDm7jwx4u5ydon8yBc9TV3H9Iz+g2Og64UzgQKOLTKO82NHytd
|
21
|
+
ZJ5PXrEVj43436ewSqK1tfUCgYEAtd6RJWUQzkRoxJ+UwyE+j9GT6lLXp7ZeDAtD
|
22
|
+
cASzU9SoQlk3Mnd196VVEimQVQEJclruCatgtObmUan6OlJjOeMsvq/NdipZYyVe
|
23
|
+
PpneZ3kRXqNe/sy9FVdnxUGFygA/w+rAKln3tvufm0L6X0JwPywy/Y0k6PvIY7Fm
|
24
|
+
8hMC4LkCgYAO82O4xrdo7Cjh1S4itM5nDuiQS4/tYcnxIHirHh6roolBoz2oIu5M
|
25
|
+
PoMZZbAAvP0mbPESndwL2f/JL8aU9EgTT9qZYtAa802yMLsFIASUWdmpA5pdnjcr
|
26
|
+
bKQ+SBYgH+c4L+kdLr0qk79FpU/SyahIlrEcTMOfKzj+PHVn64b5XQ==
|
27
|
+
-----END RSA PRIVATE KEY-----
|
@@ -0,0 +1,142 @@
|
|
1
|
+
require "open4"
|
2
|
+
require "socket"
|
3
|
+
require File.expand_path("../support/end_to_end_helpers", __FILE__)
|
4
|
+
|
5
|
+
describe "EndToEnd" do
|
6
|
+
include Gorgon::EndToEndHelpers
|
7
|
+
|
8
|
+
HOSTNAME = "listener"
|
9
|
+
|
10
|
+
before(:all) do
|
11
|
+
Dir.chdir(File.join(__dir__, "dummy")) do
|
12
|
+
pid, stdin, stdout, stderr = Open4::popen4("bundle exec gorgon")
|
13
|
+
@outputs = stdout.read.split("*" * 80)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
context "number of output hunks" do
|
18
|
+
it "is same as errors raised plus meta information" do
|
19
|
+
expect(@outputs.count).to eq(7), "expected 7 output hunks, got:\n#{@outputs.inspect}"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context "meta suite run information" do
|
24
|
+
it "has version and legend information" do
|
25
|
+
expected_meta = <<-META
|
26
|
+
Welcome to Gorgon #{Gorgon::VERSION}
|
27
|
+
before job starts was called
|
28
|
+
Loading environment and workers...\r \rLegend:
|
29
|
+
F - failure files count
|
30
|
+
H - number of hosts that have run files
|
31
|
+
W - number of workers running files
|
32
|
+
|
33
|
+
|
34
|
+
Progress: ||
|
35
|
+
|
36
|
+
META
|
37
|
+
expect(@outputs[0]).to eq(expected_meta)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
context "last hunk" do
|
42
|
+
it "has information for running after_job_finishes callback" do
|
43
|
+
expect(@outputs.last).to match(Gorgon::EndToEndHelpers::AFTER_RUNNING_REGEX)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
context "exception test" do
|
48
|
+
it "has proper error output" do
|
49
|
+
actual_output = extract_hunk(@outputs, /Stuff::Haha1/)
|
50
|
+
expected_output = <<-EXPECTED
|
51
|
+
|
52
|
+
File 'test/unit/exception_test.rb' failed/crashed at '#{HOSTNAME}:1'
|
53
|
+
Error:
|
54
|
+
test_going_to_blow_up(Stuff::Haha1):
|
55
|
+
RuntimeError: oh mah gawd
|
56
|
+
test/unit/exception_test.rb:10:in `test_going_to_blow_up'
|
57
|
+
|
58
|
+
EXPECTED
|
59
|
+
|
60
|
+
expect(actual_output).to eq(expected_output)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
context "exception spec" do
|
65
|
+
it "has proper error output" do
|
66
|
+
actual_output = extract_hunk(@outputs, /exception_spec/)
|
67
|
+
expected_output = <<-EXPECTED
|
68
|
+
|
69
|
+
File 'spec/exception_spec.rb' failed/crashed at '#{HOSTNAME}:1'
|
70
|
+
Test name: Exception spec raises: line 2
|
71
|
+
RuntimeError
|
72
|
+
Message:
|
73
|
+
BOOOOM from spec!
|
74
|
+
|
75
|
+
|
76
|
+
EXPECTED
|
77
|
+
|
78
|
+
expect(actual_output).to eq(expected_output)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
context "syntax error test" do
|
83
|
+
it "has proper error output" do
|
84
|
+
actual_output = extract_hunk(@outputs, /1_syntax_error_test/, strip_backtrace: true)
|
85
|
+
expected_output = <<-EXPECTED
|
86
|
+
|
87
|
+
File 'test/unit/1_syntax_error_test.rb' failed/crashed at '#{HOSTNAME}:1'
|
88
|
+
Exception: test/unit/1_syntax_error_test.rb:9: syntax error, unexpected end-of-input, expecting keyword_end
|
89
|
+
|
90
|
+
EXPECTED
|
91
|
+
expect(actual_output).to eq(expected_output)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
context "syntax error spec" do
|
96
|
+
it "has proper error output" do
|
97
|
+
actual_output = extract_hunk(@outputs, /1_syntax_error_spec/, strip_backtrace: true)
|
98
|
+
expected_output = <<-EXPECTED
|
99
|
+
|
100
|
+
File 'spec/1_syntax_error_spec.rb' failed/crashed at '#{HOSTNAME}:1'
|
101
|
+
Exception: undefined local variable or method `ruby' for main:Object
|
102
|
+
|
103
|
+
EXPECTED
|
104
|
+
expect(actual_output).to eq(expected_output)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
context "failing test" do
|
109
|
+
it "has proper error output" do
|
110
|
+
actual_output = extract_hunk(@outputs, /failing_test\.rb/)
|
111
|
+
expected_output = <<-EXPECTED
|
112
|
+
|
113
|
+
File 'test/unit/failing_test.rb' failed/crashed at '#{HOSTNAME}:1'
|
114
|
+
Failure:
|
115
|
+
test_2_will_fail(Stuff::Over9000) [test/unit/failing_test.rb:14]:
|
116
|
+
<false> is not true.
|
117
|
+
Failure:
|
118
|
+
test_will_fail(Stuff::Over9000) [test/unit/failing_test.rb:10]:
|
119
|
+
<false> is not true.
|
120
|
+
|
121
|
+
EXPECTED
|
122
|
+
expect(actual_output).to eq(expected_output)
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
context "failing spec" do
|
127
|
+
it "has proper error output" do
|
128
|
+
actual_output = extract_hunk(@outputs, /failing_spec\.rb/)
|
129
|
+
expected_output = <<-EXPECTED
|
130
|
+
|
131
|
+
File 'spec/failing_spec.rb' failed/crashed at '#{HOSTNAME}:1'
|
132
|
+
Test name: Failing spec fails: line 6
|
133
|
+
RSpec::Expectations::ExpectationNotMetError
|
134
|
+
Message:
|
135
|
+
failed
|
136
|
+
|
137
|
+
|
138
|
+
EXPECTED
|
139
|
+
expect(actual_output).to eq(expected_output)
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'gorgon/failures_printer'
|
2
2
|
|
3
|
-
describe FailuresPrinter do
|
3
|
+
describe Gorgon::FailuresPrinter do
|
4
4
|
let(:job_state) { double("Job State", :add_observer => nil,
|
5
5
|
:is_job_complete? => true, :is_job_cancelled? => false,
|
6
6
|
:each_failed_test => nil,
|
@@ -8,63 +8,63 @@ describe FailuresPrinter do
|
|
8
8
|
let(:fd) {double("File descriptor", :write => nil)}
|
9
9
|
|
10
10
|
subject do
|
11
|
-
FailuresPrinter.new({}, job_state)
|
11
|
+
Gorgon::FailuresPrinter.new({}, job_state)
|
12
12
|
end
|
13
13
|
|
14
14
|
it { should respond_to :update }
|
15
15
|
|
16
16
|
describe "#initialize" do
|
17
17
|
it "add its self to observers of job_state" do
|
18
|
-
job_state.
|
19
|
-
FailuresPrinter.new({}, job_state)
|
18
|
+
expect(job_state).to receive(:add_observer)
|
19
|
+
Gorgon::FailuresPrinter.new({}, job_state)
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
23
|
describe "#update" do
|
24
24
|
before do
|
25
|
-
@printer = FailuresPrinter.new({}, job_state)
|
25
|
+
@printer = Gorgon::FailuresPrinter.new({}, job_state)
|
26
26
|
end
|
27
27
|
|
28
28
|
context "job is not completed nor cancelled" do
|
29
29
|
it "doesn't output anything" do
|
30
|
-
job_state.
|
31
|
-
File.
|
30
|
+
allow(job_state).to receive(:is_job_complete?).and_return(false)
|
31
|
+
expect(File).not_to receive(:open)
|
32
32
|
@printer.update({})
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
36
|
context "job is completed" do
|
37
37
|
it "outputs failed tests return by job_state#each_failed_test" do
|
38
|
-
job_state.
|
39
|
-
File.
|
40
|
-
fd.
|
38
|
+
allow(job_state).to receive(:each_failed_test).and_yield({:filename => "file1.rb"}).and_yield({:filename => "file2.rb"})
|
39
|
+
expect(File).to receive(:open).with(Gorgon::FailuresPrinter::DEFAULT_OUTPUT_FILE, 'w+').and_yield fd
|
40
|
+
expect(fd).to receive(:write).with(Yajl::Encoder.encode(["file1.rb", "file2.rb"]))
|
41
41
|
@printer.update({})
|
42
42
|
end
|
43
43
|
|
44
44
|
it "outputs failed tests to 'failed_files' in configuration" do
|
45
|
-
printer = FailuresPrinter.new({failed_files: 'a-file-somewhere.json'}, job_state)
|
46
|
-
File.
|
45
|
+
printer = Gorgon::FailuresPrinter.new({failed_files: 'a-file-somewhere.json'}, job_state)
|
46
|
+
expect(File).to receive(:open).with('a-file-somewhere.json', 'w+')
|
47
47
|
printer.update({})
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
51
51
|
context "job is cancelled" do
|
52
52
|
before do
|
53
|
-
job_state.
|
54
|
-
job_state.
|
53
|
+
allow(job_state).to receive(:is_job_complete?).and_return(false)
|
54
|
+
allow(job_state).to receive(:is_job_cancelled?).and_return(true)
|
55
55
|
end
|
56
56
|
|
57
57
|
it "outputs failed tests return by job_state#each_failed_test" do
|
58
|
-
job_state.
|
59
|
-
File.
|
60
|
-
fd.
|
58
|
+
allow(job_state).to receive(:each_failed_test).and_yield({:filename => "file1.rb"}).and_yield({:filename => "file2.rb"})
|
59
|
+
expect(File).to receive(:open).with(Gorgon::FailuresPrinter::DEFAULT_OUTPUT_FILE, 'w+').and_yield fd
|
60
|
+
expect(fd).to receive(:write).once.with(Yajl::Encoder.encode(["file1.rb", "file2.rb"]))
|
61
61
|
@printer.update({})
|
62
62
|
end
|
63
63
|
|
64
64
|
it "outputs still-running files returns by job_state#each_running_file" do
|
65
|
-
job_state.
|
66
|
-
File.
|
67
|
-
fd.
|
65
|
+
allow(job_state).to receive(:each_running_file).and_yield("host1", "file1.rb").and_yield("host2", "file2.rb")
|
66
|
+
allow(File).to receive(:open).and_yield fd
|
67
|
+
expect(fd).to receive(:write).once.with(Yajl::Encoder.encode(["file1.rb", "file2.rb"]))
|
68
68
|
@printer.update({})
|
69
69
|
end
|
70
70
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'gorgon/gem_command_handler'
|
2
2
|
|
3
|
-
describe GemCommandHandler do
|
3
|
+
describe Gorgon::GemCommandHandler do
|
4
4
|
let(:exchange) { double("GorgonBunny Exchange", :publish => nil) }
|
5
5
|
let(:bunny) { double("GorgonBunny", :exchange => exchange, :stop => nil) }
|
6
6
|
|
@@ -15,70 +15,70 @@ describe GemCommandHandler do
|
|
15
15
|
|
16
16
|
describe "#handle" do
|
17
17
|
before do
|
18
|
-
@handler = GemCommandHandler.new bunny
|
18
|
+
@handler = Gorgon::GemCommandHandler.new bunny
|
19
19
|
@running_response = {:type => :running_command, :hostname => Socket.gethostname}
|
20
20
|
stub_methods
|
21
21
|
end
|
22
22
|
|
23
23
|
it "publishes 'running_command' message" do
|
24
|
-
bunny.
|
25
|
-
Yajl::Encoder.
|
26
|
-
exchange.
|
24
|
+
expect(bunny).to receive(:exchange).with("name", anything).and_return(exchange)
|
25
|
+
expect(Yajl::Encoder).to receive(:encode).with(@running_response).and_return :json_msg
|
26
|
+
expect(exchange).to receive(:publish).with(:json_msg)
|
27
27
|
@handler.handle payload, {}
|
28
28
|
end
|
29
29
|
|
30
30
|
it "runs 'gem <command> gorgon' using popen4" do
|
31
|
-
Open4.
|
31
|
+
expect(Open4).to receive(:popen4).with("gem cmd gorgon").and_return([1, stdin, stdout, stderr])
|
32
32
|
@handler.handle payload, {}
|
33
33
|
end
|
34
34
|
|
35
35
|
it "uses binary gem from configuration if this was specified" do
|
36
|
-
Open4.
|
36
|
+
expect(Open4).to receive(:popen4).with("path/to/gem cmd gorgon").and_return([1, stdin, stdout, stderr])
|
37
37
|
@handler.handle payload, {:bin_gem_path => "path/to/gem"}
|
38
38
|
end
|
39
39
|
|
40
40
|
it "waits for the command to finish" do
|
41
|
-
Open4.
|
42
|
-
Process.
|
41
|
+
expect(Open4).to receive(:popen4).ordered
|
42
|
+
expect(Process).to receive(:waitpid2).with(1).ordered.and_return([nil, status])
|
43
43
|
@handler.handle payload, {}
|
44
44
|
end
|
45
45
|
|
46
46
|
it "closes stding and reads stdout and stderr from process" do
|
47
|
-
stdin.
|
48
|
-
stdout.
|
49
|
-
stderr.
|
47
|
+
expect(stdin).to receive(:close)
|
48
|
+
expect(stdout).to receive(:read)
|
49
|
+
expect(stderr).to receive(:read)
|
50
50
|
@handler.handle payload, {}
|
51
51
|
end
|
52
52
|
|
53
53
|
it "sends 'command_completed' message when exitstatus is 0" do
|
54
54
|
response = {:type => :command_completed, :hostname => Socket.gethostname,
|
55
55
|
:command => "gem cmd gorgon", :stdout => "output", :stderr => "errors" }
|
56
|
-
Yajl::Encoder.
|
57
|
-
Yajl::Encoder.
|
58
|
-
exchange.
|
56
|
+
expect(Yajl::Encoder).to receive(:encode).once.ordered.with(@running_response)
|
57
|
+
expect(Yajl::Encoder).to receive(:encode).once.ordered.with(response).and_return :json_msg
|
58
|
+
expect(exchange).to receive(:publish).with(:json_msg)
|
59
59
|
@handler.handle payload, {}
|
60
60
|
end
|
61
61
|
|
62
62
|
it "stops bunny and exit if exitstatus is 0" do
|
63
|
-
bunny.
|
64
|
-
@handler.
|
63
|
+
expect(bunny).to receive(:stop).once.ordered
|
64
|
+
expect(@handler).to receive(:exit).once.ordered
|
65
65
|
@handler.handle payload, {}
|
66
66
|
end
|
67
67
|
|
68
68
|
it "sends 'command_failed' message when exitstatus is not 0" do
|
69
|
-
status.
|
69
|
+
expect(status).to receive(:exitstatus).and_return(99)
|
70
70
|
response = {:type => :command_failed, :hostname => Socket.gethostname,
|
71
71
|
:command => "gem cmd gorgon", :stdout => "output", :stderr => "errors" }
|
72
|
-
Yajl::Encoder.
|
73
|
-
exchange.
|
72
|
+
expect(Yajl::Encoder).to receive(:encode).with(response).and_return :json_msg
|
73
|
+
expect(exchange).to receive(:publish).with(:json_msg)
|
74
74
|
@handler.handle payload, {}
|
75
75
|
end
|
76
76
|
end
|
77
77
|
|
78
78
|
def stub_methods
|
79
|
-
Open4.
|
80
|
-
Process.
|
81
|
-
Yajl::Encoder.
|
82
|
-
@handler.
|
79
|
+
allow(Open4).to receive(:popen4).and_return([1, stdin, stdout, stderr])
|
80
|
+
allow(Process).to receive(:waitpid2).and_return([nil, status])
|
81
|
+
allow(Yajl::Encoder).to receive(:encode).and_return :json_msg
|
82
|
+
allow(@handler).to receive(:exit)
|
83
83
|
end
|
84
84
|
end
|