-
Notifications
You must be signed in to change notification settings - Fork 361
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Don't unnecessarily load all models in stack check (#3941)
Don't unnecessarily load all models in stack check * loading all models can cause issues in cases where the table for a model does not yet exist Co-authored-by: Alex Rocha <alex.rocha@broadcom.com> Co-authored-by: Sam Gunaratne <385176+Samze@users.noreply.github.com>
- Loading branch information
1 parent
c352e03
commit 99b4a78
Showing
6 changed files
with
98 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
require 'spec_helper' | ||
require 'tasks/rake_config' | ||
require 'cloud_controller/check_stacks' | ||
|
||
RSpec.describe 'stack_check' do | ||
let(:stack_file_contents) do | ||
{ | ||
'default' => 'cflinuxfs4', | ||
'stacks' => [ | ||
cflinuxfs4 | ||
], | ||
'deprecated_stacks' => ['cflinuxfs3'] | ||
} | ||
end | ||
|
||
let(:cflinuxfs4) { { 'name' => 'cflinuxfs4', 'description' => 'fs4' } } | ||
|
||
let(:db_double) do | ||
dbl = double('db') | ||
allow(dbl).to receive(:table_exists?).and_return(true) | ||
dbl | ||
end | ||
|
||
before do | ||
file = Tempfile.new | ||
file.write(stack_file_contents.to_yaml) | ||
file.close | ||
TestConfig.override(stacks_file: file.path) | ||
allow(RakeConfig).to receive(:config).and_return(TestConfig.config_instance) | ||
end | ||
|
||
it 'does not load all models' do | ||
expect(VCAP::CloudController::DB).not_to receive(:load_models_without_migrations_check) | ||
expect(VCAP::CloudController::DB).not_to receive(:load_models) | ||
Rake::Task['stacks:stack_check'].execute | ||
end | ||
|
||
context 'stacks' do | ||
context 'when stacks table doesnt exist' do | ||
before do | ||
allow(db_double).to receive(:table_exists?).with(:stacks).and_return false | ||
allow(VCAP::CloudController::DB).to receive(:connect).and_return(db_double) | ||
end | ||
|
||
it 'does nothing' do | ||
expect_any_instance_of(VCAP::CloudController::CheckStacks).not_to receive(:validate_stacks) | ||
Rake::Task['stacks:stack_check'].execute | ||
end | ||
end | ||
|
||
context 'when stacks table does exist' do | ||
before do | ||
allow(db_double).to receive(:table_exists?).with(:stacks).and_return true | ||
allow(VCAP::CloudController::DB).to receive(:connect).and_return(db_double) | ||
end | ||
|
||
it 'validates stacks' do | ||
expect_any_instance_of(VCAP::CloudController::CheckStacks).to receive(:validate_stacks).and_call_original | ||
Rake::Task['stacks:stack_check'].execute | ||
end | ||
end | ||
end | ||
|
||
context 'buildpack_lifecycle_data' do | ||
context 'when buildpack_lifecycle_data table doesnt exist' do | ||
before do | ||
allow(db_double).to receive(:table_exists?).with(:buildpack_lifecycle_data).and_return false | ||
allow(VCAP::CloudController::DB).to receive(:connect).and_return(db_double) | ||
end | ||
|
||
it 'does nothing' do | ||
expect_any_instance_of(VCAP::CloudController::CheckStacks).not_to receive(:validate_stacks) | ||
Rake::Task['stacks:stack_check'].execute | ||
end | ||
end | ||
|
||
context 'when buildpack_lifecycle_data table does exist' do | ||
before do | ||
allow(double).to receive(:table_exists?).with(:buildpack_lifecycle_data).and_return true | ||
allow(VCAP::CloudController::DB).to receive(:connect).and_return(db_double) | ||
end | ||
|
||
it 'validates stacks' do | ||
expect_any_instance_of(VCAP::CloudController::CheckStacks).to receive(:validate_stacks).and_call_original | ||
Rake::Task['stacks:stack_check'].execute | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters