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/gem_service_spec.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'gorgon/gem_service'
|
2
2
|
|
3
|
-
describe GemService do
|
3
|
+
describe Gorgon::GemService do
|
4
4
|
let(:configuration){ {:connection => {:host => "host"}, :originator_log_file => "file.log"}}
|
5
5
|
let(:protocol) { double("OriginatorProtocol", :connect => nil,
|
6
6
|
:receive_payloads => nil, :disconnect => nil,
|
@@ -8,46 +8,46 @@ describe GemService do
|
|
8
8
|
let(:logger){ double("Originator Logger", :log => nil, :log_message => nil)}
|
9
9
|
|
10
10
|
before do
|
11
|
-
$stdout.
|
12
|
-
GemService.
|
13
|
-
EM.
|
14
|
-
EM.
|
15
|
-
OriginatorLogger.
|
16
|
-
OriginatorProtocol.
|
17
|
-
@service = GemService.new
|
11
|
+
allow($stdout).to receive(:write)
|
12
|
+
allow_any_instance_of(Gorgon::GemService).to receive(:load_configuration_from_file).and_return configuration
|
13
|
+
allow(EM).to receive(:run).and_yield
|
14
|
+
allow(EM).to receive(:add_periodic_timer).and_yield
|
15
|
+
allow(Gorgon::OriginatorLogger).to receive(:new).and_return logger
|
16
|
+
allow(Gorgon::OriginatorProtocol).to receive(:new).and_return(protocol)
|
17
|
+
@service = Gorgon::GemService.new
|
18
18
|
@command = "install"
|
19
19
|
end
|
20
20
|
|
21
21
|
describe "#run" do
|
22
22
|
it "runs EventMachine loop and connect using configuration[:connection]" do
|
23
|
-
EM.
|
24
|
-
protocol.
|
23
|
+
expect(EM).to receive(:run)
|
24
|
+
expect(protocol).to receive(:connect).once.ordered.with({:host => "host"}, anything)
|
25
25
|
@service.run @command
|
26
26
|
end
|
27
27
|
|
28
28
|
it "calls Protocol#send_message_to_listeners with version number" do
|
29
|
-
protocol.
|
29
|
+
expect(protocol).to receive(:send_message_to_listeners).with(:gem_command, :gem_command => @command)
|
30
30
|
@service.run @command
|
31
31
|
end
|
32
32
|
|
33
33
|
it "adds a periodic timer that checks if there is any listener running command" do
|
34
|
-
EM.
|
34
|
+
expect(EM).to receive(:add_periodic_timer).with(Gorgon::GemService::TIMEOUT)
|
35
35
|
@service.run @command
|
36
36
|
end
|
37
37
|
|
38
38
|
context "when it receives an running_command message" do
|
39
39
|
before do
|
40
40
|
payload = {:type => "running_command", :hostname => "host"}
|
41
|
-
protocol.
|
41
|
+
allow(protocol).to receive(:receive_payloads).and_yield Yajl::Encoder.encode(payload)
|
42
42
|
end
|
43
43
|
|
44
44
|
it "writes to console" do
|
45
|
-
$stdout.
|
45
|
+
expect($stdout).to receive(:write).with(/host/)
|
46
46
|
@service.run @command
|
47
47
|
end
|
48
48
|
|
49
49
|
it "won't diconnect as long as there is a host running_command" do
|
50
|
-
protocol.
|
50
|
+
expect(protocol).not_to receive(:disconnect)
|
51
51
|
@service.run @command
|
52
52
|
end
|
53
53
|
end
|
@@ -56,17 +56,17 @@ describe GemService do
|
|
56
56
|
before do
|
57
57
|
running_command_payload = {:type => "running_command", :hostname => "host"}
|
58
58
|
complete_payload = {:type => "command_completed", :hostname => "host"}
|
59
|
-
protocol.
|
59
|
+
allow(protocol).to receive(:receive_payloads).and_yield(Yajl::Encoder.encode(running_command_payload))
|
60
60
|
.and_yield(Yajl::Encoder.encode(complete_payload))
|
61
61
|
end
|
62
62
|
|
63
63
|
it "writes to console" do
|
64
|
-
$stdout.
|
64
|
+
expect($stdout).to receive(:write).at_least(:twice).with(/host/)
|
65
65
|
@service.run @command
|
66
66
|
end
|
67
67
|
|
68
68
|
it "disconnect since there is no host running command anymore" do
|
69
|
-
protocol.
|
69
|
+
expect(protocol).to receive(:disconnect)
|
70
70
|
@service.run @command
|
71
71
|
end
|
72
72
|
end
|
@@ -22,53 +22,53 @@ describe RSpec::Core::Formatters::GorgonRspecFormatter do
|
|
22
22
|
end
|
23
23
|
|
24
24
|
it "returns an array of hashes when there are failures" do
|
25
|
-
@formatter.
|
25
|
+
allow(@formatter).to receive(:examples).and_return([example, fail_example])
|
26
26
|
|
27
27
|
expected_result = [{:test_name => "Full_Description: line 2", :description => "description",
|
28
28
|
:full_description => "Full_Description", :status => "failed",
|
29
29
|
:file_path => "path/to/file", :line_number => 2}]
|
30
|
-
output.
|
30
|
+
expect(output).to receive(:write).with(expected_result.to_json)
|
31
31
|
@formatter.stop
|
32
32
|
@formatter.close
|
33
33
|
end
|
34
34
|
|
35
35
|
it "returns an empty array when all examples pass" do
|
36
|
-
@formatter.
|
36
|
+
allow(@formatter).to receive(:examples).and_return([example, example])
|
37
37
|
|
38
|
-
output.
|
38
|
+
expect(output).to receive(:write).with("[]")
|
39
39
|
@formatter.stop
|
40
40
|
@formatter.close
|
41
41
|
end
|
42
42
|
|
43
43
|
it "returns an empty array when all examples are pending" do
|
44
|
-
example.
|
45
|
-
@formatter.
|
44
|
+
allow(example).to receive(:execution_result).and_return(:status => "pending")
|
45
|
+
allow(@formatter).to receive(:examples).and_return([example, example])
|
46
46
|
|
47
|
-
output.
|
47
|
+
expect(output).to receive(:write).with("[]")
|
48
48
|
@formatter.stop
|
49
49
|
@formatter.close
|
50
50
|
end
|
51
51
|
|
52
52
|
it "returns exception details if there is an exception" do
|
53
|
-
fail_example.
|
54
|
-
@formatter.
|
53
|
+
allow(fail_example).to receive(:exception).and_return(exception)
|
54
|
+
allow(@formatter).to receive(:examples).and_return([fail_example])
|
55
55
|
expected_result = [{:test_name => "Full_Description: line 2", :description => "description",
|
56
56
|
:full_description => "Full_Description", :status => "failed",
|
57
57
|
:file_path => "path/to/file", :line_number => 2, :class => Object.name,
|
58
58
|
:message => "some msg", :location => "backtrace"}]
|
59
|
-
output.
|
59
|
+
expect(output).to receive(:write).with(expected_result.to_json)
|
60
60
|
@formatter.stop
|
61
61
|
@formatter.close
|
62
62
|
end
|
63
63
|
|
64
64
|
it "uses RSpec 3 API when available" do
|
65
|
-
fail_example.execution_result.
|
65
|
+
expect(fail_example.execution_result).to receive(:status).and_return(:failed)
|
66
66
|
notification = double(examples: [fail_example])
|
67
67
|
|
68
68
|
expected_result = [{:test_name => "Full_Description: line 2", :description => "description",
|
69
69
|
:full_description => "Full_Description", :status => "failed",
|
70
70
|
:file_path => "path/to/file", :line_number => 2}]
|
71
|
-
output.
|
71
|
+
expect(output).to receive(:write).with(expected_result.to_json)
|
72
72
|
@formatter.stop(notification)
|
73
73
|
@formatter.close
|
74
74
|
end
|
data/spec/host_state_spec.rb
CHANGED
@@ -1,36 +1,36 @@
|
|
1
1
|
require 'gorgon/host_state'
|
2
2
|
|
3
|
-
describe HostState do
|
3
|
+
describe Gorgon::HostState do
|
4
4
|
it { should respond_to(:file_started).with(2).arguments }
|
5
5
|
it { should respond_to(:file_finished).with(2).arguments }
|
6
6
|
it { should respond_to(:each_running_file).with(0).argument }
|
7
7
|
it { should respond_to(:total_running_workers).with(0).argument }
|
8
8
|
|
9
9
|
before do
|
10
|
-
@host_state = HostState.new
|
10
|
+
@host_state = Gorgon::HostState.new
|
11
11
|
end
|
12
12
|
|
13
13
|
describe "#total_workers_running" do
|
14
14
|
it "returns 0 if there are no worker running files" do
|
15
|
-
@host_state.total_running_workers.
|
15
|
+
expect(@host_state.total_running_workers).to eq(0)
|
16
16
|
end
|
17
17
|
|
18
18
|
it "returns 1 if #file_started was called, but #file_finished has not been called with such a worker id" do
|
19
19
|
@host_state.file_started "worker1", "path/to/file.rb"
|
20
|
-
@host_state.total_running_workers.
|
20
|
+
expect(@host_state.total_running_workers).to eq(1)
|
21
21
|
end
|
22
22
|
|
23
23
|
it "returns 0 if #file_started and #file_finished were called for the same worker_id" do
|
24
24
|
@host_state.file_started "worker1", "path/to/file.rb"
|
25
25
|
@host_state.file_finished "worker1", "path/to/file.rb"
|
26
|
-
@host_state.total_running_workers.
|
26
|
+
expect(@host_state.total_running_workers).to eq(0)
|
27
27
|
end
|
28
28
|
|
29
29
|
it "returns 1 if #file_started and #file_finished were called for different worker id (worker1)" do
|
30
30
|
@host_state.file_started "worker1", "path/to/file.rb"
|
31
31
|
@host_state.file_started "worker2", "path/to/file2.rb"
|
32
32
|
@host_state.file_finished "worker2", "path/to/file2.rb"
|
33
|
-
@host_state.total_running_workers.
|
33
|
+
expect(@host_state.total_running_workers).to eq(1)
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
@@ -46,7 +46,7 @@ describe HostState do
|
|
46
46
|
@host_state.each_running_file do |file|
|
47
47
|
files << file
|
48
48
|
end
|
49
|
-
files.
|
49
|
+
expect(files).to eq(["path/to/file1.rb", "path/to/file2.rb"])
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
@@ -58,7 +58,7 @@ describe HostState do
|
|
58
58
|
@host_state.each_running_file do |file|
|
59
59
|
files << file
|
60
60
|
end
|
61
|
-
files.
|
61
|
+
expect(files).to eq(["path/to/file1.rb"])
|
62
62
|
end
|
63
63
|
end
|
64
64
|
end
|
data/spec/job_definition_spec.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'gorgon/job_definition'
|
2
2
|
require 'yajl'
|
3
3
|
|
4
|
-
describe JobDefinition do
|
4
|
+
describe Gorgon::JobDefinition do
|
5
5
|
before(:all) do
|
6
6
|
@json_parser = Yajl::Parser.new(:symbolize_keys => true)
|
7
7
|
end
|
@@ -16,9 +16,9 @@ describe JobDefinition do
|
|
16
16
|
:callbacks => {}
|
17
17
|
}
|
18
18
|
|
19
|
-
jd = JobDefinition.new(expected_hash)
|
19
|
+
jd = Gorgon::JobDefinition.new(expected_hash)
|
20
20
|
|
21
|
-
@json_parser.parse(jd.to_json).
|
21
|
+
expect(@json_parser.parse(jd.to_json)).to eq(expected_hash)
|
22
22
|
end
|
23
23
|
end
|
24
24
|
end
|
data/spec/job_state_spec.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'gorgon/job_state'
|
2
2
|
|
3
|
-
describe JobState do
|
3
|
+
describe Gorgon::JobState do
|
4
4
|
let(:payload) {
|
5
5
|
{:hostname => "host-name", :worker_id => "worker1", :filename => "path/file.rb",
|
6
6
|
:type => "pass", :failures => []}
|
@@ -8,7 +8,7 @@ describe JobState do
|
|
8
8
|
|
9
9
|
let (:host_state){ double("Host State", :file_started => nil, :file_finished => nil)}
|
10
10
|
|
11
|
-
subject { JobState.new 5 }
|
11
|
+
subject { Gorgon::JobState.new 5 }
|
12
12
|
it { should respond_to :failed_files_count }
|
13
13
|
it { should respond_to :finished_files_count }
|
14
14
|
it { should respond_to(:file_started).with(1).argument }
|
@@ -23,112 +23,112 @@ describe JobState do
|
|
23
23
|
it { should respond_to :is_job_cancelled? }
|
24
24
|
|
25
25
|
before do
|
26
|
-
@job_state = JobState.new 5
|
26
|
+
@job_state = Gorgon::JobState.new 5
|
27
27
|
end
|
28
28
|
|
29
29
|
describe "#initialize" do
|
30
30
|
it "sets total files for job" do
|
31
|
-
@job_state.total_files.
|
31
|
+
expect(@job_state.total_files).to eq(5)
|
32
32
|
end
|
33
33
|
|
34
34
|
it "sets remaining_files_count" do
|
35
|
-
@job_state.remaining_files_count.
|
35
|
+
expect(@job_state.remaining_files_count).to eq(5)
|
36
36
|
end
|
37
37
|
|
38
38
|
it "sets failed_files_count to 0" do
|
39
|
-
@job_state.failed_files_count.
|
39
|
+
expect(@job_state.failed_files_count).to eq(0)
|
40
40
|
end
|
41
41
|
|
42
42
|
it "set state to starting" do
|
43
|
-
@job_state.state.
|
43
|
+
expect(@job_state.state).to eq(:starting)
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
47
47
|
describe "#finished_files_count" do
|
48
48
|
it "returns total_files - remaining_files_count" do
|
49
|
-
@job_state.finished_files_count.
|
49
|
+
expect(@job_state.finished_files_count).to eq(0)
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
53
53
|
describe "#file_started" do
|
54
54
|
it "change state to running after first start_file_message is received" do
|
55
55
|
@job_state.file_started({})
|
56
|
-
@job_state.state.
|
56
|
+
expect(@job_state.state).to eq(:running)
|
57
57
|
end
|
58
58
|
|
59
59
|
it "creates a new HostState object if this is the first file started by 'hostname'" do
|
60
|
-
HostState.
|
60
|
+
expect(Gorgon::HostState).to receive(:new).and_return host_state
|
61
61
|
@job_state.file_started(payload)
|
62
62
|
end
|
63
63
|
|
64
64
|
it "doesn't create a new HostState object if this is not the first file started by 'hostname'" do
|
65
|
-
HostState.
|
65
|
+
allow(Gorgon::HostState).to receive(:new).and_return host_state
|
66
66
|
@job_state.file_started(payload)
|
67
|
-
HostState.
|
67
|
+
expect(Gorgon::HostState).not_to receive(:new)
|
68
68
|
@job_state.file_started(payload)
|
69
69
|
end
|
70
70
|
|
71
71
|
it "calls #file_started on HostState object representing 'hostname'" do
|
72
|
-
HostState.
|
73
|
-
host_state.
|
72
|
+
allow(Gorgon::HostState).to receive(:new).and_return host_state
|
73
|
+
expect(host_state).to receive(:file_started).with("worker_id", "file_name")
|
74
74
|
@job_state.file_started({:hostname => "hostname",
|
75
75
|
:worker_id => "worker_id",
|
76
76
|
:filename => "file_name"})
|
77
77
|
end
|
78
78
|
|
79
79
|
it "notify observers" do
|
80
|
-
@job_state.
|
81
|
-
@job_state.
|
80
|
+
expect(@job_state).to receive :notify_observers
|
81
|
+
expect(@job_state).to receive :changed
|
82
82
|
@job_state.file_started({})
|
83
83
|
end
|
84
84
|
end
|
85
85
|
|
86
86
|
describe "#file_finished" do
|
87
87
|
before do
|
88
|
-
HostState.
|
88
|
+
allow(Gorgon::HostState).to receive(:new).and_return host_state
|
89
89
|
@job_state.file_started payload
|
90
90
|
end
|
91
91
|
|
92
92
|
it "decreases remaining_files_count" do
|
93
|
-
lambda do
|
93
|
+
expect(lambda do
|
94
94
|
@job_state.file_finished payload
|
95
|
-
end.
|
95
|
+
end).to change{@job_state.remaining_files_count}.by(-1)
|
96
96
|
|
97
|
-
@job_state.total_files.
|
97
|
+
expect(@job_state.total_files).to eq(5)
|
98
98
|
end
|
99
99
|
|
100
100
|
it "doesn't change failed_files_count if type test result is pass" do
|
101
|
-
lambda do
|
101
|
+
expect(lambda do
|
102
102
|
@job_state.file_finished payload
|
103
|
-
end.
|
104
|
-
@job_state.failed_files_count.
|
103
|
+
end).not_to change{@job_state.failed_files_count}
|
104
|
+
expect(@job_state.failed_files_count).to eq(0)
|
105
105
|
end
|
106
106
|
|
107
107
|
it "increments failed_files_count if type is failed" do
|
108
|
-
lambda do
|
108
|
+
expect(lambda do
|
109
109
|
@job_state.file_finished payload.merge({:type => "fail", :failures => ["Failure messages"]})
|
110
|
-
end.
|
110
|
+
end).to change{@job_state.failed_files_count}.by(1)
|
111
111
|
end
|
112
112
|
|
113
113
|
it "notify observers" do
|
114
|
-
@job_state.
|
115
|
-
@job_state.
|
114
|
+
expect(@job_state).to receive :notify_observers
|
115
|
+
expect(@job_state).to receive :changed
|
116
116
|
@job_state.file_finished payload
|
117
117
|
end
|
118
118
|
|
119
119
|
it "raises if job already complete" do
|
120
120
|
finish_job
|
121
|
-
lambda do
|
121
|
+
expect(lambda do
|
122
122
|
@job_state.file_finished payload
|
123
|
-
end.
|
123
|
+
end).to raise_error(RuntimeError)
|
124
124
|
end
|
125
125
|
|
126
126
|
it "tells to the proper HostState object that a file finished in that host" do
|
127
|
-
HostState.
|
127
|
+
allow(Gorgon::HostState).to receive(:new).and_return host_state
|
128
128
|
@job_state.file_started({:hostname => "hostname",
|
129
129
|
:worker_id => "worker_id",
|
130
130
|
:filename => "file_name"})
|
131
|
-
host_state.
|
131
|
+
expect(host_state).to receive(:file_finished).with("worker_id", "file_name")
|
132
132
|
@job_state.file_finished({:hostname => "hostname",
|
133
133
|
:worker_id => "worker_id",
|
134
134
|
:filename => "file_name"})
|
@@ -141,37 +141,37 @@ describe JobState do
|
|
141
141
|
|
142
142
|
it "adds crashed host to JobState#crashed_hosted" do
|
143
143
|
@job_state.gorgon_crash_message(crash_msg)
|
144
|
-
@job_state.crashed_hosts.
|
144
|
+
expect(@job_state.crashed_hosts).to eq(["host"])
|
145
145
|
end
|
146
146
|
|
147
147
|
it "notify observers" do
|
148
|
-
@job_state.
|
149
|
-
@job_state.
|
148
|
+
expect(@job_state).to receive :notify_observers
|
149
|
+
expect(@job_state).to receive :changed
|
150
150
|
@job_state.gorgon_crash_message crash_msg
|
151
151
|
end
|
152
152
|
end
|
153
153
|
|
154
154
|
describe "#is_job_complete?" do
|
155
155
|
it "returns false if remaining_files_count != 0" do
|
156
|
-
@job_state.is_job_complete
|
156
|
+
expect(@job_state.is_job_complete?).to be_falsey
|
157
157
|
end
|
158
158
|
|
159
159
|
it "returns true if remaining_files_count == 0" do
|
160
160
|
finish_job
|
161
|
-
@job_state.is_job_complete
|
161
|
+
expect(@job_state.is_job_complete?).to be_truthy
|
162
162
|
end
|
163
163
|
end
|
164
164
|
|
165
165
|
describe "#cancel and is_job_cancelled?" do
|
166
166
|
it "cancels job" do
|
167
|
-
@job_state.is_job_cancelled
|
167
|
+
expect(@job_state.is_job_cancelled?).to be_falsey
|
168
168
|
@job_state.cancel
|
169
|
-
@job_state.is_job_cancelled
|
169
|
+
expect(@job_state.is_job_cancelled?).to be_truthy
|
170
170
|
end
|
171
171
|
|
172
172
|
it "notify observers when cancelling" do
|
173
|
-
@job_state.
|
174
|
-
@job_state.
|
173
|
+
expect(@job_state).to receive :changed
|
174
|
+
expect(@job_state).to receive :notify_observers
|
175
175
|
@job_state.cancel
|
176
176
|
end
|
177
177
|
end
|
@@ -184,7 +184,7 @@ describe JobState do
|
|
184
184
|
it "returns failed tests info" do
|
185
185
|
@job_state.file_finished payload.merge({:type => "fail", :failures => ["Failure messages"]})
|
186
186
|
@job_state.each_failed_test do |test|
|
187
|
-
test[:failures].
|
187
|
+
expect(test[:failures]).to eq(["Failure messages"])
|
188
188
|
end
|
189
189
|
end
|
190
190
|
end
|
@@ -202,9 +202,9 @@ describe JobState do
|
|
202
202
|
@job_state.each_running_file do |hostname, filename|
|
203
203
|
hosts_files[hostname] = filename
|
204
204
|
end
|
205
|
-
|
206
|
-
|
207
|
-
|
205
|
+
expect(hosts_files.size).to eq(2)
|
206
|
+
expect(hosts_files["host-name"]).to eq("path/file.rb")
|
207
|
+
expect(hosts_files["host2"]).to eq("path/file2.rb")
|
208
208
|
end
|
209
209
|
end
|
210
210
|
|
@@ -215,7 +215,7 @@ describe JobState do
|
|
215
215
|
@job_state.file_started payload.merge({ :hostname => "host2",
|
216
216
|
:filename => "path/file2.rb",
|
217
217
|
:worker_id => "worker1"})
|
218
|
-
@job_state.total_running_hosts.
|
218
|
+
expect(@job_state.total_running_hosts).to eq(2)
|
219
219
|
end
|
220
220
|
end
|
221
221
|
|
@@ -226,7 +226,7 @@ describe JobState do
|
|
226
226
|
@job_state.file_started payload.merge({ :hostname => "host2",
|
227
227
|
:filename => "path/file2.rb",
|
228
228
|
:worker_id => "worker1"})
|
229
|
-
@job_state.total_running_workers.
|
229
|
+
expect(@job_state.total_running_workers).to eq(3)
|
230
230
|
end
|
231
231
|
end
|
232
232
|
|