Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
23d0ddf
test-opt: convert 8 message specs to lightweight_spec_helper
johha Mar 2, 2026
4d60583
test-opt: convert 8 more message specs to lightweight_spec_helper
johha Mar 2, 2026
7a7e533
test-opt: convert 12 more message specs to lightweight_spec_helper
johha Mar 2, 2026
2af1bcc
test-opt: convert 10 more message specs to lightweight_spec_helper
johha Mar 2, 2026
4fa15d0
Fix db_spec_helper loading issues
johha Mar 2, 2026
3061be8
Convert 4 fetcher specs to use db_spec_helper
johha Mar 2, 2026
f9da616
Convert 9 more fetcher specs to use db_spec_helper
johha Mar 2, 2026
47b56eb
Convert 11 presenter specs to use db_spec_helper
johha Mar 2, 2026
2f69bf2
Convert 4 decorator/repository specs to use db_spec_helper
johha Mar 2, 2026
870056e
Split apps_spec.rb into 8 smaller files for better parallelization
johha Mar 2, 2026
67690e9
Split routes_spec.rb into 6 smaller files for better parallelization
johha Mar 2, 2026
09b217d
Revert file splits - no benefit without CI parallelization changes
johha Mar 2, 2026
e101b03
Convert 14 more message specs to lightweight_spec_helper
johha Mar 2, 2026
e85dca1
Fix Config stub to not conflict with spec_helper
johha Mar 2, 2026
9bc28c1
Optimize spec_helper: skip Fog reset for most tests
johha Mar 2, 2026
daf0d9d
Revert "Optimize spec_helper: skip Fog reset for most tests"
johha Mar 3, 2026
99b2c57
Use fog_spec_helper for blobstore specs needing clean state
johha Mar 3, 2026
28fb5ac
Remove legacy Spork code from spec_helper
johha Mar 3, 2026
34d3c36
Optimize TestConfig.reset to only run when context changes
johha Mar 3, 2026
ca82922
Revert "Optimize TestConfig.reset to only run when context changes"
johha Mar 3, 2026
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
1 change: 1 addition & 0 deletions lib/cloud_controller/diego/reporters/instances_reporter.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require 'utils/workpool'
require 'cloud_controller/diego/reporters/reporter_mixins'
require 'cloud_controller/diego/constants'
require 'diego/lrp_constants'

module VCAP::CloudController
Expand Down
4 changes: 4 additions & 0 deletions spec/db_spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
require 'rspec/collection_matchers'

require 'rails'
require 'oj'
require 'sequel'
Sequel.default_timezone = :utc

require 'support/bootstrap/spec_bootstrap'
require 'support/database_isolation'
require 'sequel_plugins/sequel_plugins'
Expand Down
21 changes: 21 additions & 0 deletions spec/fog_spec_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Use this helper for specs that need Fog/blobstore functionality with
# a clean state between tests (upload, download, delete operations).
#
# This helper resets Fog mocks and recreates buckets before each test.
#
# For specs that don't need blobstore isolation, use spec_helper instead.

require 'spec_helper'

RSpec.configure do |config|
config.before(:each, :fog_isolation) do
Fog::Mock.reset

if Fog.mock?
CloudController::DependencyLocator.instance.droplet_blobstore.ensure_bucket_exists
CloudController::DependencyLocator.instance.package_blobstore.ensure_bucket_exists
CloudController::DependencyLocator.instance.global_app_bits_cache.ensure_bucket_exists
CloudController::DependencyLocator.instance.buildpack_blobstore.ensure_bucket_exists
end
end
end
30 changes: 30 additions & 0 deletions spec/lightweight_spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,24 @@
$LOAD_PATH.push(File.expand_path(File.join(__dir__, '..', 'lib')))

require 'active_support/all'
require 'active_model'
require 'pry'
# So that specs using this helper don't fail with undefined constant error
module VCAP
module CloudController
# Minimal Config stub for message validation specs
# Only define if not already defined (avoid conflict with spec_helper)
unless defined?(Config)
class Config
def self.config
@config ||= new
end

def get(*_keys)
nil
end
end
end
end
end

Expand Down Expand Up @@ -34,3 +48,19 @@ def get(key)
RSpec.configure do |rspec_config|
rspec_config.expose_dsl_globally = false
end

