Sha256: 66f4fae5c82eb513153547f3ed59649636f6ad12a30124fc5eb14ca135fd3860

Contents?: true

Size: 1.2 KB

Versions: 70

Compression:

Stored size: 1.2 KB

Contents

$:.unshift "../lib"
require 'eventmachine'
require 'test/unit'

class TestEventMachineChannel < Test::Unit::TestCase
  def test_channel_subscribe
    s = 0
    EM.run do
      c = EM::Channel.new
      c.subscribe { |v| s = v; EM.stop }
      c << 1
    end
    assert_equal 1, s
  end

  def test_channel_unsubscribe
    s = 0
    EM.run do
      c = EM::Channel.new
      subscription = c.subscribe { |v| s = v }
      c.unsubscribe(subscription)
      c << 1
      EM.next_tick { EM.stop }
    end
    assert_not_equal 1, s
  end

  def test_channel_pop
    s = 0
    EM.run do
      c = EM::Channel.new
      c.pop{ |v| s = v }
      c << 1
      c << 2
      EM.next_tick { EM.stop }
    end
    assert_equal 1, s
  end

  def test_channel_reactor_thread_push
    out = []
    c = EM::Channel.new
    c.subscribe { |v| out << v }
    Thread.new { c.push(1,2,3) }.join
    assert out.empty?

    EM.run { EM.next_tick { EM.stop } }

    assert_equal [1,2,3], out
  end

  def test_channel_reactor_thread_callback
    out = []
    c = EM::Channel.new
    Thread.new { c.subscribe { |v| out << v } }.join
    c.push(1,2,3)
    assert out.empty?

    EM.run { EM.next_tick { EM.stop } }

    assert_equal [1,2,3], out
  end
end

Version data entries

70 entries across 70 versions & 10 rubygems

Version Path
classiccms-0.7.5 vendor/bundle/gems/eventmachine-0.12.10/tests/test_channel.rb
classiccms-0.7.4 vendor/bundle/gems/eventmachine-0.12.10/tests/test_channel.rb
classiccms-0.7.3 vendor/bundle/gems/eventmachine-0.12.10/tests/test_channel.rb
MattHulse-eventmachine-0.0.1 tests/test_channel.rb
MattHulse-eventmachine-0.12.10 tests/test_channel.rb
eventmachine-eventmachine-0.12.8 tests/test_channel.rb
eventmachine-eventmachine-0.12.9 tests/test_channel.rb
classiccms-0.7.2 vendor/bundle/gems/eventmachine-0.12.10/tests/test_channel.rb
classiccms-0.7.1 vendor/bundle/gems/eventmachine-0.12.10/tests/test_channel.rb
classiccms-0.7.0 vendor/bundle/gems/eventmachine-0.12.10/tests/test_channel.rb
classiccms-0.6.9 vendor/bundle/gems/eventmachine-0.12.10/tests/test_channel.rb
classiccms-0.6.8 vendor/bundle/gems/eventmachine-0.12.10/tests/test_channel.rb
classiccms-0.6.7 vendor/bundle/gems/eventmachine-0.12.10/tests/test_channel.rb
classiccms-0.6.6 vendor/bundle/gems/eventmachine-0.12.10/tests/test_channel.rb
classiccms-0.6.5 vendor/bundle/gems/eventmachine-0.12.10/tests/test_channel.rb
classiccms-0.6.4 vendor/bundle/gems/eventmachine-0.12.10/tests/test_channel.rb
classiccms-0.6.3 vendor/bundle/gems/eventmachine-0.12.10/tests/test_channel.rb
classiccms-0.6.2 vendor/bundle/gems/eventmachine-0.12.10/tests/test_channel.rb
classiccms-0.6.1 vendor/bundle/gems/eventmachine-0.12.10/tests/test_channel.rb
classiccms-0.6.0 vendor/bundle/gems/eventmachine-0.12.10/tests/test_channel.rb