Revision: 63688bea5413
Branch:   default
Author:   Pekka Klärck
Date:     Thu Sep 13 00:51:11 2012
Log: Cleaned up signal handler acceptance tests. Having interpreter specific %{TEMPDIR} is great.
http://code.google.com/p/robotframework/source/detail?r=63688bea5413

Modified:
 /atest/robot/running/ProcessManager.py
 /atest/robot/running/stopping_with_signal.txt
 /atest/testdata/running/stopping_with_signal/keyword_timeout.txt
 /atest/testdata/running/stopping_with_signal/run_keyword.txt
 /atest/testdata/running/stopping_with_signal/swallow_exception.txt
 /atest/testdata/running/stopping_with_signal/test_timeout.txt
 /atest/testdata/running/stopping_with_signal/with_teardown.txt
 /atest/testdata/running/stopping_with_signal/without_any_timeout.txt

=======================================
--- /atest/robot/running/ProcessManager.py      Mon Sep  3 09:06:55 2012
+++ /atest/robot/running/ProcessManager.py      Thu Sep 13 00:51:11 2012
@@ -2,21 +2,20 @@
 import os
 import signal
 import ctypes
-import time


 class ProcessManager(object):

     def __init__(self):
         self._process = None
-        self._stdout = ''
-        self._stderr = ''
+        self._stdout = None
+        self._stderr = None

     def start_process(self, *args):
         self._process = subprocess.Popen(args, stderr=subprocess.PIPE,
                                          stdout=subprocess.PIPE)
-        self._stdout = ''
-        self._stderr = ''
+        self._stdout = None
+        self._stderr = None

     def send_terminate(self, signal_name):
         if os.name != 'nt':
@@ -39,18 +38,16 @@
         return self._stderr

     def log_stdout_and_stderr(self):
-        print "stdout: ", self._process.stdout.read()
-        print "stderr: ", self._process.stderr.read()
+        self.wait_until_finished()
+        print 'STDOUT:'
+        print self._stdout
+        print 'STDERR:'
+        print self._stderr

     def wait_until_finished(self):
-        if self._process.returncode is None:
+        if self._stdout is None:
             self._stdout, self._stderr = self._process.communicate()

-    def busy_sleep(self, seconds):
-        max_time = time.time() + int(seconds)
-        while time.time() < max_time:
-            pass
-
     def get_runner(self, interpreter, robot_path):
         run = os.path.join(robot_path, 'run.py')
         if 'jython' not in interpreter:
@@ -74,4 +71,3 @@
         jython_jar = os.path.join(jython_home, 'jython.jar')
         cp = jython_jar + os.pathsep + os.getenv('CLASSPATH', '')
         return cp.strip(':;')
-
=======================================
--- /atest/robot/running/stopping_with_signal.txt       Wed Sep 12 15:17:39 2012
+++ /atest/robot/running/stopping_with_signal.txt       Thu Sep 13 00:51:11 2012
@@ -3,67 +3,68 @@
 Default Tags    pybot  jybot
 Resource        atest_resource.txt
 Library         ProcessManager.py
-Test Teardown   Log Info From Process And Cleanup
-Suite Setup     Set Timestamp
-Test Setup      Set Test Debug File
+Test Teardown   Run Keyword If Test Failed    Log Stdout And Stderr

+*** Variables ***
+${TEST FILE}    %{TEMPDIR}${/}signal-tests.txt
+

 *** Test Cases ***
 SIGINT Signal Should Stop Test Execution Gracefully
-    Start And Send Signal  without_any_timeout.txt  One Signal  SIGINT
+    Start And Send Signal  without_any_timeout.txt  One SIGINT
     Process Output For Graceful Shutdown
     Check Test Cases Have Failed Correctly

 SIGTERM Signal Should Stop Test Execution Gracefully
     [Tags]  pybot  jybot  x-exclude-on-windows
-    Start And Send Signal  without_any_timeout.txt  One Signal  SIGTERM
+    Start And Send Signal  without_any_timeout.txt  One SIGTERM
     Process Output For Graceful Shutdown
     Check Test Cases Have Failed Correctly

 Execution Is Stopped Even If Keyword Swallows Exception
     [Tags]  pybot
