Skip to content

Commit

Permalink
fix deployment runner spec
Browse files Browse the repository at this point in the history
  • Loading branch information
tyiuhc committed Aug 2, 2024
1 parent f8ed086 commit 6660141
Showing 1 changed file with 22 additions and 34 deletions.
56 changes: 22 additions & 34 deletions spec/experiment/deployment/deployment_runner_spec.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
require 'rspec'
require 'logger'

module AmplitudeExperiment
describe DeploymentRunner do
let(:cohort_id) { '1234' }
before(:each) do
@flag = {
let(:flag) do
{
'key' => 'flag',
'variants' => {},
'segments' => [
Expand All @@ -22,45 +24,32 @@ module AmplitudeExperiment
}
end

let(:flag_fetcher) { double('LocalEvaluationFetcher') }
let(:cohort_download_api) { double('CohortLoader') }
let(:flag_config_storage) { double('FlagConfigStorage') }
let(:cohort_storage) { double('CohortStorage') }
let(:logger) { Logger.new($stdout) }
let(:cohort_loader) { CohortLoader.new(cohort_download_api, cohort_storage) }
let(:runner) do
DeploymentRunner.new(
LocalEvaluationConfig.new,
flag_fetcher,
flag_config_storage,
cohort_storage,
logger,
cohort_loader
)
end

describe '#start' do
it 'throws an error if the first flag config load fails' do
flag_fetcher = double('LocalEvaluationFetcher')
cohort_download_api = double('CohortLoader')
flag_config_storage = double('FlagConfigStorage')
cohort_storage = double('CohortStorage')
cohort_loader = CohortLoader.new(cohort_download_api, cohort_storage)
logger = Logger.new($stdout)
runner = DeploymentRunner.new(
LocalEvaluationConfig.new,
flag_fetcher,
flag_config_storage,
cohort_storage,
logger,
cohort_loader
)

allow(flag_fetcher).to receive(:fetch_v2).and_raise(RuntimeError, 'test')

expect { runner.start }.to raise_error(RuntimeError, 'test')
end

it 'does not raise an error if the first cohort load fails' do
flag_fetcher = double('LocalEvaluationFetcher')
cohort_download_api = double('CohortLoader')
flag_config_storage = double('FlagConfigStorage')
cohort_storage = double('CohortStorage')
cohort_loader = CohortLoader.new(cohort_download_api, cohort_storage)
logger = Logger.new($stdout)
runner = DeploymentRunner.new(
LocalEvaluationConfig.new,
flag_fetcher,
flag_config_storage,
cohort_storage,
logger,
cohort_loader
)

allow(flag_fetcher).to receive(:fetch_v2).and_return([@flag])
allow(flag_fetcher).to receive(:fetch_v2).and_return([flag])
allow(flag_config_storage).to receive(:remove_if).and_return(nil)
allow(flag_config_storage).to receive(:flag_configs).and_return({})
allow(flag_config_storage).to receive(:put_flag_config).and_return(nil)
Expand All @@ -69,7 +58,6 @@ module AmplitudeExperiment
allow(cohort_storage).to receive(:cohort).and_return(nil)
allow(cohort_download_api).to receive(:get_cohort).and_raise(RuntimeError, 'test')

# Expect no error to be raised
expect { runner.start }.not_to raise_error
end
end
Expand Down

0 comments on commit 6660141

Please sign in to comment.