# errors_on helper from rspec-collection_matchers gem
# Enables: expect(message.errors_on(:attribute)).to include("error message")
# This extension is added when ActiveModel::Validations is loaded
if defined?(ActiveModel::Validations)
module ::ActiveModel::Validations
def errors_on(attribute, options={})
valid_args = [options[:context]].compact
valid?(*valid_args)

[errors[attribute]].flatten.compact
end

alias_method :error_on, :errors_on
end
end
74 changes: 11 additions & 63 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,6 @@
require 'rubygems'
require 'mock_redis'

begin
require 'spork'
# uncomment the following line to use spork with the debugger
# require 'spork/ext/ruby-debug'

run_spork = !`ps | grep spork | grep -v grep`.empty?
rescue LoadError
run_spork = false
end

# --- Instructions ---
# Sort the contents of this file into a Spork.prefork and a Spork.each_run
# block.
#
# The Spork.prefork block is run only once when the spork server is started.
# You typically want to place most of your (slow) initializer code in here, in
# particular, require'ing any 3rd-party gems that you don't normally modify
# during development.
#
# The Spork.each_run block is run each time you run your specs. In case you
# need to load files that tend to change during development, require them here.
# With Rails, your application modules are loaded automatically, so sometimes
# this block can remain empty.
#
# Note: You can modify files loaded *from* the Spork.each_run block without
# restarting the spork server. However, this file itself will not be reloaded,
# so if you change any of the code inside the each_run block, you still need to
# restart the server. In general, if you have non-trivial code in this file,
# it's advisable to move it into a separate file so you can easily edit it
# without restarting spork. (For example, with RSpec, you could move
# non-trivial code into a file spec/support/my_helper.rb, making sure that the
# spec/support/* files are require'd from inside the each_run block.)
#
# Any code that is left outside the two blocks will be run during preforking
# *and* during each_run -- that's probably not what you want.
#
# These instructions should self-destruct in 10 seconds. If they don't, feel
# free to delete them.

init_block = proc do
$LOAD_PATH.push(File.expand_path(__dir__))

Expand Down Expand Up @@ -159,6 +120,15 @@
# calling this more than once will load tasks again and 'invoke' or 'execute' calls
# will call rake tasks multiple times
Application.load_tasks

# Initialize Fog mock buckets once at suite start.
# Tests that need isolated/clean Fog state should use fog_spec_helper.
if Fog.mock?
CloudController::DependencyLocator.instance.droplet_blobstore.ensure_bucket_exists
CloudController::DependencyLocator.instance.package_blobstore.ensure_bucket_exists
CloudController::DependencyLocator.instance.global_app_bits_cache.ensure_bucket_exists
CloudController::DependencyLocator.instance.buildpack_blobstore.ensure_bucket_exists
end
end

rspec_config.before do
Expand All @@ -169,15 +139,6 @@
TestConfig.context = example.metadata[:job_context] || :api
TestConfig.reset

Fog::Mock.reset

if Fog.mock?
CloudController::DependencyLocator.instance.droplet_blobstore.ensure_bucket_exists
CloudController::DependencyLocator.instance.package_blobstore.ensure_bucket_exists
CloudController::DependencyLocator.instance.global_app_bits_cache.ensure_bucket_exists
CloudController::DependencyLocator.instance.buildpack_blobstore.ensure_bucket_exists
end

VCAP::CloudController::SecurityContext.clear
VCAP::Request.current_id = nil
allow_any_instance_of(VCAP::CloudController::UaaTokenDecoder).to receive(:uaa_issuer).and_return(UAAIssuer::ISSUER)
Expand Down Expand Up @@ -219,18 +180,5 @@
end
end

if run_spork
Spork.prefork do
# Loading more in this block will cause your tests to run faster. However,
# if you change any configuration or code from libraries loaded here, you'll
# need to restart spork for it to take effect.
init_block.call
end
Spork.each_run do
# This code will be run each time you run your specs.
each_run_block.call
end
else
init_block.call
each_run_block.call
end
init_block.call
each_run_block.call
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
require 'spec_helper'
require 'fog_spec_helper'

## NOTICE: Prefer request specs over controller specs as per ADR #0003 ##

