Skip to content

Commit

Permalink
Merge pull request #3035 from DataDog/refactor/interval_loop_fiber
Browse files Browse the repository at this point in the history
Use Fiber instead of Thread for IntervalLoop spec
  • Loading branch information
delner authored Aug 9, 2023
2 parents 0ec5812 + 27d2719 commit d131819
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions spec/datadog/core/workers/interval_loop_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,26 @@
end
end

shared_context 'perform loop in thread' do
before do
# Start the loop in a thread, give it time to warm up.
@thread = Thread.new { worker.perform }
sleep(0.1)
shared_context 'perform loop in fiber' do
let(:fiber) do
Fiber.new do
worker.perform
end
end

after do
@thread.kill
@thread.join
let(:task) do
proc do |*args|
worker_spy.perform(*args)
Fiber.yield
end
end

before do
# Start the loop in a fiber.
fiber.resume

# Verify we hit the breakpoint
expect(worker_spy).to have_received(:perform)
end
end

Expand Down Expand Up @@ -103,7 +113,7 @@
end

context 'when the worker is running' do
include_context 'perform loop in thread'
include_context 'perform loop in fiber'

it { is_expected.to be true }

Expand All @@ -129,7 +139,7 @@
end

context 'when the worker is running' do
include_context 'perform loop in thread'
include_context 'perform loop in fiber'
it { is_expected.to be true }
end
end
Expand All @@ -142,7 +152,7 @@
end

context 'when worker is running' do
include_context 'perform loop in thread'
include_context 'perform loop in fiber'
it { is_expected.to be true }
end
end
Expand Down

0 comments on commit d131819

Please sign in to comment.