Bug 970143 - [RFE] rlWaitUntilReady - sync between test and SUT
Summary: [RFE] rlWaitUntilReady - sync between test and SUT
Keywords:
Status: CLOSED DUPLICATE of bug 1032123
Alias: None
Product: Fedora
Classification: Fedora
Component: beakerlib
Version: rawhide
Hardware: Unspecified
OS: Unspecified
medium
medium
Target Milestone: ---
Assignee: Hubert Kario
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard: Project: Easy
: 879260 (view as bug list)
Depends On:
Blocks: 1032123
TreeView+ depends on / blocked
 
Reported: 2013-06-03 14:27 UTC by Ales Zelinka
Modified: 2013-11-21 10:03 UTC (History)
6 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2013-11-21 10:03:07 UTC
Type: Bug
Embargoed:


Attachments (Terms of Use)

Description Ales Zelinka 2013-06-03 14:27:03 UTC
I often need to make sure that a specific assert is only checked when the system under test is ready to be tested. Typically test has to be run after setup is finished. E.g. a service needs some time for initiation, doing

rlServiceStart service
rlRun "check service"

fails because the service needs some "warm up" time. Quick and dirty "solution" is to run sleep before the test but that's unreliable - you either don't wait long enough and run the check too soon or wait for too long and waste time. 

I propose a synchronization function that would block until the test and SUT are in sync.

I believe test-SUT synchronization is an use-case common enough to warrant a beakerlib function.

This is what I currently use for samba testing:

sb_tries(){
    local COMMAND=$1
    local COUNT=${2:-10}
    local PAUSE=${3:-10}
    local RESULT=${4:-0}
    local DESCRIPTION=${5:-$COMMAND}
    local ECODE=0
    while [ "$COUNT" -gt 0 ] ; do
        echo "tries: COUNT=$COUNT PAUSE=$PAUSE RESULT=$RESULT COMMAND=$DESCRIPTION"
        eval $COMMAND
        ECODE=$?
        [ $ECODE -eq "$RESULT" ] && return 0
        echo "ecode: $ECODE"
        sleep "$PAUSE"
        COUNT=$(( $COUNT -1 ))
    done
    return $ECODE
}

Example usage:
rlServiceStart smb
#run the command repeatedly with 10 second pause in between runs unless it returns 0 or 10 iterations 
sb_tries "smbclient -N -L 127.0.0.1"
rlRun "the real test"

Comment 1 Petr Muller 2013-06-07 11:06:46 UTC
*** Bug 879260 has been marked as a duplicate of this bug. ***

Comment 2 Hubert Kario 2013-11-18 19:18:43 UTC
I'm working on a generic set of routines for process synchronisation, and I'm wondering if just waiting for network or UNIX sockets wouldn't be enough?

Other than that, I think a timeout-based approach would be better. Because if the test command blocks, we can still continue with the test execution. This way the cleanup phase has a chance to run.

Comment 3 Ales Zelinka 2013-11-19 10:15:45 UTC
(In reply to Hubert Kario from comment #2)
> I'm working on a generic set of routines for process synchronisation, and
> I'm wondering if just waiting for network or UNIX sockets wouldn't be enough?

AFAIK doesn't work for my use-case from comment#0

> 
> Other than that, I think a timeout-based approach would be better. Because
> if the test command blocks, we can still continue with the test execution.
> This way the cleanup phase has a chance to run.

additional timeout parameter can be added, or, better, you should be able to wrap the rlWaitUntilReady in rlWatchdog.

Comment 4 Hubert Kario 2013-11-20 19:21:54 UTC
I've created a new routine, rlWaitForCmd, details on mailing list:
https://lists.fedorahosted.org/pipermail/beakerlib-devel/2013-November/000043.html

Usage:

  rlWaitForCmd command [-p PID] [-t time] [-m count] [-d delay] [-r retval]

=item command

Command that will be executed until its return code is equal 0 or value
speciefied as option to `-r'.

=item -t time

Timeout in seconds, default=120. If the command doesn't return 0
before time elapses, the command will be killed.

=item -p PID

PID of the process to check before running command. If the process
exits before the socket is opened, the command will log a WARNING.

=item -m count

Maximum number of `command' executions before continuing anyway. Default is
infite.

=item -d delay

Delay between `command' invocations. Default 1.

=item -r retval

Expected return value of command. Default 0.

Comment 5 Ales Zelinka 2013-11-21 10:03:07 UTC

*** This bug has been marked as a duplicate of bug 1032123 ***


Note You need to log in before you can comment on or make changes to this bug.