From 8b71ba5e68347e5227823dff62eb7760d51f9d5b Mon Sep 17 00:00:00 2001 From: Ryan Date: Wed, 4 Mar 2009 11:54:20 +0100 Subject: [PATCH] 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. --- node.cc | 2 +- test/common.rb | 6 +++++- test/test_setTimeout.rb | 16 ++++++++++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) create mode 100755 test/test_setTimeout.rb diff --git a/node.cc b/node.cc index 2eb189c..e458775 100644 --- a/node.cc +++ b/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); diff --git a/test/common.rb b/test/common.rb index 484b7bd..44f1ee6 100644 --- a/test/common.rb +++ b/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) diff --git a/test/test_setTimeout.rb b/test/test_setTimeout.rb new file mode 100755 index 0000000..7a0b0f0 --- /dev/null +++ b/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); -- 2.7.4