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/originator_spec.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
require 'gorgon/originator'
|
2
|
+
require File.expand_path("../support/stream_helpers", __FILE__)
|
2
3
|
|
3
|
-
describe Originator do
|
4
|
+
describe Gorgon::Originator do
|
5
|
+
include Gorgon::StreamHelpers
|
4
6
|
let(:protocol){ double("Originator Protocol", :connect => nil, :publish_files => nil,
|
5
7
|
:publish_job_to_all => nil, :publish_job_to_one => nil, :receive_payloads => nil, :cancel_job => nil,
|
6
8
|
:disconnect => nil, :receive_new_listener_notifications => nil)}
|
@@ -10,15 +12,16 @@ describe Originator do
|
|
10
12
|
:add_observer => nil)}
|
11
13
|
let(:progress_bar_view){ double("Progress Bar View", :show => nil)}
|
12
14
|
let(:originator_logger){ double("Originator Logger", :log => nil, :log_message => nil)}
|
13
|
-
let(:source_tree_syncer) { double("Source Tree Syncer"
|
14
|
-
|
15
|
-
let(:job_definition){ JobDefinition.new }
|
15
|
+
let(:source_tree_syncer) { double("Source Tree Syncer")}
|
16
|
+
let(:sync_execution_context) { double("Sync Execution Context", success: true, command: "command")}
|
17
|
+
let(:job_definition){ Gorgon::JobDefinition.new }
|
16
18
|
|
17
19
|
before do
|
18
|
-
OriginatorLogger.
|
19
|
-
SourceTreeSyncer.
|
20
|
-
|
21
|
-
|
20
|
+
allow(Gorgon::OriginatorLogger).to receive(:new).and_return originator_logger
|
21
|
+
allow(Gorgon::SourceTreeSyncer).to receive(:new).and_return source_tree_syncer
|
22
|
+
allow(source_tree_syncer).to receive(:push).and_return(sync_execution_context)
|
23
|
+
allow(Dir).to receive(:[]).and_return(["file"])
|
24
|
+
@originator = Gorgon::Originator.new
|
22
25
|
end
|
23
26
|
|
24
27
|
describe "#publish" do
|
@@ -27,61 +30,63 @@ describe Originator do
|
|
27
30
|
end
|
28
31
|
|
29
32
|
it "creates a JobState instance and passes total files" do
|
30
|
-
@originator.
|
31
|
-
JobState.
|
33
|
+
allow(@originator).to receive(:files).and_return ["a file", "other file"]
|
34
|
+
expect(Gorgon::JobState).to receive(:new).with(2).and_return job_state
|
32
35
|
|
33
36
|
@originator.publish
|
34
37
|
end
|
35
38
|
|
36
39
|
it "propagates the success result of handle_reply" do
|
37
|
-
@originator.publish.
|
40
|
+
expect(@originator.publish).to eq Gorgon::Originator::SPEC_SUCCESS_EXIT_STATUS
|
38
41
|
end
|
39
42
|
|
40
43
|
it "propagates the error result of handle_reply" do
|
41
|
-
OriginatorProtocol.
|
42
|
-
protocol.
|
44
|
+
expect(Gorgon::OriginatorProtocol).to receive(:new).and_return(protocol)
|
45
|
+
expect(protocol).to receive(:receive_payloads).and_yield(Yajl::Encoder.encode({:type => 'fail'}))
|
43
46
|
|
44
|
-
|
47
|
+
silence_streams($stdout) do
|
48
|
+
expect(@originator.publish).to eq Gorgon::Originator::SPEC_FAILURE_EXIT_STATUS
|
49
|
+
end
|
45
50
|
end
|
46
51
|
|
47
52
|
it "creates a ProgressBarView and show" do
|
48
|
-
JobState.
|
49
|
-
ProgressBarView.
|
50
|
-
progress_bar_view.
|
53
|
+
allow(Gorgon::JobState).to receive(:new).and_return job_state
|
54
|
+
expect(Gorgon::ProgressBarView).to receive(:new).with(job_state).and_return progress_bar_view
|
55
|
+
expect(progress_bar_view).to receive(:show)
|
51
56
|
@originator.publish
|
52
57
|
end
|
53
58
|
|
54
59
|
it "pushes source code" do
|
55
|
-
source_tree_syncer.
|
56
|
-
|
60
|
+
expect(source_tree_syncer).to receive(:push).and_return(sync_execution_context)
|
61
|
+
expect(sync_execution_context).to receive(:success).and_return true
|
57
62
|
|
58
63
|
@originator.publish
|
59
64
|
end
|
60
65
|
|
61
66
|
it "errors and halts when there are no test files" do
|
62
|
-
Dir.
|
67
|
+
allow(Dir).to receive(:[]).and_return([])
|
63
68
|
|
64
|
-
$stderr.
|
65
|
-
OriginatorProtocol.
|
66
|
-
source_tree_syncer.
|
69
|
+
expect($stderr).to receive(:puts)
|
70
|
+
expect(Gorgon::OriginatorProtocol).not_to receive(:new)
|
71
|
+
expect(source_tree_syncer).not_to receive(:push)
|
67
72
|
|
68
73
|
expect { @originator.publish }.to raise_error(SystemExit)
|
69
74
|
end
|
70
75
|
|
71
76
|
it "calls before_originate callback" do
|
72
|
-
CallbackHandler.
|
77
|
+
expect_any_instance_of(Gorgon::CallbackHandler).to receive(:before_originate)
|
73
78
|
@originator.publish
|
74
79
|
end
|
75
80
|
|
76
81
|
it "uses results of before_originate callback to build a job_queue_name" do
|
77
|
-
CallbackHandler.
|
78
|
-
OriginatorProtocol.
|
82
|
+
allow_any_instance_of(Gorgon::CallbackHandler).to receive(:before_originate).and_return('job_1')
|
83
|
+
expect(Gorgon::OriginatorProtocol).to receive(:new).with(anything, 'job_1')
|
79
84
|
|
80
85
|
@originator.publish
|
81
86
|
end
|
82
87
|
|
83
88
|
it "calls after_job_finishes callback" do
|
84
|
-
CallbackHandler.
|
89
|
+
expect_any_instance_of(Gorgon::CallbackHandler).to receive(:after_job_finishes)
|
85
90
|
|
86
91
|
@originator.publish
|
87
92
|
end
|
@@ -93,12 +98,12 @@ describe Originator do
|
|
93
98
|
end
|
94
99
|
|
95
100
|
it "exits with a non-zero status code when the originator crashes" do
|
96
|
-
originator_logger.
|
101
|
+
allow(originator_logger).to receive(:log_error)
|
97
102
|
$stderr = StringIO.new # slurp up the error output so we don't pollute the rspec run
|
98
|
-
CallbackHandler.
|
103
|
+
expect_any_instance_of(Gorgon::CallbackHandler).to receive(:before_originate).and_throw("I'm an unhandled exception")
|
99
104
|
|
100
105
|
expect { @originator.originate }.to raise_error(SystemExit) do |error|
|
101
|
-
error.success
|
106
|
+
expect(error.success?).to be_falsey
|
102
107
|
end
|
103
108
|
$stderr = STDERR
|
104
109
|
end
|
@@ -111,12 +116,12 @@ describe Originator do
|
|
111
116
|
|
112
117
|
it 'tells ShutdownManager to cancel_job' do
|
113
118
|
shutdown_manager = double('ShutdownManager')
|
114
|
-
JobState.
|
119
|
+
allow(Gorgon::JobState).to receive(:new).and_return job_state
|
115
120
|
|
116
|
-
ShutdownManager.
|
121
|
+
expect(Gorgon::ShutdownManager).to receive(:new).
|
117
122
|
with(hash_including(protocol: protocol, job_state: job_state)).
|
118
123
|
and_return(shutdown_manager)
|
119
|
-
shutdown_manager.
|
124
|
+
expect(shutdown_manager).to receive(:cancel_job)
|
120
125
|
|
121
126
|
@originator.publish
|
122
127
|
@originator.cancel_job
|
@@ -126,18 +131,18 @@ describe Originator do
|
|
126
131
|
describe "#cleanup_if_job_complete" do
|
127
132
|
before do
|
128
133
|
stub_methods
|
129
|
-
JobState.
|
134
|
+
allow(Gorgon::JobState).to receive(:new).and_return job_state
|
130
135
|
@originator.publish
|
131
136
|
end
|
132
137
|
|
133
138
|
it "calls JobState#is_job_complete?" do
|
134
|
-
job_state.
|
139
|
+
expect(job_state).to receive(:is_job_complete?).and_return false
|
135
140
|
@originator.cleanup_if_job_complete
|
136
141
|
end
|
137
142
|
|
138
143
|
it "disconnect if job is complete" do
|
139
|
-
job_state.
|
140
|
-
protocol.
|
144
|
+
allow(job_state).to receive(:is_job_complete?).and_return true
|
145
|
+
expect(protocol).to receive(:disconnect)
|
141
146
|
@originator.cleanup_if_job_complete
|
142
147
|
end
|
143
148
|
end
|
@@ -145,47 +150,51 @@ describe Originator do
|
|
145
150
|
describe "#handle_reply" do
|
146
151
|
before do
|
147
152
|
stub_methods
|
148
|
-
JobState.
|
153
|
+
allow(Gorgon::JobState).to receive(:new).and_return job_state
|
149
154
|
@originator.publish
|
150
155
|
end
|
151
156
|
|
152
157
|
it "returns SPEC_SUCCESS_EXIT_STATUS when payload[:action] is start" do
|
153
|
-
job_state.
|
154
|
-
@originator.handle_reply(start_payload).
|
158
|
+
allow(job_state).to receive(:file_started)
|
159
|
+
expect(@originator.handle_reply(start_payload)).to eq Gorgon::Originator::SPEC_SUCCESS_EXIT_STATUS
|
155
160
|
end
|
156
161
|
|
157
162
|
it "returns SPEC_SUCCESS_EXIT_STATUS when payload[:action] is finish" do
|
158
|
-
job_state.
|
159
|
-
@originator.handle_reply(finish_payload).
|
163
|
+
allow(job_state).to receive(:file_finished)
|
164
|
+
expect(@originator.handle_reply(finish_payload)).to eq Gorgon::Originator::SPEC_SUCCESS_EXIT_STATUS
|
160
165
|
end
|
161
166
|
|
162
167
|
it "returns SPEC_FAILURE_EXIT_STATUS when payload[:action] is crash" do
|
163
|
-
job_state.
|
164
|
-
@originator.handle_reply(Yajl::Encoder.encode(gorgon_crash_message)).
|
168
|
+
allow(job_state).to receive(:gorgon_crash_message)
|
169
|
+
expect(@originator.handle_reply(Yajl::Encoder.encode(gorgon_crash_message))).to eq Gorgon::Originator::SPEC_FAILURE_EXIT_STATUS
|
165
170
|
end
|
166
171
|
|
167
172
|
it "returns SPEC_FAILURE_EXIT_STATUS when payload[:action] is exception" do
|
168
|
-
|
173
|
+
silence_streams($stdout) do
|
174
|
+
expect(@originator.handle_reply(Yajl::Encoder.encode({:type => 'exception'}))).to eq Gorgon::Originator::SPEC_FAILURE_EXIT_STATUS
|
175
|
+
end
|
169
176
|
end
|
170
177
|
|
171
178
|
it "returns SPEC_FAILURE_EXIT_STATUS when payload[:action] is fail" do
|
172
|
-
|
179
|
+
silence_streams($stdout) do
|
180
|
+
expect(@originator.handle_reply(Yajl::Encoder.encode({:type => 'fail'}))).to eq Gorgon::Originator::SPEC_FAILURE_EXIT_STATUS
|
181
|
+
end
|
173
182
|
end
|
174
183
|
|
175
184
|
it "calls cleanup_if_job_complete" do
|
176
|
-
@originator.
|
185
|
+
expect(@originator).to receive(:cleanup_if_job_complete)
|
177
186
|
@originator.handle_reply finish_payload
|
178
187
|
end
|
179
188
|
|
180
189
|
it "calls JobState#file_started if payload[:action] is 'start'" do
|
181
190
|
Yajl::Parser.new(:symbolize_keys => true).parse(start_payload)
|
182
|
-
job_state.
|
191
|
+
expect(job_state).to receive(:file_started)
|
183
192
|
@originator.handle_reply(start_payload)
|
184
193
|
end
|
185
194
|
|
186
195
|
it "calls JobState#file_finished if payload[:action] is 'finish'" do
|
187
196
|
payload = Yajl::Parser.new(:symbolize_keys => true).parse(finish_payload)
|
188
|
-
job_state.
|
197
|
+
expect(job_state).to receive(:file_finished).with(payload)
|
189
198
|
@originator.handle_reply(finish_payload)
|
190
199
|
end
|
191
200
|
|
@@ -193,7 +202,7 @@ describe Originator do
|
|
193
202
|
:stdout => "some output", :stderr => "some errors"}}
|
194
203
|
|
195
204
|
it "calls JobState#gorgon_crash_message if payload[:type] is 'crash'" do
|
196
|
-
job_state.
|
205
|
+
expect(job_state).to receive(:gorgon_crash_message).with(gorgon_crash_message)
|
197
206
|
@originator.handle_reply(Yajl::Encoder.encode(gorgon_crash_message))
|
198
207
|
end
|
199
208
|
end
|
@@ -203,48 +212,48 @@ describe Originator do
|
|
203
212
|
stub_methods
|
204
213
|
@originator.publish
|
205
214
|
|
206
|
-
protocol.
|
215
|
+
expect(protocol).to receive(:publish_job_to_one).with(job_definition, 'abcd1234')
|
207
216
|
@originator.handle_new_listener_notification({:listener_queue_name => 'abcd1234'}.to_json)
|
208
217
|
end
|
209
218
|
end
|
210
219
|
|
211
220
|
describe "#job_definition" do
|
212
221
|
it "returns a JobDefinition object" do
|
213
|
-
@originator.
|
214
|
-
job_definition = JobDefinition.new
|
215
|
-
JobDefinition.
|
216
|
-
@originator.job_definition.
|
222
|
+
allow(@originator).to receive(:configuration).and_return configuration
|
223
|
+
job_definition = Gorgon::JobDefinition.new
|
224
|
+
expect(Gorgon::JobDefinition).to receive(:new).and_return job_definition
|
225
|
+
expect(@originator.job_definition).to equal job_definition
|
217
226
|
end
|
218
227
|
|
219
228
|
it "builds anonymous source_tree_path if it was not specified in the configuration" do
|
220
|
-
@originator.
|
221
|
-
Socket.
|
222
|
-
Dir.
|
229
|
+
allow(@originator).to receive(:configuration).and_return(configuration.merge(:file_server => {:host => 'host-name'}))
|
230
|
+
allow(Socket).to receive(:gethostname).and_return('my-host')
|
231
|
+
allow(Dir).to receive(:pwd).and_return('dir')
|
223
232
|
|
224
|
-
@originator.job_definition.sync[:source_tree_path].
|
233
|
+
expect(@originator.job_definition.sync[:source_tree_path]).to eq("rsync://host-name:43434/src/my-host_dir")
|
225
234
|
end
|
226
235
|
|
227
236
|
it "builds ssh source_tree_path if using ssh rsync transport" do
|
228
|
-
@originator.
|
237
|
+
allow(@originator).to receive(:configuration).and_return(configuration.merge(
|
229
238
|
:file_server => {:host => 'host-name'},
|
230
239
|
:job => { :sync => { :rsync_transport => 'ssh'}}
|
231
240
|
))
|
232
|
-
Socket.
|
233
|
-
Dir.
|
241
|
+
allow(Socket).to receive(:gethostname).and_return('my-host')
|
242
|
+
allow(Dir).to receive(:pwd).and_return('dir')
|
234
243
|
|
235
|
-
@originator.job_definition.sync[:source_tree_path].
|
244
|
+
expect(@originator.job_definition.sync[:source_tree_path]).to eq("host-name:my-host_dir")
|
236
245
|
end
|
237
246
|
end
|
238
247
|
|
239
248
|
private
|
240
249
|
|
241
250
|
def stub_methods
|
242
|
-
EventMachine.
|
243
|
-
ProgressBarView.
|
244
|
-
OriginatorProtocol.
|
245
|
-
@originator.
|
246
|
-
@originator.
|
247
|
-
@originator.
|
251
|
+
allow(EventMachine).to receive(:run).and_yield
|
252
|
+
allow(Gorgon::ProgressBarView).to receive(:new).and_return progress_bar_view
|
253
|
+
allow(Gorgon::OriginatorProtocol).to receive(:new).and_return protocol
|
254
|
+
allow(@originator).to receive(:configuration).and_return configuration
|
255
|
+
allow(@originator).to receive(:connection_information).and_return 'host'
|
256
|
+
allow(@originator).to receive(:job_definition).and_return job_definition
|
248
257
|
end
|
249
258
|
|
250
259
|
def start_payload
|
data/spec/ping_service_spec.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'gorgon/ping_service'
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe Gorgon::PingService do
|
4
4
|
describe "#ping_listeners" do
|
5
5
|
let(:configuration){ {:connection => {:host => "host"}, :originator_log_file => "file.log"}}
|
6
6
|
let(:protocol) { double("OriginatorProtocol", :connect => nil, :ping => nil,
|
@@ -9,34 +9,34 @@ describe "PingService" do
|
|
9
9
|
let(:logger){ double("Originator Logger", :log => nil, :log_message => nil)}
|
10
10
|
|
11
11
|
before do
|
12
|
-
$stdout.
|
13
|
-
PingService.
|
14
|
-
EventMachine.
|
15
|
-
EM.
|
16
|
-
OriginatorLogger.
|
12
|
+
allow($stdout).to receive(:write)
|
13
|
+
allow_any_instance_of(Gorgon::PingService).to receive(:load_configuration_from_file).and_return configuration
|
14
|
+
allow(EventMachine).to receive(:run).and_yield
|
15
|
+
allow(EM).to receive(:add_timer).and_yield
|
16
|
+
allow(Gorgon::OriginatorLogger).to receive(:new).and_return logger
|
17
17
|
end
|
18
18
|
|
19
19
|
it "connnects and calls OriginatorProtocol#send_message_to_listeners" do
|
20
|
-
OriginatorProtocol.
|
21
|
-
protocol.
|
22
|
-
protocol.
|
23
|
-
PingService.new.ping_listeners
|
20
|
+
expect(Gorgon::OriginatorProtocol).to receive(:new).once.ordered.and_return(protocol)
|
21
|
+
expect(protocol).to receive(:connect).once.ordered.with({:host => "host"}, anything)
|
22
|
+
expect(protocol).to receive(:send_message_to_listeners).once.ordered
|
23
|
+
Gorgon::PingService.new.ping_listeners
|
24
24
|
end
|
25
25
|
|
26
26
|
context "after sending ping messages" do
|
27
27
|
before do
|
28
|
-
OriginatorProtocol.
|
29
|
-
@service = PingService.new
|
28
|
+
allow(Gorgon::OriginatorProtocol).to receive(:new).and_return(protocol)
|
29
|
+
@service = Gorgon::PingService.new
|
30
30
|
end
|
31
31
|
|
32
32
|
it "adds an Event machine timer" do
|
33
|
-
EM.
|
33
|
+
expect(EM).to receive(:add_timer).and_yield
|
34
34
|
@service.ping_listeners
|
35
35
|
end
|
36
36
|
|
37
37
|
it "receives a ping_response message" do
|
38
38
|
payload = {:type => "ping_response", :hostname => "host", :version => "1.1.1"}
|
39
|
-
protocol.
|
39
|
+
expect(protocol).to receive(:receive_payloads).and_yield Yajl::Encoder.encode(payload)
|
40
40
|
@service.ping_listeners
|
41
41
|
end
|
42
42
|
end
|
data/spec/pipe_forker_spec.rb
CHANGED
@@ -1,53 +1,53 @@
|
|
1
1
|
require 'gorgon/pipe_forker'
|
2
2
|
|
3
|
-
describe PipeForker do
|
3
|
+
describe Gorgon::PipeForker do
|
4
4
|
let(:io_pipe) { double("IO object", :close => nil)}
|
5
5
|
let(:pipe) {double("Pipe", :write => io_pipe)}
|
6
6
|
|
7
7
|
let(:container_class) do
|
8
8
|
Class.new do
|
9
|
-
extend(PipeForker)
|
9
|
+
extend(Gorgon::PipeForker)
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
13
|
before do
|
14
|
-
IO.
|
15
|
-
STDIN.
|
16
|
-
container_class.
|
17
|
-
container_class.
|
14
|
+
allow(IO).to receive(:pipe).and_return([io_pipe, io_pipe])
|
15
|
+
allow(STDIN).to receive(:reopen)
|
16
|
+
allow(container_class).to receive(:fork).and_yield.and_return(1)
|
17
|
+
allow(container_class).to receive(:exit)
|
18
18
|
end
|
19
19
|
|
20
20
|
describe ".pipe_fork" do
|
21
21
|
it "creates a new pipe" do
|
22
|
-
IO.
|
22
|
+
expect(IO).to receive(:pipe).once.and_return ([io_pipe,io_pipe])
|
23
23
|
container_class.pipe_fork { }
|
24
24
|
end
|
25
25
|
|
26
26
|
it "forks once" do
|
27
|
-
container_class.
|
27
|
+
expect(container_class).to receive(:fork).and_yield
|
28
28
|
container_class.pipe_fork { }
|
29
29
|
end
|
30
30
|
|
31
31
|
it "closes both side of pipe inside child and read in parent" do
|
32
|
-
io_pipe.
|
32
|
+
expect(io_pipe).to receive(:close).exactly(3).times
|
33
33
|
container_class.pipe_fork { }
|
34
34
|
end
|
35
35
|
|
36
36
|
it "reopens stdin with a pipe" do
|
37
|
-
STDIN.
|
37
|
+
expect(STDIN).to receive(:reopen).with(io_pipe)
|
38
38
|
container_class.pipe_fork { }
|
39
39
|
end
|
40
40
|
|
41
41
|
it "yields" do
|
42
42
|
has_yielded = false
|
43
43
|
container_class.pipe_fork { has_yielded = true }
|
44
|
-
has_yielded.
|
44
|
+
expect(has_yielded).to be_truthy
|
45
45
|
end
|
46
46
|
|
47
47
|
it "returns pid of new process and a pipe" do
|
48
48
|
pid, stdin = container_class.pipe_fork { }
|
49
|
-
pid.
|
50
|
-
stdin.
|
49
|
+
expect(pid).to eq(1)
|
50
|
+
expect(stdin).to eq(io_pipe)
|
51
51
|
end
|
52
52
|
end
|
53
53
|
end
|
@@ -1,28 +1,28 @@
|
|
1
1
|
require 'gorgon/progress_bar_view'
|
2
2
|
require 'gorgon/job_state'
|
3
3
|
|
4
|
-
describe ProgressBarView do
|
4
|
+
describe Gorgon::ProgressBarView do
|
5
5
|
before do
|
6
|
-
EventMachine::PeriodicTimer.
|
6
|
+
allow(EventMachine::PeriodicTimer).to receive(:new)
|
7
7
|
end
|
8
8
|
|
9
9
|
describe "#initialize" do
|
10
10
|
it "adds itself to observers of job_state" do
|
11
|
-
job_state = JobState.new 1
|
12
|
-
job_state.
|
13
|
-
ProgressBarView.new job_state
|
11
|
+
job_state = Gorgon::JobState.new 1
|
12
|
+
expect(job_state).to receive(:add_observer)
|
13
|
+
Gorgon::ProgressBarView.new job_state
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
17
|
describe "#show" do
|
18
18
|
before do
|
19
|
-
job_state = JobState.new 1
|
20
|
-
@progress_bar_view = ProgressBarView.new job_state
|
19
|
+
job_state = Gorgon::JobState.new 1
|
20
|
+
@progress_bar_view = Gorgon::ProgressBarView.new job_state
|
21
21
|
end
|
22
22
|
|
23
23
|
it "prints in console gorgon's version and that is loading workers" do
|
24
|
-
$stdout.
|
25
|
-
ProgressBar.
|
24
|
+
expect($stdout).to receive(:write).with(/loading .*workers/i)
|
25
|
+
expect(ProgressBar).not_to receive(:create)
|
26
26
|
@progress_bar_view.show
|
27
27
|
end
|
28
28
|
end
|
@@ -37,64 +37,64 @@ describe ProgressBarView do
|
|
37
37
|
}
|
38
38
|
|
39
39
|
before do
|
40
|
-
ProgressBar.
|
41
|
-
@job_state = JobState.new 2
|
42
|
-
@job_state.
|
43
|
-
@progress_bar_view = ProgressBarView.new @job_state
|
44
|
-
$stdout.
|
40
|
+
allow(ProgressBar).to receive(:create).and_return progress_bar
|
41
|
+
@job_state = Gorgon::JobState.new 2
|
42
|
+
allow(@job_state).to receive(:state).and_return :running
|
43
|
+
@progress_bar_view = Gorgon::ProgressBarView.new @job_state
|
44
|
+
allow($stdout).to receive(:write)
|
45
45
|
@progress_bar_view.show
|
46
46
|
end
|
47
47
|
|
48
48
|
it "doesn't create ProgressBar if JobState is not running" do
|
49
|
-
@job_state.
|
50
|
-
ProgressBar.
|
49
|
+
expect(@job_state).to receive(:state).and_return :starting
|
50
|
+
expect(ProgressBar).not_to receive(:create).with(hash_including(:total => 2))
|
51
51
|
@progress_bar_view.update
|
52
52
|
end
|
53
53
|
|
54
54
|
it "doesn't create a ProgressBar if one was already created" do
|
55
55
|
@progress_bar_view.update
|
56
|
-
ProgressBar.
|
56
|
+
expect(ProgressBar).not_to receive(:create).with(hash_including(:total => 2))
|
57
57
|
@progress_bar_view.update
|
58
58
|
end
|
59
59
|
|
60
60
|
it "gets total files from JobState and create a ProgressBar once JobState is running" do
|
61
|
-
ProgressBar.
|
61
|
+
expect(ProgressBar).to receive(:create).with(hash_including(:total => 2))
|
62
62
|
@progress_bar_view.update
|
63
63
|
end
|
64
64
|
|
65
65
|
it "gets finished_files_count" do
|
66
|
-
@job_state.
|
66
|
+
expect(@job_state).to receive :finished_files_count
|
67
67
|
@progress_bar_view.update
|
68
68
|
end
|
69
69
|
|
70
70
|
it "gets failed_files_count" do
|
71
|
-
@job_state.
|
71
|
+
expect(@job_state).to receive(:failed_files_count).and_return 0
|
72
72
|
@progress_bar_view.update
|
73
73
|
end
|
74
74
|
|
75
75
|
it "prints failures and finish progress_bar when job is done" do
|
76
76
|
@progress_bar_view.update
|
77
|
-
@job_state.
|
78
|
-
@job_state.
|
79
|
-
$stdout.
|
77
|
+
allow(@job_state).to receive(:each_failed_test).and_yield(payload)
|
78
|
+
allow(@job_state).to receive(:is_job_complete?).and_return :true
|
79
|
+
expect($stdout).to receive(:write).with(/Failure messages/)
|
80
80
|
@progress_bar_view.update
|
81
81
|
end
|
82
82
|
|
83
83
|
context "when job is cancelled" do
|
84
84
|
before do
|
85
85
|
@progress_bar_view.update
|
86
|
-
@job_state.
|
86
|
+
allow(@job_state).to receive(:is_job_cancelled?).and_return :true
|
87
87
|
end
|
88
88
|
|
89
89
|
it "prints failures and finish progress_bar when job is cancelled" do
|
90
|
-
@job_state.
|
91
|
-
$stdout.
|
90
|
+
allow(@job_state).to receive(:each_failed_test).and_yield(payload)
|
91
|
+
expect($stdout).to receive(:write).with(/Failure messages/)
|
92
92
|
@progress_bar_view.update
|
93
93
|
end
|
94
94
|
|
95
95
|
it "prints files that were running when the job was cancelled" do
|
96
|
-
@job_state.
|
97
|
-
$stdout.
|
96
|
+
expect(@job_state).to receive(:each_running_file).and_yield("hostname", "file1.rb")
|
97
|
+
expect($stdout).to receive(:write).with(/file1\.rb.*hostname/)
|
98
98
|
@progress_bar_view.update
|
99
99
|
end
|
100
100
|
end
|
@@ -103,10 +103,10 @@ describe ProgressBarView do
|
|
103
103
|
let(:crash_message) {{:type => "crash", :hostname => "host",
|
104
104
|
:stdout => "some output", :stderr => "some errors"}}
|
105
105
|
it "prints info about crash in standard error" do
|
106
|
-
$stderr.
|
107
|
-
$stderr.
|
108
|
-
$stderr.
|
109
|
-
$stderr.
|
106
|
+
allow($stderr).to receive(:write)
|
107
|
+
expect($stderr).to receive(:write).with(/crash.*host/i)
|
108
|
+
expect($stderr).to receive(:write).with(/some output/i)
|
109
|
+
expect($stderr).to receive(:write).with(/some errors/i)
|
110
110
|
@progress_bar_view.update crash_message
|
111
111
|
end
|
112
112
|
end
|