module VCAP::CloudController
RSpec.describe VCAP::CloudController::BuildpackBitsController do
RSpec.describe VCAP::CloudController::BuildpackBitsController, :fog_isolation do
let(:user) { make_user }
let(:filename) { 'file.zip' }
let(:sha_valid_zip) { Digester.new(algorithm: OpenSSL::Digest::SHA256).digest_file(valid_zip) }
Expand Down
4 changes: 2 additions & 2 deletions spec/unit/controllers/runtime/buildpacks_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
require 'spec_helper'
require 'fog_spec_helper'

## NOTICE: Prefer request specs over controller specs as per ADR #0003 ##

module VCAP::CloudController
RSpec.describe VCAP::CloudController::BuildpacksController do
RSpec.describe VCAP::CloudController::BuildpacksController, :fog_isolation do
def ordered_buildpacks
Buildpack.order(:position).map { |bp| [bp.name, bp.position] }
end
Expand Down
4 changes: 2 additions & 2 deletions spec/unit/controllers/runtime/stagings_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'spec_helper'
require 'fog_spec_helper'

## NOTICE: Prefer request specs over controller specs as per ADR #0003 ##

Expand Down Expand Up @@ -164,7 +164,7 @@ module VCAP::CloudController
end
end

RSpec.describe StagingsController do
RSpec.describe StagingsController, :fog_isolation do
let(:timeout_in_seconds) { 120 }
let(:cc_addr) { '1.2.3.4' }
let(:cc_port) { 5678 }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'spec_helper'
require 'db_spec_helper'
require 'decorators/embed_process_instances_decorator'

module VCAP::CloudController
RSpec.describe EmbedProcessInstancesDecorator do
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'spec_helper'
require 'db_spec_helper'
require 'decorators/field_service_offering_service_broker_decorator'
require 'field_decorator_spec_shared_examples'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'spec_helper'
require 'db_spec_helper'
require 'decorators/field_service_plan_service_broker_decorator'
require 'field_decorator_spec_shared_examples'

Expand Down
2 changes: 1 addition & 1 deletion spec/unit/fetchers/app_fetcher_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'spec_helper'
require 'db_spec_helper'
require 'fetchers/app_fetcher'

module VCAP::CloudController
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/fetchers/assign_current_droplet_fetcher_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'spec_helper'
require 'db_spec_helper'
require 'fetchers/assign_current_droplet_fetcher'

module VCAP::CloudController
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/fetchers/base_list_fetcher_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'spec_helper'
require 'db_spec_helper'
require 'messages/events_list_message'
require 'fetchers/event_list_fetcher'

Expand Down
2 changes: 1 addition & 1 deletion spec/unit/fetchers/build_list_fetcher_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'spec_helper'
require 'db_spec_helper'
require 'messages/builds_list_message'
require 'fetchers/build_list_fetcher'

Expand Down
2 changes: 1 addition & 1 deletion spec/unit/fetchers/droplet_fetcher_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'spec_helper'
require 'db_spec_helper'
require 'fetchers/droplet_fetcher'

module VCAP::CloudController
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/fetchers/event_list_fetcher_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'spec_helper'
require 'db_spec_helper'
require 'messages/events_list_message'
require 'fetchers/event_list_fetcher'

Expand Down
2 changes: 1 addition & 1 deletion spec/unit/fetchers/organization_quota_list_fetcher_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'spec_helper'
require 'db_spec_helper'
require 'fetchers/organization_quota_list_fetcher'
require 'messages/organization_quotas_list_message'

Expand Down
2 changes: 1 addition & 1 deletion spec/unit/fetchers/organization_user_roles_fetcher_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'spec_helper'
require 'db_spec_helper'
require 'fetchers/organization_user_roles_fetcher'

module VCAP::CloudController
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/fetchers/package_fetcher_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'spec_helper'
require 'db_spec_helper'
require 'fetchers/package_fetcher'

module VCAP::CloudController
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/fetchers/process_fetcher_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'spec_helper'
require 'db_spec_helper'
require 'fetchers/process_fetcher'

module VCAP::CloudController
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/fetchers/route_destinations_list_fetcher_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'spec_helper'
require 'db_spec_helper'
require 'fetchers/route_destinations_list_fetcher'
require 'messages/route_destinations_list_message'

