Skip to content

Commit

Permalink
Tests for watch_only?
Browse files Browse the repository at this point in the history
  • Loading branch information
sodabrew committed Apr 30, 2018
1 parent b430a52 commit 168e406
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 3 deletions.
3 changes: 1 addition & 2 deletions ext/cmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -378,8 +378,7 @@ extern "C" int evma_is_watch_only (const uintptr_t binding)
EventableDescriptor *cd = dynamic_cast <EventableDescriptor*> (Bindable_t::GetObject (binding));
if (cd)
return cd->IsWatchOnly() ? 1 : 0;

return 0;
return -1;
}

/****************************
Expand Down
48 changes: 48 additions & 0 deletions tests/test_attach.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,4 +148,52 @@ def test_read_write_pipe
ensure
[r,w].each {|io| io.close rescue nil }
end

# This test shows that watch_only? is true for EM.watch
def test_watch_only
r, w = IO.pipe
$watch_only = nil

EM.run do
EM.watch r do |c|
assert_true(c.watch_only?)
c.notify_readable = true
def c.receive_data data
fail('this method should not be called')
end
def c.notify_readable
$watch_only = watch_only?
end
end
w.write 'hello'
EM.next_tick { EM.stop }
end

assert_true($watch_only)
end

# This test shows that watch_only? is false for EM.attach
def test_attach_data
r, w = IO.pipe
$watch_only = nil
$read = []

EM.run do
EM.attach r do |c|
assert_false(c.watch_only?)
def c.receive_data data
$watch_only = watch_only?
$read << data
end
def c.notify_readable
fail('this method should not be called')
end
end
w.write 'world'
EM.next_tick { EM.stop }
end

assert_false($watch_only)
assert_equal('world', $read.first)
end
end
1 change: 0 additions & 1 deletion tests/test_process_watch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ def test_events
EM.watch_process(Process.pid, ParentProcessWatcher)
$fork_pid = fork{ sleep }
child = EM.watch_process($fork_pid, ChildProcessWatcher)
assert_equal(child.watch_only?, true)
$pid = child.pid

EM.add_timer(0.2){
Expand Down

0 comments on commit 168e406

Please sign in to comment.