diff options
author | luislavena <luislavena@19e92222-5c0b-0410-8929-a290d50e31e9> | 2008-04-18 07:09:44 +0000 |
---|---|---|
committer | luislavena <luislavena@19e92222-5c0b-0410-8929-a290d50e31e9> | 2008-04-18 07:09:44 +0000 |
commit | e01981e04f12638176b7699e8daf23c0a805bde2 (patch) | |
tree | 87d5267a2625c005902f0e5190412ecabe774a47 | |
parent | 87e6494e924849fc22d0602187b650a0b7a11fc8 (diff) | |
download | unicorn-e01981e04f12638176b7699e8daf23c0a805bde2.tar.gz |
Imported tests from RubyServices project. (Closes #18). git-svn-id: svn+ssh://rubyforge.org/var/svn/mongrel/branches/stable_1-2@1012 19e92222-5c0b-0410-8929-a290d50e31e9
-rw-r--r-- | projects/mongrel_service/CHANGELOG | 5 | ||||
-rw-r--r-- | projects/mongrel_service/native/console_process.bas | 22 | ||||
-rw-r--r-- | projects/mongrel_service/tests/test_console_process.bas | 149 | ||||
-rw-r--r-- | projects/mongrel_service/tests/test_helpers.bas | 2 |
4 files changed, 109 insertions, 69 deletions
diff --git a/projects/mongrel_service/CHANGELOG b/projects/mongrel_service/CHANGELOG index 67f5086..074c87a 100644 --- a/projects/mongrel_service/CHANGELOG +++ b/projects/mongrel_service/CHANGELOG @@ -1,3 +1,8 @@ +* 0.3.5 * + + * Wait longer for child process terminate properly (max 20 seconds). Imported + tests from RubyServices project. (Closes #18). + * Updated ServiceFB to work with FB > 0.18. * 0.3.4 * diff --git a/projects/mongrel_service/native/console_process.bas b/projects/mongrel_service/native/console_process.bas index 78dc1a0..a2bb5c9 100644 --- a/projects/mongrel_service/native/console_process.bas +++ b/projects/mongrel_service/native/console_process.bas @@ -81,6 +81,7 @@ property ConsoleProcess.pid() as uinteger end property
property ConsoleProcess.exit_code() as uinteger
+ static previous_code as uinteger
dim result as uinteger
result = 0
@@ -90,9 +91,16 @@ property ConsoleProcess.exit_code() as uinteger if not (_process_info.hProcess = NULL) then
'# the process reference is valid, get the exit_code
if not (GetExitCodeProcess(_process_info.hProcess, @result) = 0) then
+ previous_code = result
'# OK
'# no error in the query, get result
+ if not (result = STILL_ACTIVE) then
+ CloseHandle(_process_info.hProcess)
+ _process_info.hProcess = NULL
+ end if '# (result = STILL_ACTIVE)
end if '# not (GetExitCodeProcess() = 0)
+ else
+ result = previous_code
end if '# not (proc = NULL)
end if '# not (_pid = 0)
@@ -228,7 +236,7 @@ function ConsoleProcess.start() as boolean else
'# use pipes instead
'# StdOut
- if (CreatePipe(@StdErrRd, @StdErrWr, @proc_sa, 0) = 0) then
+ if (CreatePipe(@StdErrRd, @StdErrWr, @proc_sa, 0) = 0) then
success = false
end if
@@ -283,10 +291,10 @@ function ConsoleProcess.start() as boolean CloseHandle(StdErrRd)
CloseHandle(StdErrWr)
- '# close children main Thread handle
- 'CloseHandle(proc.hThread)
- 'CloseHandle(proc.hProcess)
-
+ '# close children main Thread handle and
+ '# NULLify to avoid issues
+ CloseHandle(_process_info.hThread)
+ _process_info.hThread = NULL
end if '# (CreateProcess() = 0)
else
result = false
@@ -322,7 +330,7 @@ function ConsoleProcess.terminate(byval force as boolean = false) as boolean '# send CTRL_C_EVENT and wait for result
if not (GenerateConsoleCtrlEvent(CTRL_C_EVENT, 0) = 0) then
'# it worked, wait 5 seconds terminates.
- wait_code = WaitForSingleObject(proc, 5000)
+ wait_code = WaitForSingleObject(proc, 10000)
if not (wait_code = WAIT_TIMEOUT) then
success = true
end if
@@ -335,7 +343,7 @@ function ConsoleProcess.terminate(byval force as boolean = false) as boolean '# send CTRL_BREAK_EVENT and wait for result
if not (GenerateConsoleCtrlEvent(CTRL_BREAK_EVENT, 0) = 0) then
'# it worked, wait 5 seconds terminates.
- wait_code = WaitForSingleObject(proc, 5000)
+ wait_code = WaitForSingleObject(proc, 10000)
if not (wait_code = WAIT_TIMEOUT) then
success = true
end if
diff --git a/projects/mongrel_service/tests/test_console_process.bas b/projects/mongrel_service/tests/test_console_process.bas index 02cb5f9..d41c0fb 100644 --- a/projects/mongrel_service/tests/test_console_process.bas +++ b/projects/mongrel_service/tests/test_console_process.bas @@ -30,7 +30,7 @@ namespace Suite_Test_Console_Process sub test_process_create()
child = new ConsoleProcess()
- assert_not_equal_error(0, child)
+ assert_not_equal(0, child)
assert_equal("", child->filename)
assert_equal("", child->arguments)
assert_false(child->running)
@@ -64,7 +64,7 @@ namespace Suite_Test_Console_Process '# start() should return true since it started, no matter if was terminated
'# improperly
assert_true(child->start())
- sleep 150
+ sleep 500
'# should not be running, but pid should be != than 0
assert_not_equal(0, child->pid)
@@ -80,6 +80,9 @@ namespace Suite_Test_Console_Process end sub
sub test_redirected_output()
+ assert_false(fileexists("out.log"))
+ assert_false(fileexists("err.log"))
+
'# redirected output is used with logging files.
child = new ConsoleProcess("mock_process.exe")
@@ -93,7 +96,7 @@ namespace Suite_Test_Console_Process '# start() will be true since process terminated nicely
assert_true(child->start())
- sleep 150
+ sleep 500
'# running should be false
assert_false(child->running)
@@ -101,6 +104,8 @@ namespace Suite_Test_Console_Process '# exit_code should be 0
assert_equal(0, child->exit_code)
+ delete child
+
'# now out.log and err.log must exist and content must be valid.
assert_true(fileexists("out.log"))
assert_string_equal("out: message", content_of_file("out.log"))
@@ -108,14 +113,8 @@ namespace Suite_Test_Console_Process assert_true(fileexists("err.log"))
assert_string_equal("err: error", content_of_file("err.log"))
- '# cleanup
- process_cleanup()
- assert_equal_error(0, kill("out.log"))
- assert_equal_error(0, kill("err.log"))
-
- assert_true_error(fileexists("err.log"))
-
- delete child
+ assert_equal(0, kill("out.log"))
+ assert_equal(0, kill("err.log"))
end sub
sub test_redirected_merged_output()
@@ -131,7 +130,7 @@ namespace Suite_Test_Console_Process '# start() will be true since process terminated nicely
assert_true(child->start())
- sleep 150
+ sleep 500
'# running should be false
assert_false(child->running)
@@ -139,6 +138,8 @@ namespace Suite_Test_Console_Process '# exit_code should be 0
assert_equal(0, child->exit_code)
+ delete child
+
'# file must exists
assert_true(fileexists("both.log"))
@@ -148,11 +149,7 @@ namespace Suite_Test_Console_Process assert_not_equal(0, instr(content, "out: message"))
assert_not_equal(0, instr(content, "err: error"))
- '# cleanup
- process_cleanup()
- assert_equal_error(0, kill("both.log"))
-
- delete child
+ assert_equal(0, kill("both.log"))
end sub
sub test_redirected_output_append()
@@ -165,21 +162,19 @@ namespace Suite_Test_Console_Process '# start() will be true since process terminated nicely
assert_true(child->start())
- sleep 150
+ sleep 500
content = content_of_file("both.log")
'# start() again
assert_true(child->start())
- sleep 150
+ sleep 500
- assert_not_equal(len(content), len(content_of_file("both.log")))
+ delete child
- '# cleanup
- process_cleanup()
- assert_equal_error(0, kill("both.log"))
+ assert_not_equal(len(content), len(content_of_file("both.log")))
- delete child
+ assert_equal(0, kill("both.log"))
end sub
sub test_process_terminate()
@@ -191,7 +186,7 @@ namespace Suite_Test_Console_Process '# start
assert_true(child->start())
- sleep 150
+ sleep 500
'# validate if running
assert_true(child->running)
@@ -201,13 +196,15 @@ namespace Suite_Test_Console_Process '# now terminates it
assert_true(child->terminate())
- sleep 150
+ sleep 500
assert_equal(9, child->exit_code)
'# it should be done
assert_false(child->running)
+ delete child
+
'# validate output
'# file must exists
assert_true(fileexists("both.log"))
@@ -219,23 +216,61 @@ namespace Suite_Test_Console_Process assert_not_equal(0, instr(content, "err: error"))
assert_not_equal(0, instr(content, "interrupted"))
- '# cleanup
- process_cleanup()
- assert_equal_error(0, kill("both.log"))
+ assert_equal(0, kill("both.log"))
+ end sub
+
+ sub test_process_terminate_slow1()
+ dim content as string
+
+ '# redirected output is used with logging files.
+ child = new ConsoleProcess("mock_process.exe", "slow1")
+ child->redirect(ProcessStdBoth, "both_slow1.log")
+
+ '# start
+ assert_true(child->start())
+ sleep 500
+
+ '# validate if running
+ assert_true(child->running)
+
+ '# validate PID
+ assert_not_equal(0, child->pid)
+
+ '# now terminates it
+ assert_true(child->terminate())
+ sleep 500
+
+ assert_equal(10, child->exit_code)
+
+ '# it should be done
+ assert_false(child->running)
delete child
+
+ '# validate output
+ '# file must exists
+ assert_true(fileexists("both_slow1.log"))
+
+ '# contents must match
+ content = content_of_file("both_slow1.log")
+
+ assert_equal(0, instr(content, "interrupted"))
+ assert_not_equal(0, instr(content, "out: CTRL-C received"))
+ assert_equal(0, instr(content, "out: CTRL-BREAK received"))
+
+ assert_equal(0, kill("both_slow1.log"))
end sub
- sub test_process_terminate_slow()
+ sub test_process_terminate_slow2()
dim content as string
'# redirected output is used with logging files.
- child = new ConsoleProcess("mock_process.exe", "slow")
- child->redirect(ProcessStdBoth, "both_slow.log")
+ child = new ConsoleProcess("mock_process.exe", "slow2")
+ child->redirect(ProcessStdBoth, "both_slow2.log")
'# start
assert_true(child->start())
- sleep 150
+ sleep 500
'# validate if running
assert_true(child->running)
@@ -245,34 +280,32 @@ namespace Suite_Test_Console_Process '# now terminates it
assert_true(child->terminate())
- sleep 150
+ sleep 500
+
+ assert_equal(20, child->exit_code)
- '# it should be done now
+ '# it should be done
assert_false(child->running)
- assert_equal(10, child->exit_code)
+
+ delete child
'# validate output
'# file must exists
- assert_true(fileexists("both_slow.log"))
+ assert_true(fileexists("both_slow2.log"))
'# contents must match
- content = content_of_file("both_slow.log")
+ content = content_of_file("both_slow2.log")
- assert_not_equal(0, instr(content, "out: message"))
- assert_not_equal(0, instr(content, "err: error"))
- assert_not_equal(0, instr(content, "out: slow stop"))
assert_equal(0, instr(content, "interrupted"))
+ assert_not_equal(0, instr(content, "out: CTRL-C received"))
+ assert_not_equal(0, instr(content, "out: CTRL-BREAK received"))
'# cleanup
- process_cleanup()
- assert_equal_error(0, kill("both_slow.log"))
-
- delete child
+ assert_equal(0, kill("both_slow2.log"))
end sub
-
+
sub test_process_terminate_forced()
dim content as string
- dim x as integer
'# redirected output is used with logging files.
child = new ConsoleProcess("mock_process.exe", "wait")
@@ -280,7 +313,7 @@ namespace Suite_Test_Console_Process '# start
assert_true(child->start())
- sleep 150
+ sleep 500
'# validate if running
assert_true(child->running)
@@ -290,7 +323,7 @@ namespace Suite_Test_Console_Process '# now terminates it
assert_true(child->terminate(true))
- sleep 150
+ sleep 500
'# it should be done
assert_false(child->running)
@@ -298,6 +331,8 @@ namespace Suite_Test_Console_Process '# look for termination code
assert_equal(0, child->exit_code)
+ delete child
+
'# validate output
'# file must exists
assert_true(fileexists("both_forced.log"))
@@ -309,11 +344,7 @@ namespace Suite_Test_Console_Process assert_equal(0, instr(content, "err: error"))
assert_equal(0, instr(content, "interrupted"))
- '# cleanup
- process_cleanup()
- assert_equal_error(0, kill("both_forced.log"))
-
- delete child
+ assert_equal(0, kill("both_forced.log"))
end sub
sub test_reuse_object_instance()
@@ -323,7 +354,7 @@ namespace Suite_Test_Console_Process '# start
assert_true(child->start())
- sleep 150
+ sleep 500
'# validate not running
assert_false(child->running)
@@ -336,16 +367,13 @@ namespace Suite_Test_Console_Process '# start it again
assert_true(child->start())
- sleep 150
+ sleep 500
'# it should have stopped by now
assert_false(child->running)
assert_not_equal(0, child->pid)
assert_not_equal(first_pid, child->pid)
- '# cleanup
- process_cleanup()
-
delete child
end sub
@@ -360,7 +388,8 @@ namespace Suite_Test_Console_Process add_test(test_redirected_merged_output)
add_test(test_redirected_output_append)
add_test(test_process_terminate)
- add_test(test_process_terminate_slow)
+ add_test(test_process_terminate_slow1)
+ add_test(test_process_terminate_slow2)
add_test(test_process_terminate_forced)
add_test(test_reuse_object_instance)
end sub
diff --git a/projects/mongrel_service/tests/test_helpers.bas b/projects/mongrel_service/tests/test_helpers.bas index 69b74cd..c4647c0 100644 --- a/projects/mongrel_service/tests/test_helpers.bas +++ b/projects/mongrel_service/tests/test_helpers.bas @@ -33,5 +33,3 @@ function content_of_file(byref filename as string) as string return result
end function
-
-print content_of_file("testing.log")
|