-    Start And Send Signal  swallow_exception.txt  One Signal  SIGTERM
+    Start And Send Signal  swallow_exception.txt  One SIGTERM
     Process Output For Graceful Shutdown
     Check Test Cases Have Failed Correctly

 One Signal Should Stop Test Execution Gracefully When Run Keyword Is Used
-    Start And Send Signal  run_keyword.txt  One Signal  SIGTERM
+    Start And Send Signal  run_keyword.txt  One SIGTERM
     Process Output For Graceful Shutdown
     Check Test Cases Have Failed Correctly

 One Signal Should Stop Test Execution Gracefully When Test Timeout Is Used
-    Start And Send Signal  test_timeout.txt  One Signal  SIGTERM
+    Start And Send Signal  test_timeout.txt  One SIGTERM
     Process Output For Graceful Shutdown
     Check Test Cases Have Failed Correctly

One Signal Should Stop Test Execution Gracefully When Keyword Timeout Is Used
-    Start And Send Signal  keyword_timeout.txt  One Signal  SIGTERM
+    Start And Send Signal  keyword_timeout.txt  One SIGTERM
     Process Output For Graceful Shutdown
     Check Test Cases Have Failed Correctly

 Two SIGINT Signals Should Stop Test Execution Forcefully
-    Start And Send Signal  without_any_timeout.txt  Two Signals  SIGINT  2s
+    Start And Send Signal  without_any_timeout.txt  Two SIGINTs  2s
     Check Tests Have Been Forced To Shutdown

 Two SIGTERM Signals Should Stop Test Execution Forcefully
     [Tags]  pybot  jybot  x-exclude-on-windows
- Start And Send Signal without_any_timeout.txt Two Signals SIGTERM 2s
+    Start And Send Signal  without_any_timeout.txt  Two SIGTERMs  2s
     Check Tests Have Been Forced To Shutdown

 Two Signals Should Stop Test Execution Forcefully When Run Keyword Is Used
-    Start And Send Signal  run_keyword.txt  Two Signals  SIGINT  2s
+    Start And Send Signal  run_keyword.txt  Two SIGINTs  2s
     Check Tests Have Been Forced To Shutdown

 Two Signals Should Stop Test Execution Forcefully When Test Timeout Is Used
-    Start And Send Signal  test_timeout.txt  Two Signals  SIGINT  2s
+    Start And Send Signal  test_timeout.txt  Two SIGINTs  2s
     Check Tests Have Been Forced To Shutdown

Two Signals Should Stop Test Execution Forcefully When Keyword Timeout Is Used
-    Start And Send Signal  keyword_timeout.txt  Two Signals  SIGINT  2s
+    Start And Send Signal  keyword_timeout.txt  Two SIGINTs  2s
     Check Tests Have Been Forced To Shutdown

One Signal Should Stop Test Execution Gracefully And Test Case And Suite Teardowns Should Be Run
-    Start And Send Signal  with_teardown.txt  One Signal  SIGINT
+    Start And Send Signal  with_teardown.txt  One SIGINT
     Process Output For Graceful Shutdown
     Check Test Cases Have Failed Correctly
     ${tc} =  Get Test Case  Test
@@ -72,7 +73,7 @@
Check Log Message ${ts.teardown.kws[0].msgs[0]} Logging Suite Teardown

One Signal Should Stop Test Execution Gracefully And Skip Teardowns With Runmode - Start And Send Signal with_teardown.txt One Signal SIGINT runmode=SkipTeardownOnExit + Start And Send Signal with_teardown.txt One SIGINT runmode=SkipTeardownOnExit
     Process Output For Graceful Shutdown
     Check Test Cases Have Failed Correctly
     ${tc} =  Get Test Case  Test
@@ -83,57 +84,52 @@

 *** Keywords ***
 Start And Send Signal
