Sha256: d3ef02413dca916e25eb38d489b0755655c8ace0c31d92469b06f77ce6a7ce74

Contents?: true

Size: 1.06 KB

Versions: 1

Compression:

Stored size: 1.06 KB

Contents

require 'quack_concurrency'

RSpec.describe QuackConcurrency::Queue do
  
  describe "pop" do
  
    context "when called when queue empty" do
      it "should wait" do
        $test = []
        queue = QuackConcurrency::Queue.new
        thread = Thread.new do
          queue.pop
          $test << 1
          sleep 1
          queue.push
        end
        sleep 1
        queue.push
        queue.pop
        $test << 2
        thread.join
        expect($test).to eql [1, 2]
      end
    end
    
    context "when called when queue not empty" do
      it "should immediately return" do
        $test = []
        queue = QuackConcurrency::Queue.new
        queue.push
        thread = Thread.new do
          queue.pop
          $test << 1
        end
        sleep 1
        $test << 2
        thread.join
        expect($test).to eql [1, 2]
      end
    end
    
    context "when called" do
      it "should return value of the push" do
        queue = QuackConcurrency::Queue.new
        queue.push 1
        expect(queue.pop).to eql 1
      end
    end
    
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
quack_concurrency-0.2.0 spec/queue_spec.rb