free_mutant/spec/unit/mutant/actor/env_spec.rb
Markus Schirp d8e6805206 Fix actor race condition
* Use the `ConditionVariable` primitive to fix rece between stopped
  receiver Thread and its wake signal.
* Race was only observable via synthetical benchmarks and explicit
  sleeps between unlocking receiver mutex and Thread.stop
* Simplifies code a lot as thread must not be passed around anymore
2014-12-06 04:37:20 +00:00

29 lines
736 B
Ruby

RSpec.describe Mutant::Actor::Env do
let(:thread) { double('Thread') }
let(:thread_root) { double('Thread Root') }
let(:object) { described_class.new(thread_root) }
describe '#spawn' do
subject { object.spawn(&block) }
let!(:mailbox) { Mutant::Actor::Mailbox.new }
let(:yields) { [] }
let(:block) { ->(actor) { yields << actor } }
before do
expect(Mutant::Actor::Mailbox).to receive(:new).and_return(mailbox).ordered
expect(thread_root).to receive(:new).and_yield.and_return(thread).ordered
end
it 'returns sender' do
should be(mailbox.sender)
end
it 'yields actor' do
expect { subject }.to change { yields }.from([]).to([mailbox])
end
end
end