Fixed logic error occuring at certain values 07/45307/14
authorlbuckuli <lbuckuli@cisco.com>
Tue, 20 Sep 2016 13:09:01 +0000 (13:09 +0000)
committerVratko Polák <vrpolak@cisco.com>
Fri, 23 Sep 2016 07:56:16 +0000 (07:56 +0000)
When the "Wait For Getter Error Or Safe Stateful Validator
Consecutive Success" keyword receives certain arguments, it
will crash with a "Logic error" because the calculated repeat
count will be less than 1 or even 2.

WaitUtilsTest.robot: a new test case Timeout_Hits_Off_By_One_Bug added.

In WaitUtils.robot for keywords:
Wait_For_Getter_And_Safe_Stateful_Validator_Consecutive_Success,

Wait_For_Getter_Error_Or_Safe_Stateful_Validator_Consecutive_Success
changed:
: FOR    ${try}    IN RANGE    1    ${maximum_tries}+1    # If maximum_tries is 3, for will go through 1, 2, and 3.
to
: FOR    ${try}    IN RANGE    1    ${maximum_sleeps}+2    # If maximum_sleeps is 2, for will go through 1, 2, and 3.

Change-Id: Ie924cbd22dad01abf0e3ab9d06c2843abfcfda86
Signed-off-by: Jozef Behran <jbehran@cisco.com>
Signed-off-by: lbuckuli <lbuckuli@cisco.com>
csit/libraries/WaitUtils.robot
csit/suites/test/libraries/WaitUtilsTest.robot

index 09c96033e1132978743651ea6d8a818f7ac814a7..3ed1e7d7d103a4cd75858619e35f1e623a6ba6ce 100644 (file)
@@ -193,12 +193,12 @@ Wait_For_Getter_And_Safe_Stateful_Validator_Consecutive_Success
     [Documentation]    Analogue of Wait Until Keyword Succeeds, but it passes state of validator around. Calls GASSVHTSCBD to verify data is "stable".
     # FIXME: Document that Safe Stateful Validator has to return state, status and message (and never fail)
     ${timeout_in_seconds}    ${period_in_seconds}    ${date_deadline} =    WaitUtils__Check_Sanity_And_Compute_Derived_Times    timeout=${timeout}    period=${period}    count=${count}
-    # Maximum number of tries. TODO: Move to separate Keyword?
-    ${maximum_tries} =    BuiltIn.Evaluate    math.ceil(${timeout_in_seconds} / ${period_in_seconds}) + 1    modules=math
+    # Maximum number of sleeps. TODO: Move to separate Keyword?
+    ${maximum_sleeps} =    BuiltIn.Evaluate    math.ceil(${timeout_in_seconds} / ${period_in_seconds}) + 1    modules=math
     ${result} =    BuiltIn.Set_Variable    No result yet.
     ${state} =    BuiltIn.Set_Variable    ${initial_state}
     # The loop for failures.
-    : FOR    ${try}    IN RANGE    1    ${maximum_tries}+1    # If maximum_tries is 3, for will go through 1, 2, and 3.
+    : FOR    ${try}    IN RANGE    1    ${maximum_sleeps}+2    # If maximum_sleeps is 2, for will go through 1, 2, and 3.
     \    ${state}    ${status}    ${result} =    Getter_And_Safe_Stateful_Validator_Have_To_Succeed_Consecutively_By_Deadline    date_deadline=${date_deadline}    period_in_seconds=${period_in_seconds}
     \    ...    count=${count}    getter=${getter}    safe_validator=${safe_validator}    initial_state=${state}
     \    # Have we passed?
@@ -216,12 +216,12 @@ Wait_For_Getter_Error_Or_Safe_Stateful_Validator_Consecutive_Success
     ${tmp}=    BuiltIn.Evaluate    int(${count})
     BuiltIn.Log    count=${tmp}
     ${timeout_in_seconds}    ${period_in_seconds}    ${date_deadline} =    WaitUtils__Check_Sanity_And_Compute_Derived_Times    timeout=${timeout}    period=${period}    count=${count}
-    # Maximum number of tries. TODO: Move to separate Keyword or add into CSACDT?
-    ${maximum_tries} =    BuiltIn.Evaluate    math.ceil(${timeout_in_seconds} / ${period_in_seconds})    modules=math
+    # Maximum number of sleeps. TODO: Move to separate Keyword or add into CSACDT?
+    ${maximum_sleeps} =    BuiltIn.Evaluate    math.ceil(${timeout_in_seconds} / ${period_in_seconds})    modules=math
     ${result} =    BuiltIn.Set_Variable    No result yet.
     ${state} =    BuiltIn.Set_Variable    ${initial_state}
     # The loop for failures.
-    : FOR    ${try}    IN RANGE    1    ${maximum_tries}+1    # If maximum_tries is 3, for will go through 1, 2, and 3.
+    : FOR    ${try}    IN RANGE    1    ${maximum_sleeps}+2    # If maximum_sleeps is 2, for will go through 1, 2, and 3.
     \    ${state}    ${status}    ${result} =    Getter_And_Safe_Stateful_Validator_Have_To_Succeed_Consecutively_By_Deadline    date_deadline=${date_deadline}    period_in_seconds=${period_in_seconds}
     \    ...    count=${count}    getter=${getter}    safe_validator=${safe_validator}    initial_state=${state}
     \    # Have we passed?
index 6763ad8aa16c017ae2d1eabb30e0ecca2f6130b6..bf0bc4184b0db5660693a9b79e908268178f4a8e 100644 (file)
@@ -164,6 +164,12 @@ WFGEOSSVCS_Early_exit
     BuiltIn.Should_Be_Equal    ${status}    FAIL
     BuiltIn.Should_Be_Equal    ${message}    Getter failed: Got negative -1
 
+WFGEOSSVCS_Sleeps_Too_Long
+    [Documentation]    Use getter, standard validator, timeout with a reserve and checks that the expected error=timeout occurred.
+    ${getter} =    Create_Scenario_Getter_Closure    ${stability_scenario}    delay=0s    fail_on_negative=False
+    BuiltIn.Run_Keyword_And_Expect_Error    Not possible to succeed within the deadline. Last result: No result yet.    Wait_For_Getter_Error_Or_Safe_Stateful_Validator_Consecutive_Success    timeout=9.15s    period=2s    count=1    getter=${getter}
+    ...    safe_validator=${standard_validator}
+
 *** Keywords ***
 WUT_Setup
     [Documentation]    Call Setup keywords of libraries, define reusable variables.