Migrate GoBgpLib.robot
[integration/test.git] / csit / libraries / WaitForFailure.robot
1 *** Settings ***
2 Documentation       Robot keyword Resource for catching a later failure in temporarily passing repeated check.
3 ...
4 ...                 Copyright (c) 2015-2017 Cisco Systems, Inc. and others. All rights reserved.
5 ...
6 ...                 This program and the accompanying materials are made available under the
7 ...                 terms of the Eclipse Public License v1.0 which accompanies this distribution,
8 ...                 and is available at http://www.eclipse.org/legal/epl-v10.html
9 ...
10 ...
11 ...                 Terminology:
12 ...                 "cell_sequence" is a sequence of Robot cells, usually executable.
13 ...                 "keyword_name" is a first cell in that sequence, entry point of execution,
14 ...                 the item defined in Keywords table (or in a Library or Resource)
15 ...                 which may take arguments (the rest of cell sequence).
16 ...                 Note that this may not work correctly with named arguments, due to ordering,
17 ...                 so positional cells are strongly suggested to be positional arguments.
18 ...                 "Keyword" or "keyword" may refer to keyword_name or executable cell sequence,
19 ...                 or both, depending on context.
20
21
22 *** Keywords ***
23 Log_Failable_Keyword
24     [Documentation]    Execute failable Keyword. Log the resulting value when it does not fail.
25     ...    Deprecated, was used in previous implementation of higher-level keywords.
26     [Arguments]    @{cell_sequence}
27     ${result} =    BuiltIn.Run_Keyword    @{cell_sequence}
28     BuiltIn.Log    ${result}
29     RETURN    ${result}
30
31 Keyword_Should_Fail_In_Any_Way
32     [Documentation]    Try to run the Keyword and Log the result. Pass and return the error on any failure, Fail otherwise.
33     ...    Deprecated, was used in previous implementation of higher-level keywords.
34     [Arguments]    @{cell_sequence}
35     ${error} =    BuiltIn.Run_Keyword_And_Expect_Error    *    Log_Failable_Keyword    @{cell_sequence}
36     RETURN    ${error}
37
38     # '*' means we really catch all types of errors.
39
40 Invert_Failure
41     [Documentation]    The response of Keyword execution is either a return value or a failure message.
42     ...    This keyword calls the argument keyword and returns its failure message string,
43     ...    or fails with its return value converted to string.
44     [Arguments]    @{cell_sequence}
45     ${status}    ${output} =    BuiltIn.Run_Keyword_And_Ignore_Error    @{cell_sequence}
46     IF    "${status}" != "PASS"    RETURN    ${output}
47     ${output} =    BuiltIn.Convert_To_String    ${output}
48     BuiltIn.Fail    ${output}
49
50 Confirm_Keyword_Fails_Within_Timeout
51     [Documentation]    Some Keywords need several tries to finally fail, this keyword passes if and only if the failure ultimately happens.
52     [Arguments]    ${timeout}    ${refresh}    @{cell_list}
53     # Arguments with default values interact badly with varargs, so using WUKS argument style.
54     BuiltIn.Run_Keyword_And_Return
55     ...    BuiltIn.Wait_Until_Keyword_Succeeds
56     ...    ${timeout}
57     ...    ${refresh}
58     ...    Invert_Failure
59     ...    @{cell_list}
60
61 Verify_Keyword_Never_Passes_Within_Timeout
62     [Documentation]    Some negative checks report false failure for a short time. This keyword verifies no pass does happen within timeout period.
63     [Arguments]    ${timeout}    ${refresh}    @{cell_list}
64     BuiltIn.Run_Keyword_And_Return
65     ...    Invert_Failure
66     ...    BuiltIn.Wait_Until_Keyword_Succeeds
67     ...    ${timeout}
68     ...    ${refresh}
69     ...    @{cell_list}
70
71 Verify_Keyword_Does_Not_Fail_Within_Timeout
72     [Documentation]    Some positive checks report false success for a short time. This keyword verifies no failure does happen within timeout period.
73     ...    This implementation needs more complicated logic than, Verify_Keyword_Never_Passes_Within_Timeout,
74     ...    so use that keyword in case you have a negative check handy.
75     [Arguments]    ${timeout}    ${refresh}    @{cell_list}
76     BuiltIn.Run_Keyword_And_Return
77     ...    Invert_Failure
78     ...    Confirm_Keyword_Fails_Within_Timeout
79     ...    ${timeout}
80     ...    ${refresh}
81     ...    @{cell_list}
82     # TODO: Remove the added comment text of time running out to restore last Keyword return value.