Sha256: f2f4b758d10b4ff2367e65dcc49af6854d53842ce581f97596c44570838869dd

Contents?: true

Size: 1.79 KB

Versions: 2

Compression:

Stored size: 1.79 KB

Contents

require File.expand_path 'test_helper', File.dirname(__FILE__)

class TestBlockingReadTake < MiniTest::Test

  def test_blocking_take
    ts_name = "ts_blocking_take_#{rand Time.now.to_i}"
    results = Array.new

    EM::run do
      client = EM::RocketIO::Linda::Client.new App.url
      ts = client.tuplespace[ts_name]
      
      client.io.on :connect do
        1.upto(3) do |i|
          ts.write ["blocking", "take", i]
        end

        client2 = EM::RocketIO::Linda::Client.new App.url
        ts2 = client2.tuplespace[ts_name]
        client2.io.on :connect do
          EM::defer do
            loop do
              results.push ts2.take ["blocking", "take"]
            end
          end
        end
      end

      EM::defer do
        50.times do
          sleep 0.1
          break if results.size > 2
        end
        EM::add_timer 1 do
          EM::stop
        end
      end
    end

    assert_equal results.size, 3
    assert_equal results.shift, ["blocking", "take", 3]
    assert_equal results.shift, ["blocking", "take", 2]
    assert_equal results.shift, ["blocking", "take", 1]
  end


  def test_blocking_read
    ts_name = "ts_blocking_read_#{rand Time.now.to_i}"
    results = Array.new

    EM::run do
      client = EM::RocketIO::Linda::Client.new App.url
      ts = client.tuplespace[ts_name]
      client.io.on :connect do
        EM::defer do
          1.upto(3) do |i|
            ts.write ["blocking", "read", i]
            results.push ts.read ["blocking", "read"]
          end
          EM::add_timer 1 do
            EM::stop
          end
        end
      end
    end

    assert_equal results.size, 3
    assert_equal results.shift, ["blocking", "read", 1]
    assert_equal results.shift, ["blocking", "read", 2]
    assert_equal results.shift, ["blocking", "read", 3]
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
em-rocketio-linda-client-1.0.0 test/test_blocking_read_take.rb
em-rocketio-linda-client-0.0.3 test/test_blocking_read_take.rb