Sha256: 0d7268c49a8a21cb128ff75f7cf0fd57dc8ca8321675307d81f1c8b76cd86a9d
Contents?: true
Size: 1.23 KB
Versions: 7
Compression:
Stored size: 1.23 KB
Contents
require File.expand_path(File.dirname(__FILE__) + '/spec_helper') require 'thread' CNT = 10000 CNTI = CNT CNTO = CNT describe QueueDing::QDing do before(:each) do @queue = QueueDing::QDing.new class Foobar def initialize @stuff = [1, 2, 3] end end @foo = Foobar.new end it "QDing can be created" do expect(@queue).to_not be_nil end it "pushes an object into the queue" do @queue << @foo expect(@queue.first).to eq @foo end it "extracts an object from the queue" do @queue << @foo bar = @queue.pop expect(bar).to eq @foo end it "handles concurrency" do tout = Thread.new do (0..CNTO).each{ |j| (i, num) = @queue.next expect(j).to eq i expect(num).to eq j * 7 + 3 } end tin = Thread.new do (0..CNTI).map{|i| [i, i * 7 + 3]}.each{|pair| @queue << pair } end tin.join tout.join expect(@queue.empty?).to be_truthy end it "handles teeing" do tg = ThreadGroup.new tg.add Thread.new { sleep 5 (0..CNT).each{|i| @queue << i } } 20.times do tg.add Thread.new { (0..CNT).each{|i| expect(i).to eq @queue.next } } end tg.list.each {|t| t.join } end end
Version data entries
7 entries across 7 versions & 1 rubygems