diff options
author | yugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-08-25 15:02:05 +0000 |
---|---|---|
committer | yugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-08-25 15:02:05 +0000 |
commit | 0dc342de848a642ecce8db697b8fecd83a63e117 (patch) | |
tree | 2b7ed4724aff1f86073e4740134bda9c4aac1a39 /trunk/test/webrick/test_server.rb | |
parent | ef70cf7138ab8034b5b806f466e4b484b24f0f88 (diff) |
added tag v1_9_0_4
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/tags/v1_9_0_4@18845 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'trunk/test/webrick/test_server.rb')
-rw-r--r-- | trunk/test/webrick/test_server.rb | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/trunk/test/webrick/test_server.rb b/trunk/test/webrick/test_server.rb new file mode 100644 index 0000000000..ce5ee85c6c --- /dev/null +++ b/trunk/test/webrick/test_server.rb @@ -0,0 +1,64 @@ +require "test/unit" +require "tempfile" +require "webrick" +require File.join(File.dirname(__FILE__), "utils.rb") + +class TestWEBrickServer < Test::Unit::TestCase + class Echo < WEBrick::GenericServer + def run(sock) + while line = sock.gets + sock << line + end + end + end + + def test_server + TestWEBrick.start_server(Echo){|server, addr, port| + TCPSocket.open(addr, port){|sock| + sock.puts("foo"); assert_equal("foo\n", sock.gets) + sock.puts("bar"); assert_equal("bar\n", sock.gets) + sock.puts("baz"); assert_equal("baz\n", sock.gets) + sock.puts("qux"); assert_equal("qux\n", sock.gets) + } + } + end + + def test_callbacks + accepted = started = stopped = 0 + config = { + :AcceptCallback => Proc.new{ accepted += 1 }, + :StartCallback => Proc.new{ started += 1 }, + :StopCallback => Proc.new{ stopped += 1 }, + } + TestWEBrick.start_server(Echo, config){|server, addr, port| + true while server.status != :Running + assert_equal(started, 1) + assert_equal(stopped, 0) + assert_equal(accepted, 0) + TCPSocket.open(addr, port){|sock| (sock << "foo\n").gets } + TCPSocket.open(addr, port){|sock| (sock << "foo\n").gets } + TCPSocket.open(addr, port){|sock| (sock << "foo\n").gets } + assert_equal(accepted, 3) + } + assert_equal(started, 1) + assert_equal(stopped, 1) + end + + def test_daemon + begin + r, w = IO.pipe + Process.fork{ + r.close + WEBrick::Daemon.start + w.puts(Process.pid) + sleep + } + assert(Process.kill(:KILL, r.gets.to_i)) + rescue NotImplementedError + # snip this test + ensure + r.close + w.close + end + end +end |