Skip to content

Commit

Permalink
poller specs
Browse files Browse the repository at this point in the history
  • Loading branch information
k-solutions committed Jun 23, 2016
1 parent c0e5c53 commit 9b8b1de
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
44 changes: 44 additions & 0 deletions spec/poller_spec.cr
@@ -0,0 +1,44 @@
require "./spec_helper"

POLLER_ENDPOINT = "inproc://poll_test"

describe ZMQ::Poller do
context "#register" do
it "returns false when given a nil pollable" do
poller = ZMQ::Poller.new
ZMQ::Context.create(ZMQ::DEALER) do |ctx, (pollable)|
orig = poller.poll_items.size
poller.register(pollable, ZMQ::POLLIN)
poller.poll_items.size.should eq(orig + 1)
end
end
end

context "#poll" do
it "returns 0 when there are no sockets to poll" do
poller = ZMQ::Poller.new
poller.poll(1).should eq(0)
end

it "returns 0 when there is a single socket to poll and no events" do
poller = ZMQ::Poller.new
ZMQ::Context.create(ZMQ::DEALER) do |ctx, (first)|
poller.register(first, ZMQ::POLLIN)
poller.poll(1).should eq(0)
end
end

it "returns 1 when there is a read event on a socket" do
poller = ZMQ::Poller.new
ZMQ::Context.create(ZMQ::DEALER, ZMQ::ROUTER) do |ctx, (first, last)|
first.bind POLLER_ENDPOINT
APIHelper.connect_to_inproc last, POLLER_ENDPOINT

poller.register_readable last
first.send_string "test"

poller.poll(1).should eq(1)
end
end
end
end
2 changes: 2 additions & 0 deletions src/zeromq/poller.cr
@@ -1,4 +1,6 @@
class ZMQ::Poller
getter poll_items

def initialize
@poll_items = [] of {Socket, Int32}
@readables = [] of Socket
Expand Down

0 comments on commit 9b8b1de

Please sign in to comment.