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

VEBT: fix failing VYE bdn_ingress test on holidays #20814

Merged
merged 1 commit into from
Feb 17, 2025
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
53 changes: 39 additions & 14 deletions modules/vye/spec/sidekiq/vye/midnight_run/ingress_bdn_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,28 @@
let(:bdn_clone) { create(:vye_bdn_clone_base) }
let(:chunks) do
5.times.map do |i|
offset = i * 1000
block_size = 1000
filename = "file-#{offset}.txt"
Vye::BatchTransfer::Chunk.new(offset:, block_size:, filename:)
double('Chunk',
offset: i * 1000,
block_size: 1000,
filename: "file-#{i * 1000}.txt")
end
end
let(:holiday_checker) { class_double(Vye::CloudTransfer).as_stubbed_const }
let(:batch_double) { instance_double(Sidekiq::Batch, description: nil, on: nil) }

before do
Sidekiq::Job.clear_all
allow(Sidekiq::Batch).to receive(:new).and_return(batch_double)
allow(batch_double).to receive(:description=)
allow(batch_double).to receive(:on)
# Allow the jobs block to execute
allow(batch_double).to receive(:jobs).and_yield
end

context 'when it is not a holiday' do
before do
Timecop.freeze(Time.zone.local(2024, 7, 2)) # Regular work day
allow(holiday_checker).to receive(:holiday?).and_return(false)
end

after do
Expand All @@ -32,32 +40,49 @@
expect(Vye::BdnClone).to receive(:create!).and_return(bdn_clone)
expect(Vye::BatchTransfer::BdnChunk).to receive(:build_chunks).and_return(chunks)

expect do
described_class.perform_async
end.to change { Sidekiq::Worker.jobs.size }.by(1)
worker = described_class.new
worker.perform

described_class.drain
expect(Vye::MidnightRun::IngressBdnChunk).to have_enqueued_sidekiq_job.exactly(5).times
end
end

context 'when it is a holiday' do
before do
Timecop.freeze(Time.zone.local(2024, 7, 2))
allow(holiday_checker).to receive(:holiday?).and_return(true)
allow(Vye::BdnClone).to receive(:create!).and_return(bdn_clone)
allow(Vye::BatchTransfer::BdnChunk).to receive(:build_chunks).and_return(chunks)
end

after do
Timecop.return
end

it 'logs holiday message and processes normally' do
worker = described_class.new
expect(Rails.logger).to receive(:info).with(/holiday detected, job run at:/).ordered
expect(Rails.logger).to receive(:info).with('Vye::MidnightRun::IngressBdn: starting').ordered
expect(Rails.logger).to receive(:info).with('Vye::MidnightRun::IngressBdn: finished').ordered

worker.perform

expect(Vye::MidnightRun::IngressBdnChunk).to have_enqueued_sidekiq_job.exactly(5).times
end
end

context 'logging' do
before do
allow(holiday_checker).to receive(:holiday?).and_return(false)
allow(Vye::BdnClone).to receive(:create!).and_return(double('BdnClone', id: 123))
allow(Vye::BatchTransfer::BdnChunk).to receive(:build_chunks).and_return([])

batch_double = instance_double(Sidekiq::Batch, description: nil, on: nil, jobs: nil)
allow(Sidekiq::Batch).to receive(:new).and_return(batch_double)
allow(batch_double).to receive(:description=).with('Ingress BDN Clone feed as chunked files')
end

# See comment in Vye::MidnightRun regarding logging. It applies here too.
it 'logs info' do
expect(Rails.logger).to receive(:info).with('Vye::MidnightRun::IngressBdn: starting')
expect(Rails.logger).to receive(:info).with('Vye::MidnightRun::IngressBdn: finished')

Vye::MidnightRun::IngressBdn.new.perform
described_class.new.perform
end
end
end
Loading