Expand Down
2 changes: 1 addition & 1 deletion spec/unit/fetchers/service_binding_list_fetcher_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'spec_helper'
require 'db_spec_helper'
require 'fetchers/service_binding_list_fetcher'

module VCAP::CloudController
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/fetchers/space_quota_list_fetcher_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'spec_helper'
require 'db_spec_helper'
require 'fetchers/space_quota_list_fetcher'
require 'messages/space_quotas_list_message'

Expand Down
4 changes: 2 additions & 2 deletions spec/unit/jobs/runtime/blobstore_delete_spec.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
require 'spec_helper'
require 'fog_spec_helper'

module VCAP::CloudController
module Jobs::Runtime
RSpec.describe BlobstoreDelete, job_context: :worker do
RSpec.describe BlobstoreDelete, :fog_isolation, job_context: :worker do
let(:key) { 'key' }
subject(:job) do
BlobstoreDelete.new(key, :droplet_blobstore)
Expand Down
4 changes: 2 additions & 2 deletions spec/unit/jobs/runtime/blobstore_upload_spec.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
require 'spec_helper'
require 'fog_spec_helper'

module VCAP::CloudController
module Jobs::Runtime
RSpec.describe BlobstoreUpload, job_context: :worker do
RSpec.describe BlobstoreUpload, :fog_isolation, job_context: :worker do
let(:local_file) { Tempfile.new('tmpfile') }
let(:blobstore_key) { 'key' }
let(:blobstore_name) { :droplet_blobstore }
Expand Down
4 changes: 2 additions & 2 deletions spec/unit/jobs/runtime/buildpack_cache_cleanup_spec.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
require 'spec_helper'
require 'fog_spec_helper'

module VCAP::CloudController
module Jobs::Runtime
RSpec.describe BuildpackCacheCleanup, job_context: :worker do
RSpec.describe BuildpackCacheCleanup, :fog_isolation, job_context: :worker do
let(:cc_addr) { '1.2.3.4' }
let(:cc_port) { 5678 }
let(:orphan_key) { 'orphan-key' }
Expand Down
4 changes: 2 additions & 2 deletions spec/unit/jobs/v3/buildpack_cache_cleanup_spec.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
require 'spec_helper'
require 'fog_spec_helper'

module VCAP::CloudController
module Jobs::V3
RSpec.describe BuildpackCacheCleanup, job_context: :worker do
RSpec.describe BuildpackCacheCleanup, :fog_isolation, job_context: :worker do
let(:cc_addr) { '1.2.3.4' }
let(:cc_port) { 5678 }
let(:orphan_key) { 'orphan-key' }
Expand Down
4 changes: 2 additions & 2 deletions spec/unit/jobs/v3/buildpack_cache_delete_spec.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
require 'spec_helper'
require 'fog_spec_helper'
require 'jobs/v3/buildpack_cache_delete'

module VCAP::CloudController
module Jobs::V3
RSpec.describe BuildpackCacheDelete, job_context: :worker do
RSpec.describe BuildpackCacheDelete, :fog_isolation, job_context: :worker do
let(:app_guid) { 'some-guid' }
let(:local_dir) { Dir.mktmpdir }
let!(:blobstore) do
Expand Down
4 changes: 2 additions & 2 deletions spec/unit/jobs/v3/buildpack_cache_upload_spec.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
require 'spec_helper'
require 'fog_spec_helper'

module VCAP::CloudController
module Jobs::V3
RSpec.describe BuildpackCacheUpload, job_context: :api do
RSpec.describe BuildpackCacheUpload, :fog_isolation, job_context: :api do
subject(:job) { BuildpackCacheUpload.new(local_path: local_file.path, app_guid: app.guid, stack_name: 'some-stack') }

let(:app) { AppModel.make(:buildpack) }
Expand Down
4 changes: 2 additions & 2 deletions spec/unit/jobs/v3/droplet_bits_copier_spec.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
require 'spec_helper'
require 'fog_spec_helper'

module VCAP::CloudController
module Jobs::V3
RSpec.describe DropletBitsCopier do
RSpec.describe DropletBitsCopier, :fog_isolation do
subject(:job) { DropletBitsCopier.new(source_droplet.guid, destination_droplet.guid) }

let(:droplet_bits_path) { File.expand_path('../../../fixtures/good.zip', File.dirname(__FILE__)) }
Expand Down
Loading
Loading