- [Arguments] ${testcase file} ${signal method} ${signal} ${teardown sleep}=0s ${runmode}=normal
-    ${jython} =  Running On Jython  ${INTERPRETER}
- ${testfile} = Set Variable If ${jython} robot_signal_test_jython.txt robot_signal_test_python.txt
-    Remove File  %{TEMPDIR}/${testfile}
- Start Run ${testfile} running/stopping_with_signal/${testcase file} ${teardown sleep} ${runmode}
-    Wait Until Created  %{TEMPDIR}/${testfile}  1 minutes
-    Run Keyword  ${signal method}  ${signal}
-    Wait Until Finished With Timeout
-
-Wait Until Finished With Timeout
-    [timeout]  1 minute
-    wait until finished
+ [Arguments] ${datasource} ${signals} ${sleep}=0s ${runmode}=normal
+    Remove File    ${TEST FILE}
+    Start Run    ${datasource}    ${sleep}    ${runmode}
+    Wait Until Created    ${TESTFILE}    timeout=45s
+    Run Keyword    ${signals}
+    Wait Until Finished

 Start Run
- [arguments] ${test signal file} ${datasource} ${teardown sleep} ${runmode}
+    [Arguments]    ${datasource}    ${sleep}    ${runmode}
     Set Runners
- ${path to datasource} = Set Variables And Get Datasources ${datasource} + ${datasource} = Set Variables And Get Datasources running/stopping_with_signal/${datasource}
     @{runner} =    Get Runner    ${INTERPRETER}    ${ROBOTPATH}
- @{command} = Create List @{runner} --variable TESTSIGNALFILE:${test signal file} --output ${OUTFILE} --report None --log None --debugfile ${TEST DEBUG FILE} --variable TEARDOWNSLEEP:${teardown sleep} --runmode ${runmode} ${path to datasource}
-    Log Many  @{command}
-    ProcessManager.start process  @{command}
+    @{command} =    Create List
+    ...    @{runner}
+    ...    --output    ${OUTFILE}    --report    NONE    --log    NONE
+    ...    --variable    TESTSIGNALFILE:${TEST FILE}
+    ...    --variable    TEARDOWNSLEEP:${sleep}
+    ...    --runmode    ${runmode}
+    ...    ${datasource}
+    Log Many    @{command}
+    ProcessManager.start process    @{command}

 Check Test Cases Have Failed Correctly
-    Check Test Case  Test  FAIL  Execution terminated by signal
- Check Test Case Test2 FAIL Test execution is stopped due to a fatal error
+    Check Test Case    Test    FAIL    Execution terminated by signal
+ Check Test Case Test2 FAIL Test execution is stopped due to a fatal error

 Check Tests Have Been Forced To Shutdown
-    ${stderr string}  ProcessManager.Get Stderr
-    Should Contain  ${stderr string}  Execution forcefully stopped
+    ${stderr} =    ProcessManager.Get Stderr
+    Should Contain    ${stderr}    Execution forcefully stopped

 Process Output For Graceful Shutdown
-    Wait Until Created  ${OUTFILE}
-    Process Output  ${OUTFILE}
+    Wait Until Created    ${OUTFILE}    timeout=45s
+    Process Output    ${OUTFILE}

-One Signal
-    [arguments]  ${signal}
-    send terminate  ${signal}
+One SIGINT
+    Send Terminate    SIGINT

-Two Signals
-    [arguments]  ${signal}
-    send terminate  ${signal}
-    Busy Sleep  1
-    send terminate  ${signal}
+One SIGTERM
+    Send Terminate    SIGTERM

-Set Timestamp
-    ${tmp time} =  Get Time
-    Set Suite Variable  ${TEST TIMESTAMP}  ${tmp time}
+Two SIGINTs
+    One SIGINT
+    Sleep    1s
+    One SIGINT

-Set Test Debug File
- Set Test Variable ${TEST DEBUG FILE} %{TEMPDIR}/${TESTNAME}_${TEST TIMESTAMP}.txt
-
-Log Info From Process And Cleanup
-    Run Keyword If Test Failed  Log Stdout And Stderr
-    Run Keyword If Test Passed  Remove File  ${TEST DEBUG FILE}
+Two SIGTERMs
+    One SIGTERM
+    Sleep    1s
+    One SIGTERM
=======================================
--- /atest/testdata/running/stopping_with_signal/keyword_timeout.txt Wed Sep 12 15:17:39 2012 +++ /atest/testdata/running/stopping_with_signal/keyword_timeout.txt Thu Sep 13 00:51:11 2012
@@ -2,14 +2,10 @@
 Library  Library.py
 Library  OperatingSystem
 Suite Teardown  Sleep  ${TEARDOWN SLEEP}
