Changeset 1012

Show
Ignore:
Timestamp:
04/18/08 02:09:44 (3 months ago)
Author:
luislavena
Message:

Wait longer for child process terminate properly (max 20 seconds).
Imported tests from RubyServices? project. (Closes #18).

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/stable_1-2

    • Property bzr:revision-id:v3-trunk0 changed from
      814 luislavena@gmail.com-20080331074345-8r7ghwi05bwwqz7f
      815 luislavena@gmail.com-20080331075048-t48wb12km03z1k7d
      816 luislavena@gmail.com-20080331081757-x3m83b2w24vlgbhz
      817 luislavena@gmail.com-20080406001418-f6mxbnyordlkvosz
      822 luislavena@gmail.com-20080418001345-y6hgwpxkfc5qml6v
      823 luislavena@gmail.com-20080418001931-wxuitk2diz0s32cu
      824 luislavena@gmail.com-20080418001955-wdpwvupki3pe6mu4
      825 luislavena@gmail.com-20080418065700-yx69onb815nh8zgg
      to
      814 luislavena@gmail.com-20080331074345-8r7ghwi05bwwqz7f
      815 luislavena@gmail.com-20080331075048-t48wb12km03z1k7d
      816 luislavena@gmail.com-20080331081757-x3m83b2w24vlgbhz
      817 luislavena@gmail.com-20080406001418-f6mxbnyordlkvosz
      822 luislavena@gmail.com-20080418001345-y6hgwpxkfc5qml6v
      823 luislavena@gmail.com-20080418001931-wxuitk2diz0s32cu
      824 luislavena@gmail.com-20080418001955-wdpwvupki3pe6mu4
      825 luislavena@gmail.com-20080418065700-yx69onb815nh8zgg
      826 luislavena@gmail.com-20080418070615-2a0sikp3sfacwy2k
    • Property bzr:revision-info changed from
      timestamp: 2008-04-18 03:57:00.687000036 -0300
      committer: Luis Lavena <luislavena@gmail.com>
      properties:
      branch-nick: stable_1-2
      to
      timestamp: 2008-04-18 04:06:15.515000105 -0300
      committer: Luis Lavena <luislavena@gmail.com>
      properties:
      branch-nick: stable_1-2
  • branches/stable_1-2/projects/mongrel_service/CHANGELOG

    r1007 r1012  
     1* 0.3.5 * 
     2 
     3    * Wait longer for child process terminate properly (max 20 seconds). Imported 
     4    tests from RubyServices project. (Closes #18). 
     5    * Updated ServiceFB to work with FB > 0.18. 
    16 
    27* 0.3.4 * 
  • branches/stable_1-2/projects/mongrel_service/native/console_process.bas

    r623 r1012  
    8282 
    8383property ConsoleProcess.exit_code() as uinteger 
     84    static previous_code as uinteger 
    8485    dim result as uinteger 
    8586     
     
    9192            '# the process reference is valid, get the exit_code 
    9293            if not (GetExitCodeProcess(_process_info.hProcess, @result) = 0) then 
     94                previous_code = result 
    9395                '# OK 
    9496                '# no error in the query, get result 
     97                if not (result = STILL_ACTIVE) then 
     98                    CloseHandle(_process_info.hProcess) 
     99                    _process_info.hProcess = NULL 
     100                end if '# (result = STILL_ACTIVE) 
    95101            end if '# not (GetExitCodeProcess() = 0) 
     102        else 
     103            result = previous_code 
    96104        end if '# not (proc = NULL) 
    97105    end if '# not (_pid = 0) 
     
    229237                '# use pipes instead 
    230238                '# StdOut 
    231                 if (CreatePipe(@StdErrRd, @StdErrWr, @proc_sa, 0) = 0) then  
     239                if (CreatePipe(@StdErrRd, @StdErrWr, @proc_sa, 0) = 0) then 
    232240                    success = false 
    233241                end if 
     
    284292                CloseHandle(StdErrWr) 
    285293                 
    286                 '# close children main Thread handle 
    287                 'CloseHandle(proc.hThread) 
    288                 'CloseHandle(proc.hProcess
    289                  
     294                '# close children main Thread handle and 
     295                '# NULLify to avoid issues 
     296                CloseHandle(_process_info.hThread
     297                _process_info.hThread = NULL 
    290298            end if '# (CreateProcess() = 0) 
    291299        else 
     
    323331                    if not (GenerateConsoleCtrlEvent(CTRL_C_EVENT, 0) = 0) then 
    324332                        '# it worked, wait 5 seconds terminates. 
    325                         wait_code = WaitForSingleObject(proc, 5000) 
     333                        wait_code = WaitForSingleObject(proc, 10000) 
    326334                        if not (wait_code = WAIT_TIMEOUT) then 
    327335                            success = true 
     
    336344                        if not (GenerateConsoleCtrlEvent(CTRL_BREAK_EVENT, 0) = 0) then 
    337345                            '# it worked, wait 5 seconds terminates. 
    338                             wait_code = WaitForSingleObject(proc, 5000)  
     346                            wait_code = WaitForSingleObject(proc, 10000)  
    339347                            if not (wait_code = WAIT_TIMEOUT) then 
    340348                                success = true 
  • branches/stable_1-2/projects/mongrel_service/tests/test_console_process.bas

    r1009 r1012  
    3131    sub test_process_create() 
    3232        child = new ConsoleProcess() 
    33         assert_not_equal_error(0, child) 
     33        assert_not_equal(0, child) 
    3434        assert_equal("", child->filename) 
    3535        assert_equal("", child->arguments) 
     
    6565        '# improperly 
    6666        assert_true(child->start()) 
    67         sleep 15
     67        sleep 50
    6868         
    6969        '# should not be running, but pid should be != than 0 
     
    8181     
    8282    sub test_redirected_output() 
     83        assert_false(fileexists("out.log")) 
     84        assert_false(fileexists("err.log")) 
     85         
    8386        '# redirected output is used with logging files. 
    8487        child = new ConsoleProcess("mock_process.exe") 
     
    9497        '# start() will be true since process terminated nicely 
    9598        assert_true(child->start()) 
    96         sleep 15
     99        sleep 50
    97100         
    98101        '# running should be false 
     
    101104        '# exit_code should be 0 
    102105        assert_equal(0, child->exit_code) 
     106         
     107        delete child 
    103108         
    104109        '# now out.log and err.log must exist and content must be valid. 
     
    109114        assert_string_equal("err: error", content_of_file("err.log")) 
    110115         
    111         '# cleanup 
    112         process_cleanup() 
    113         assert_equal_error(0, kill("out.log")) 
    114         assert_equal_error(0, kill("err.log")) 
    115          
    116         assert_true_error(fileexists("err.log")) 
    117          
    118         delete child 
     116        assert_equal(0, kill("out.log")) 
     117        assert_equal(0, kill("err.log")) 
    119118    end sub 
    120119     
     
    132131        '# start() will be true since process terminated nicely 
    133132        assert_true(child->start()) 
    134         sleep 15
     133        sleep 50
    135134         
    136135        '# running should be false 
     
    140139        assert_equal(0, child->exit_code) 
    141140         
     141        delete child 
     142         
    142143        '# file must exists 
    143144        assert_true(fileexists("both.log")) 
     
    149150        assert_not_equal(0, instr(content, "err: error")) 
    150151         
    151         '# cleanup 
    152         process_cleanup() 
    153         assert_equal_error(0, kill("both.log")) 
    154          
    155         delete child 
     152        assert_equal(0, kill("both.log")) 
    156153    end sub 
    157154     
     
    166163        '# start() will be true since process terminated nicely 
    167164        assert_true(child->start()) 
    168         sleep 15
     165        sleep 50
    169166         
    170167        content = content_of_file("both.log") 
     
    172169        '# start() again 
    173170        assert_true(child->start()) 
    174         sleep 150 
     171        sleep 500 
     172         
     173        delete child 
    175174         
    176175        assert_not_equal(len(content), len(content_of_file("both.log"))) 
    177176         
    178         '# cleanup 
    179         process_cleanup() 
    180         assert_equal_error(0, kill("both.log")) 
    181          
    182         delete child 
     177        assert_equal(0, kill("both.log")) 
    183178    end sub 
    184179     
     
    192187        '# start 
    193188        assert_true(child->start()) 
    194         sleep 15
     189        sleep 50
    195190         
    196191        '# validate if running 
     
    202197        '# now terminates it 
    203198        assert_true(child->terminate()) 
    204         sleep 15
     199        sleep 50
    205200         
    206201        assert_equal(9, child->exit_code) 
     
    208203        '# it should be done 
    209204        assert_false(child->running) 
     205         
     206        delete child 
    210207         
    211208        '# validate output 
     
    220217        assert_not_equal(0, instr(content, "interrupted")) 
    221218         
    222         '# cleanup 
    223         process_cleanup() 
    224         assert_equal_error(0, kill("both.log")) 
    225          
    226         delete child 
    227     end sub 
    228      
    229     sub test_process_terminate_slow() 
    230         dim content as string 
    231          
    232         '# redirected output is used with logging files. 
    233         child = new ConsoleProcess("mock_process.exe", "slow") 
    234         child->redirect(ProcessStdBoth, "both_slow.log") 
     219        assert_equal(0, kill("both.log")) 
     220    end sub 
     221     
     222    sub test_process_terminate_slow1() 
     223        dim content as string 
     224         
     225        '# redirected output is used with logging files. 
     226        child = new ConsoleProcess("mock_process.exe", "slow1") 
     227        child->redirect(ProcessStdBoth, "both_slow1.log") 
    235228         
    236229        '# start 
    237230        assert_true(child->start()) 
    238         sleep 15
     231        sleep 50
    239232         
    240233        '# validate if running 
     
    246239        '# now terminates it 
    247240        assert_true(child->terminate()) 
    248         sleep 150 
    249          
    250         '# it should be done now 
    251         assert_false(child->running) 
     241        sleep 500 
     242         
    252243        assert_equal(10, child->exit_code) 
     244         
     245        '# it should be done 
     246        assert_false(child->running) 
     247         
     248        delete child 
    253249         
    254250        '# validate output 
    255251        '# file must exists 
    256         assert_true(fileexists("both_slow.log")) 
     252        assert_true(fileexists("both_slow1.log")) 
    257253         
    258254        '# contents must match 
    259         content = content_of_file("both_slow.log") 
    260          
    261         assert_not_equal(0, instr(content, "out: message")) 
    262         assert_not_equal(0, instr(content, "err: error")) 
    263         assert_not_equal(0, instr(content, "out: slow stop")) 
     255        content = content_of_file("both_slow1.log") 
     256         
    264257        assert_equal(0, instr(content, "interrupted")) 
     258        assert_not_equal(0, instr(content, "out: CTRL-C received")) 
     259        assert_equal(0, instr(content, "out: CTRL-BREAK received")) 
     260         
     261        assert_equal(0, kill("both_slow1.log")) 
     262    end sub 
     263     
     264    sub test_process_terminate_slow2() 
     265        dim content as string 
     266         
     267        '# redirected output is used with logging files. 
     268        child = new ConsoleProcess("mock_process.exe", "slow2") 
     269        child->redirect(ProcessStdBoth, "both_slow2.log") 
     270         
     271        '# start 
     272        assert_true(child->start()) 
     273        sleep 500 
     274         
     275        '# validate if running 
     276        assert_true(child->running) 
     277         
     278        '# validate PID 
     279        assert_not_equal(0, child->pid) 
     280         
     281        '# now terminates it 
     282        assert_true(child->terminate()) 
     283        sleep 500 
     284         
     285        assert_equal(20, child->exit_code) 
     286         
     287        '# it should be done 
     288        assert_false(child->running) 
     289         
     290        delete child 
     291         
     292        '# validate output 
     293        '# file must exists 
     294        assert_true(fileexists("both_slow2.log")) 
     295         
     296        '# contents must match 
     297        content = content_of_file("both_slow2.log") 
     298         
     299        assert_equal(0, instr(content, "interrupted")) 
     300        assert_not_equal(0, instr(content, "out: CTRL-C received")) 
     301        assert_not_equal(0, instr(content, "out: CTRL-BREAK received")) 
    265302         
    266303        '# cleanup 
    267         process_cleanup() 
    268         assert_equal_error(0, kill("both_slow.log")) 
    269          
    270         delete child 
    271     end sub 
    272      
     304        assert_equal(0, kill("both_slow2.log")) 
     305    end sub 
     306 
    273307    sub test_process_terminate_forced() 
    274308        dim content as string 
    275         dim x as integer 
    276309         
    277310        '# redirected output is used with logging files. 
     
    281314        '# start 
    282315        assert_true(child->start()) 
    283         sleep 15
     316        sleep 50
    284317         
    285318        '# validate if running 
     
    291324        '# now terminates it 
    292325        assert_true(child->terminate(true)) 
    293         sleep 15
     326        sleep 50
    294327         
    295328        '# it should be done 
     
    298331        '# look for termination code 
    299332        assert_equal(0, child->exit_code) 
     333         
     334        delete child 
    300335         
    301336        '# validate output 
     
    310345        assert_equal(0, instr(content, "interrupted")) 
    311346         
    312         '# cleanup 
    313         process_cleanup() 
    314         assert_equal_error(0, kill("both_forced.log")) 
    315          
    316         delete child 
     347        assert_equal(0, kill("both_forced.log")) 
    317348    end sub 
    318349     
     
    324355        '# start 
    325356        assert_true(child->start()) 
    326         sleep 15
     357        sleep 50
    327358         
    328359        '# validate not running 
     
    337368        '# start it again 
    338369        assert_true(child->start()) 
    339         sleep 15
     370        sleep 50
    340371         
    341372        '# it should have stopped by now 
     
    343374        assert_not_equal(0, child->pid) 
    344375        assert_not_equal(first_pid, child->pid) 
    345          
    346         '# cleanup 
    347         process_cleanup() 
    348376         
    349377        delete child 
     
    361389        add_test(test_redirected_output_append) 
    362390        add_test(test_process_terminate) 
    363         add_test(test_process_terminate_slow) 
     391        add_test(test_process_terminate_slow1) 
     392        add_test(test_process_terminate_slow2) 
    364393        add_test(test_process_terminate_forced) 
    365394        add_test(test_reuse_object_instance) 
  • branches/stable_1-2/projects/mongrel_service/tests/test_helpers.bas

    r1009 r1012  
    3434    return result 
    3535end function 
    36  
    37 print content_of_file("testing.log")