OSDN Git Service

Replaced mongrel with thin
[redminele/redminele.git] / ruby / lib / ruby / gems / 1.8 / gems / eventmachine-0.12.10-x86-mswin32-60 / tests / test_channel.rb
diff --git a/ruby/lib/ruby/gems/1.8/gems/eventmachine-0.12.10-x86-mswin32-60/tests/test_channel.rb b/ruby/lib/ruby/gems/1.8/gems/eventmachine-0.12.10-x86-mswin32-60/tests/test_channel.rb
new file mode 100644 (file)
index 0000000..dd2d124
--- /dev/null
@@ -0,0 +1,63 @@
+$:.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
\ No newline at end of file