-
-*** Variables ***
-${TEARDOWN SLEEP} =  0 seconds
-${TESTSIGNALFILE} =  test_signal_file.txt

 *** Test Case ***
 Test
-  Create File  %{TEMPDIR}/${TESTSIGNALFILE}
+  Create File  ${TESTSIGNALFILE}
   Timeout In UK
   No operation

=======================================
--- /atest/testdata/running/stopping_with_signal/run_keyword.txt Wed Sep 12 15:17:39 2012 +++ /atest/testdata/running/stopping_with_signal/run_keyword.txt Thu Sep 13 00:51:11 2012
@@ -2,14 +2,10 @@
 Library  Library.py
 Library  OperatingSystem
 Suite Teardown  Sleep  ${TEARDOWN SLEEP}
-
-*** Variables ***
-${TEARDOWN SLEEP} =  0 seconds
-${TESTSIGNALFILE} =  test_signal_file.txt

 *** Test Case ***
 Test
-  Create File  %{TEMPDIR}/${TESTSIGNALFILE}
+  Create File  ${TESTSIGNALFILE}
   Run Keyword  Busy Sleep  2
   No Operation

=======================================
--- /atest/testdata/running/stopping_with_signal/swallow_exception.txt Wed Sep 12 15:17:39 2012 +++ /atest/testdata/running/stopping_with_signal/swallow_exception.txt Thu Sep 13 00:51:11 2012
@@ -2,14 +2,10 @@
 Library  Library.py
 Library  OperatingSystem
 Suite Teardown  Sleep  ${TEARDOWN SLEEP}
-
-*** Variables ***
-${TEARDOWN SLEEP} =  0 seconds
-${TESTSIGNALFILE} =  test_signal_file.txt

 *** Test Case ***
 Test
-    Create File  %{TEMPDIR}/${TESTSIGNALFILE}
+    Create File  ${TESTSIGNALFILE}
     Swallow exception
     Fail  Should not be executed

=======================================
--- /atest/testdata/running/stopping_with_signal/test_timeout.txt Wed Sep 12 15:17:39 2012 +++ /atest/testdata/running/stopping_with_signal/test_timeout.txt Thu Sep 13 00:51:11 2012
@@ -2,14 +2,10 @@
 Library  Library.py
 Library  OperatingSystem
 Suite Teardown  Sleep  ${TEARDOWN SLEEP}
-
-*** Variables ***
-${TEARDOWN SLEEP} =  0 seconds
-${TESTSIGNALFILE} =  test_signal_file.txt

 *** Test Case ***
 Test  [timeout]  3 Seconds
-  Create File  %{TEMPDIR}/${TESTSIGNALFILE}
+  Create File  ${TESTSIGNALFILE}
   Busy Sleep  2
   No Operation

=======================================
--- /atest/testdata/running/stopping_with_signal/with_teardown.txt Wed Sep 12 15:17:39 2012 +++ /atest/testdata/running/stopping_with_signal/with_teardown.txt Thu Sep 13 00:51:11 2012
@@ -3,13 +3,9 @@
 Library  OperatingSystem
 Suite Teardown  My Suite Teardown

-*** Variables ***
-${TEARDOWN SLEEP} =  0 seconds
-${TESTSIGNALFILE} =  test_signal_file.txt
-
 *** Test Case ***
 Test
-  Create File  %{TEMPDIR}/${TESTSIGNALFILE}
+  Create File  ${TESTSIGNALFILE}
   Busy Sleep  2
   No Operation
   [teardown]  Log  Logging Test Case Teardown
=======================================
--- /atest/testdata/running/stopping_with_signal/without_any_timeout.txt Wed Sep 12 15:17:39 2012 +++ /atest/testdata/running/stopping_with_signal/without_any_timeout.txt Thu Sep 13 00:51:11 2012
@@ -2,14 +2,10 @@
 Library  Library.py
 Library  OperatingSystem
 Suite Teardown  Sleep  ${TEARDOWN SLEEP}
-
-*** Variables ***
-${TEARDOWN SLEEP} =  0 seconds
-${TESTSIGNALFILE} =  test_signal_file.txt

 *** Test Case ***
 Test
-  Create File  %{TEMPDIR}/${TESTSIGNALFILE}
+  Create File  ${TESTSIGNALFILE}
   Busy Sleep  2
   No Operation

Reply via email to