Sha256: 40492d125cd66e1d0b50c1cb97e33674472908f693a82cbbb48abfff78ab4994

Contents?: true

Size: 1003 Bytes

Versions: 12

Compression:

Stored size: 1003 Bytes

Contents

require File.dirname(__FILE__) + '/test_helper.rb'

class TestRQueue < Test::Unit::TestCase
  def setup
    @q = RQueue.new
  end
  def test_RQueue_init
    q = RQueue.new
    assert q.empty?
  end
  def test_RQueue_init_with_RQueue_max_size
    max = 10
    q = RQueue.new max
    assert q.empty? && q.max_size==max
  end
  def test_RQueue_mutex_push
    max = 100
    q = RQueue.new max
    th1 = Thread.new{
      loop{
        q.push 1
      }
    }
    th2 = Thread.new{
      loop{
        q.push 1
      }
    }
    sleep 0.1
    assert th1.status == "sleep" && th2.status == "sleep" && q.full?
  end
  def test_RQueue_mutex_pop
    max = 10
    q = RQueue.new max
    max.times{ q.push 1 }
    th1 = Thread.new{
      loop{
        q.pop
      }
    }
    th2 = Thread.new{
      loop{
        q.pop
      }
    }
    while not q.empty? do
      sleep 0.1
    end
    assert th1.status == "sleep" && th2.status == "sleep" && q.empty?
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
noda-0.0.15 test/test_rqueue.rb
noda-0.0.14 test/test_rqueue.rb
noda-0.0.13 test/test_rqueue.rb
noda-0.0.12 test/test_rqueue.rb
noda-0.0.11 test/test_rqueue.rb
noda-0.0.10 test/test_rqueue.rb
noda-0.0.9 test/test_rqueue.rb
noda-0.0.8 test/test_rqueue.rb
noda-0.0.7 test/test_rqueue.rb
noda-0.0.6 test/test_rqueue.rb
noda-0.0.5.1 test/test_rqueue.rb
noda-0.0.5 test/test_rqueue.rb