Testing IndirectImmediateExecutor Thread Management in concurrent-ruby
This test suite validates the IndirectImmediateExecutor implementation in concurrent-ruby, focusing on synchronous task execution and thread management. It ensures proper executor service behavior while verifying tasks run immediately but on separate threads.
Test Coverage Overview
Implementation Analysis
Technical Details
Best Practices Demonstrated
ruby-concurrency/concurrent-ruby
spec/concurrent/executor/indirect_immediate_executor_spec.rb
require 'concurrent/executor/indirect_immediate_executor'
require_relative 'executor_service_shared'
module Concurrent
RSpec.describe IndirectImmediateExecutor do
subject { IndirectImmediateExecutor.new }
it_should_behave_like :executor_service, immediate_type: true
it "runs its tasks synchronously" do
start = Time.now
subject.post { sleep 0.1 }
expect(Time.now - start).to be >= 0.1
end
it "runs the task on a separate thread" do
used_thread = nil
subject.post { used_thread = Thread.current }
expect(used_thread).not_to be(Thread.current)
end
end
end