Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restructure runner spec #3462

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 50 additions & 50 deletions spec/unit/lib/cloud_controller/runner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module VCAP::CloudController
let(:valid_config_file_path) { File.join(Paths::CONFIG, 'cloud_controller.yml') }
let(:config_file) { File.new(valid_config_file_path) }
let(:periodic_updater) { instance_double(VCAP::CloudController::Metrics::PeriodicUpdater) }
let(:request_metrics) { instance_double(VCAP::CloudController::Metrics::RequestMetrics) }
let(:routing_api_client) { instance_double(VCAP::CloudController::RoutingApi::Client, router_group_guid: '') }

let(:argv) { [] }
Expand All @@ -14,6 +15,7 @@ module VCAP::CloudController
allow(CloudController::DependencyLocator.instance).to receive(:routing_api_client).and_return(routing_api_client)
allow(EM).to receive(:run).and_yield
allow(VCAP::CloudController::Metrics::PeriodicUpdater).to receive(:new).and_return(periodic_updater)
allow(VCAP::CloudController::Metrics::RequestMetrics).to receive(:new).and_return(request_metrics)
allow(periodic_updater).to receive(:setup_updates)
allow(VCAP::PidFile).to receive(:new) { double(:pidfile, unlink_at_exit: nil) }
allow_any_instance_of(VCAP::CloudController::ThinRunner).to receive(:start!)
Expand All @@ -26,7 +28,42 @@ module VCAP::CloudController
describe '#run!' do
it 'creates a pidfile' do
expect(VCAP::PidFile).to receive(:new).with('/tmp/cloud_controller.pid')

subject.run!
end

it 'starts the web server' do
server = double(:server)
allow(server).to receive(:start!)
expect(VCAP::CloudController::ThinRunner).to receive(:new).and_return(server)

subject.run!
expect(server).to have_received(:start!).once
end
end

describe '#initialize' do
before do
allow_any_instance_of(Runner).to receive(:deprecation_warning)
end

describe 'web server selection' do
context 'when thin is specifed' do
it 'chooses ThinRunner as the web server' do
expect(subject.instance_variable_get(:@server)).to be_an_instance_of(ThinRunner)
end
end

context 'when puma is specified' do
before do
TestConfig.override(webserver: 'puma')
allow(Config).to receive(:load_from_file).and_return(TestConfig.config_instance)
end

it 'chooses puma as the web server' do
expect(subject.instance_variable_get(:@server)).to be_an_instance_of(PumaRunner)
end
end
end

it 'registers a log counter with the component' do
Expand All @@ -37,24 +74,24 @@ module VCAP::CloudController
expect(steno_config.sinks).to include log_counter
end

subject.run!
subject
end

it 'sets up database' do
expect(DB).to receive(:load_models)
subject.run!
subject
end

it 'configures components' do
expect_any_instance_of(Config).to receive(:configure_components)
subject.run!
subject
end

it 'sets up loggregator emitter' do
loggregator_emitter = double(:loggregator_emitter)
expect(LoggregatorEmitter::Emitter).to receive(:new).and_return(loggregator_emitter)
expect(VCAP::AppLogEmitter).to receive(:emitter=).with(loggregator_emitter)
subject.run!
subject
end

context 'when fluent is configured' do
Expand All @@ -74,7 +111,7 @@ module VCAP::CloudController
it 'sets up fluent emitter' do
expect(::Fluent::Logger::FluentLogger).to receive(:new).and_return(fluent_logger)
expect(VCAP::AppLogEmitter).to receive(:fluent_emitter=).with(instance_of(VCAP::FluentEmitter))
subject.run!
subject
end
end

Expand All @@ -83,14 +120,14 @@ module VCAP::CloudController
allow(RackAppBuilder).to receive(:new).and_return(builder)
request_logs = double(:request_logs)
allow(VCAP::CloudController::Logs::RequestLogs).to receive(:new).and_return(request_logs)
expect(builder).to receive(:build).with(anything, instance_of(VCAP::CloudController::Metrics::RequestMetrics),
expect(builder).to receive(:build).with(anything, request_metrics,
request_logs)
subject.run!
subject
end

it 'sets a local ip in the host system' do
expect_any_instance_of(VCAP::HostSystem).to receive(:local_ip).and_return('some_local_ip')
subject.run!
subject
end

it 'sets up logging before creating a logger' do
Expand All @@ -110,27 +147,15 @@ module VCAP::CloudController
logger
end

subject.run!
subject

expect(logging_configuration_time).to be < logger_creation_time
end

it 'only sets up logging once' do
steno_configurer = instance_double(StenoConfigurer)
allow(StenoConfigurer).to receive(:new).and_return(steno_configurer)
allow(steno_configurer).to receive(:configure)

subject.run!
subject.run!

expect(steno_configurer).to have_received(:configure).once
end

it 'sets up telemetry logging once' do
it 'sets up telemetry logging' do
allow(TelemetryLogger).to receive(:init)

subject.run!
subject.run!
subject
philippthun marked this conversation as resolved.
Show resolved Hide resolved

expect(TelemetryLogger).to have_received(:init).once
end
Expand All @@ -148,7 +173,7 @@ module VCAP::CloudController
it 'sets up telemetry logging with nil logger' do
allow(TelemetryLogger).to receive(:init)

subject.run!
subject

expect(TelemetryLogger).not_to have_received(:init)
end
Expand All @@ -165,38 +190,13 @@ module VCAP::CloudController
expect(CloudController::DependencyLocator.instance).to receive(:global_app_bits_cache).and_return(resource_blobstore)
expect(CloudController::DependencyLocator.instance).to receive(:buildpack_blobstore).and_return(buildpack_blobstore)

subject.run!
subject

expect(droplet_blobstore).to have_received(:ensure_bucket_exists)
expect(package_blobstore).to have_received(:ensure_bucket_exists)
expect(resource_blobstore).to have_received(:ensure_bucket_exists)
expect(buildpack_blobstore).to have_received(:ensure_bucket_exists)
end
end

describe '#initialize' do
before do
allow_any_instance_of(Runner).to receive(:deprecation_warning)
end

describe 'web server selection' do
context 'when thin is specifed' do
it 'chooses ThinRunner as the web server' do
expect(subject.instance_variable_get(:@server)).to be_an_instance_of(ThinRunner)
end
end

context 'when puma is specified' do
before do
TestConfig.override(webserver: 'puma')
allow(Config).to receive(:load_from_file).and_return(TestConfig.config_instance)
end

it 'chooses puma as the web server' do
expect(subject.instance_variable_get(:@server)).to be_an_instance_of(PumaRunner)
end
end
end

describe 'argument parsing' do
subject { Runner.new(argv_options) }
Expand Down