
ThreadOrder
A tool for testing threaded code.
Its purpose is to enable reasoning about thread order.
- Tested on 1.8.7 - 2.6, JRuby, Rbx
- It has no external dependencies
- It does not depend on the stdlib.
Example
class MyQueue
attr_reader :array
def initialize
@array, @mutex = [], Mutex.new
end
def enqueue
@mutex.synchronize { @array << yield }
end
end
require 'rspec/autorun'
require 'thread_order'
RSpec.describe MyQueue do
let(:queue) { described_class.new }
let(:order) { ThreadOrder.new }
after { order.apocalypse! }
it 'is threadsafe on enqueue' do
order.declare :concurrent_enqueue do
queue.enqueue { :concurrent }
end
queue.enqueue do
order.pass_to :concurrent_enqueue, resume_on: :sleep
:main
end
order.join_all
expect(queue.array).to eq [:main, :concurrent]
end
end