Browse Source

add test_setTimeout

Had to disable Init_tcp because it starts an oi_async thread pool and
prevents the node loop from exiting when no watchers remain. Not sure how
to deal with this problem in general because eventually we'll need the
thread pool.
v0.7.4-release
Ryan 16 years ago
parent
commit
8b71ba5e68
  1. 2
      node.cc
  2. 6
      test/common.rb
  3. 16
      test/test_setTimeout.rb

2
node.cc

@ -154,7 +154,7 @@ main (int argc, char *argv[])
g->Set( String::New("log"), FunctionTemplate::New(LogCallback)->GetFunction());
Init_timer(g);
Init_tcp(g);
//Init_tcp(g);
Init_http(g);
V8::SetFatalErrorHandler(OnFatalError);

6
test/common.rb

@ -11,7 +11,11 @@ def assert(x, msg = "")
end
def assert_equal(x, y, msg = "")
assert(x == y, "#{x.inspect} != #{y.inspect} #{msg}")
raise("expected #{x.inspect} == #{y.inspect}. #{msg}") unless x == y
end
def assert_less_than(x, y, msg = "")
raise("expected #{x.inspect} < #{y.inspect}. #{msg}") unless x < y
end
def wait_for_server(host, port)

16
test/test_setTimeout.rb

@ -0,0 +1,16 @@
#!/usr/bin/env ruby
require File.dirname(__FILE__) + "/common"
prog = IO.popen("#{$node} #{$tf.path}")
a = Time.now
assert_equal("hello\n", prog.readpartial(100))
b = Time.now
assert_equal("world\n", prog.read(100))
c = Time.now
assert_less_than(b - a, 0.5) # startup time
assert_less_than(1.5, c - b)
__END__
log("hello");
setTimeout(function () { log("world"); }, 1500);
Loading…
Cancel
Save