mirror of https://github.com/lukechilds/node.git
Ryan
16 years ago
8 changed files with 0 additions and 189 deletions
@ -1,8 +0,0 @@ |
|||||
var filename = ARGV[2]; |
|
||||
File.cat(filename, function (status, content) { |
|
||||
if (status == 0) |
|
||||
puts(content); |
|
||||
else |
|
||||
puts("error"); |
|
||||
}); |
|
||||
puts("hello world"); |
|
@ -1,34 +0,0 @@ |
|||||
require 'tempfile' |
|
||||
|
|
||||
$node = File.join(File.dirname(__FILE__), "../node") |
|
||||
$tf = Tempfile.open("node") |
|
||||
$tf.puts(DATA.read) |
|
||||
$tf.close |
|
||||
|
|
||||
def assert(x, msg = "") |
|
||||
raise(msg) unless x |
|
||||
end |
|
||||
|
|
||||
def assert_equal(x, y, 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) |
|
||||
loop do |
|
||||
begin |
|
||||
socket = ::TCPSocket.open(host, port) |
|
||||
return |
|
||||
rescue Errno::ECONNREFUSED |
|
||||
$stderr.print "." if $DEBUG |
|
||||
$stderr.flush |
|
||||
sleep 0.2 |
|
||||
ensure |
|
||||
socket.close |
|
||||
end |
|
||||
end |
|
||||
end |
|
||||
|
|
@ -1,24 +0,0 @@ |
|||||
var f = new File; |
|
||||
|
|
||||
f.open("/tmp/world", "w+", function (status) { |
|
||||
if (status == 0) { |
|
||||
stdout.puts("file open"); |
|
||||
f.write("hello world\n"); |
|
||||
f.write("something else.\n", function () { |
|
||||
stdout.puts("written. "); |
|
||||
}); |
|
||||
f.read(100, function (status, buf) { |
|
||||
if (buf) |
|
||||
stdout.puts("read: >>" + buf.encodeUtf8() + "<<"); |
|
||||
}); |
|
||||
} else { |
|
||||
stdout.puts("file open failed: " + status.toString()); |
|
||||
} |
|
||||
|
|
||||
f.close(function (status) { |
|
||||
stdout.puts("closed: " + status.toString()); |
|
||||
File.rename("/tmp/world", "/tmp/hello", function (status) { |
|
||||
stdout.puts("rename: " + status.toString()); |
|
||||
}); |
|
||||
}); |
|
||||
}); |
|
@ -1,15 +0,0 @@ |
|||||
File.stat(ARGV[2], function (status, stats) { |
|
||||
if (status == 0) { |
|
||||
for (var i in stats) { |
|
||||
puts(i + " : " + stats[i]); |
|
||||
} |
|
||||
} else { |
|
||||
puts("error: " + File.strerror(status)); |
|
||||
} |
|
||||
}); |
|
||||
|
|
||||
File.exists(ARGV[2], function (r) { |
|
||||
puts("file exists: " + r); |
|
||||
}); |
|
||||
|
|
||||
|
|
@ -1,14 +0,0 @@ |
|||||
#!/usr/bin/env ruby |
|
||||
require File.dirname(__FILE__) + "/common" |
|
||||
|
|
||||
a = Time.now |
|
||||
out = `#{$node} #{$tf.path}` |
|
||||
b = Time.now |
|
||||
assert_equal("hello\nworld\n", out) |
|
||||
assert_less_than(b - a, 1) # startup time |
|
||||
|
|
||||
__END__ |
|
||||
log("hello"); |
|
||||
timeout1 = setTimeout(function () { log("world"); }, 500); |
|
||||
timeout2 = setTimeout(function () { log("ryah"); }, 5000); |
|
||||
clearTimeout(timeout2) |
|
@ -1,53 +0,0 @@ |
|||||
#!/usr/bin/env ruby |
|
||||
require 'net/http' |
|
||||
require File.dirname(__FILE__) + "/common" |
|
||||
|
|
||||
pid = fork do |
|
||||
exec($node, $tf.path) |
|
||||
end |
|
||||
|
|
||||
begin |
|
||||
wait_for_server("localhost", 8000) |
|
||||
connection = Net::HTTP.new("localhost", 8000) |
|
||||
|
|
||||
response, body = connection.get("/") |
|
||||
assert_equal(response.code, "200") |
|
||||
assert(response.chunked?) |
|
||||
assert_equal(body, "\n") |
|
||||
assert_equal(response.content_type, "text/plain") |
|
||||
|
|
||||
response, body = connection.post("/", "hello world") |
|
||||
assert_equal(response.code, "200") |
|
||||
assert(response.chunked?) |
|
||||
assert_equal(body, "hello world\n") |
|
||||
assert_equal(response.content_type, "text/plain") |
|
||||
ensure |
|
||||
`kill -9 #{pid}` |
|
||||
end |
|
||||
|
|
||||
__END__ |
|
||||
function encode(data) { |
|
||||
var chunk = data.toString(); |
|
||||
return chunk.length.toString(16) + "\r\n" + chunk + "\r\n"; |
|
||||
} |
|
||||
|
|
||||
var port = 8000; |
|
||||
var server = new HTTPServer(null, port, function (request) { |
|
||||
|
|
||||
// onBody sends null on the last chunk. |
|
||||
request.onbody = function (chunk) { |
|
||||
if(chunk) { |
|
||||
this.respond(encode(chunk)); |
|
||||
} else { |
|
||||
this.respond(encode("\n")); |
|
||||
this.respond("0\r\n\r\n"); |
|
||||
this.respond(null); // signals end-of-request |
|
||||
} |
|
||||
} |
|
||||
request.respond("HTTP/1.0 200 OK\r\n"); |
|
||||
request.respond("Content-Type: text/plain\r\n"); |
|
||||
request.respond("Transfer-Encoding: chunked\r\n"); |
|
||||
request.respond("\r\n"); |
|
||||
}); |
|
||||
|
|
||||
log("Running at http://localhost:" + port + "/"); |
|
@ -1,25 +0,0 @@ |
|||||
#!/usr/bin/env ruby |
|
||||
require 'net/http' |
|
||||
require File.dirname(__FILE__) + "/common" |
|
||||
|
|
||||
pid = fork do |
|
||||
exec($node, $tf.path) |
|
||||
end |
|
||||
|
|
||||
begin |
|
||||
wait_for_server("localhost", 8000) |
|
||||
connection = Net::HTTP.new("localhost", 8000) |
|
||||
|
|
||||
response, body = connection.get("/") |
|
||||
ensure |
|
||||
`kill -9 #{pid}` |
|
||||
end |
|
||||
|
|
||||
__END__ |
|
||||
var server = new HTTPServer(null, 8000, function (request) { |
|
||||
log("request"); |
|
||||
request.respond("HTTP/1.1 200 OK\r\n"); |
|
||||
request.respond("Content-Length: 0\r\n"); |
|
||||
request.respond("\r\n"); |
|
||||
request.respond(null); |
|
||||
}); |
|
@ -1,16 +0,0 @@ |
|||||
#!/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…
Reference in new issue