test-fullautomation / robotframework

Generic automation framework for acceptance testing and RPA
http://robotframework.org
Apache License 2.0
1 stars 0 forks source link

threading: local scope of thread overwritten in case of reentrance of keyword #50

Closed test-fullautomation closed 2 months ago

test-fullautomation commented 7 months ago

threading: local scope of thread overwritten in case of reentrance of keyword


*** Settings **
Library    Collections
Library    String

*** Keywords ***

#
#    Threading payload base keywords
#
################################################################################
threading_keyword_multiple_time_called.keyword
    [Arguments]    ${msg}=""    ${waittime}=5
    Log    Entering Thread ${msg}    console=True
    sleep    ${waittime}
    Log    Closing Thread ${msg}    console=True

*** Test Cases ***
Threading Keyword Multiple Time Called
#    ${payload1} =    Evaluate    {'CLIENT':{'NAME':'NAME','ID':1},'SERVER': {'ID':2,'IP':'172.17.0.4','PORT':'12345'},'SERVICE':{'ID':'ECHOSERVICE'}}
#
    THREAD    TEST_THREAD1    False
        threading_keyword_multiple_time_called.keyword    msg="thrd1"    waittime=5
    END

    THREAD    TEST_THREAD2    False
        threading_keyword_multiple_time_called.keyword    msg="thrd2"    waittime=1
    END

    THREAD    TEST_THREAD3    False
        threading_keyword_multiple_time_called.keyword    msg="thrd3"    waittime=1
    END

    THREAD    TEST_THREAD4    False
        threading_keyword_multiple_time_called.keyword    msg="thrd4"    waittime=1
    END

    Sleep    10

Results in unexpected: should be "Entering Thread 1,2,3,4" and accordingly closing. Order is arbitrary ,but repetition of same string argument is a bug.

$  cd C:\\RobotTest\\testcases ; /usr/bin/env C:\\Users\\pol2hi\\AppData\\Local\\Temp\\rf-ls-run\\run_env_00_rpwvdqgq.bat -u c:\\Program\ Files\\RobotFramework\\robotvscode\\data\\extensions\\robocorp.robotframework-lsp-1.11.0\\src\\robotframework_debug_adapter\\run_robot__main__.py --port 62032 --no-debug -T -d C:\\RobotTest\\testcases\\..\\logfiles -b debug\\hanging_thread.log -l htmllog\\hanging_thread_log.html -o xmloutput\\hanging_thread_output.xml -r htmlreport\\hanging_thread_report.html c:\\RobotTest\\testcases\\hanging_thread.robot 
==============================================================================
Hanging Thread
==============================================================================
Threading Keyword Multiple Time Called                                Entering Thread "thrd1"
Entering Thread "thrd4"
Entering Thread "thrd3"
Entering Thread "thrd3"
Closing Thread "thrd3"
Closing Thread "thrd3"
Closing Thread "thrd3"
Closing Thread "thrd3"
RFStream Warning: keyword - BuiltIn.Sleep did not have a corresponding pop.
RFStream Warning: keyword - .threading_keyword_multiple_time_called.keyword did not have a corresponding pop.
RFStream Warning: keyword - BuiltIn.Sleep did not have a corresponding pop.
RFStream Warning: unable to pop keyword - BuiltIn.Sleep because it does not match the current top: suite - s1
RFStream Warning: unable to pop keyword - BuiltIn.Sleep because it does not match the current top: suite - s1
Threading Keyword Multiple Time Called                                | PASS |
------------------------------------------------------------------------------
Hanging Thread                                                        | PASS |
1 test, 1 passed, 0 failed, 0 unknown
==============================================================================
Debug:   C:\RobotTest\logfiles\debug\hanging_thread-20231110-141935.log
Output:  C:\RobotTest\logfiles\xmloutput\hanging_thread_output-20231110-141935.xml
Log:     C:\RobotTest\logfiles\htmllog\hanging_thread_log-20231110-141935.html
Report:  C:\RobotTest\logfiles\htmlreport\hanging_thread_report-20231110-141935.html

THREAD builtin deactivated results in correct:

$  cd C:\\RobotTest\\testcases ; /usr/bin/env C:\\Users\\pol2hi\\AppData\\Local\\Temp\\rf-ls-run\\run_env_00_gkv5o7lc.bat -u c:\\Program\ Files\\RobotFramework\\robotvscode\\data\\extensions\\robocorp.robotframework-lsp-1.11.0\\src\\robotframework_debug_adapter\\run_robot__main__.py --port 62052 --no-debug -T -d C:\\RobotTest\\testcases\\..\\logfiles -b debug\\hanging_thread.log -l htmllog\\hanging_thread_log.html -o xmloutput\\hanging_thread_output.xml -r htmlreport\\hanging_thread_report.html c:\\RobotTest\\testcases\\hanging_thread.robot 
==============================================================================
Hanging Thread
==============================================================================
Threading Keyword Multiple Time Called                                Entering Thread "thrd1"
Closing Thread "thrd1"
.Entering Thread "thrd2"
Closing Thread "thrd2"
.Entering Thread "thrd3"
Closing Thread "thrd3"
.Entering Thread "thrd4"
Closing Thread "thrd4"
Threading Keyword Multiple Time Called                                | PASS |
------------------------------------------------------------------------------
Hanging Thread                                                        | PASS |
1 test, 1 passed, 0 failed, 0 unknown
==============================================================================
Debug:   C:\RobotTest\logfiles\debug\hanging_thread-20231110-142349.log
Output:  C:\RobotTest\logfiles\xmloutput\hanging_thread_output-20231110-142349.xml
Log:     C:\RobotTest\logfiles\htmllog\hanging_thread_log-20231110-142349.html
Report:  C:\RobotTest\logfiles\htmlreport\hanging_thread_report-20231110-142349.html
test-fullautomation commented 2 months ago

integrated in RobotFramework AIO 0.11.0