Bugzilla (bugzilla.redhat.com) will be under maintenance for infrastructure upgrades and will not be unavailable on July 31st between 12:30 AM - 05:30 AM UTC. We appreciate your understanding and patience. You can follow status.redhat.com for details.
Bug 879260 - RFE: add function to to wait till a port is opened
Summary: RFE: add function to to wait till a port is opened
Keywords:
Status: CLOSED DUPLICATE of bug 970143
Alias: None
Product: Fedora
Classification: Fedora
Component: beakerlib
Version: rawhide
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: ---
Assignee: Petr Muller
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2012-11-22 13:26 UTC by Jan Vcelak
Modified: 2016-09-20 02:09 UTC (History)
6 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2013-06-07 11:06:46 UTC
Type: Bug


Attachments (Terms of Use)

Description Jan Vcelak 2012-11-22 13:26:39 UTC
Description of problem:

Beakerlib should provide some function to repeat a given command periodically till executed successfully or till some timeout expires.

For example: we run OpenLDAP server via valgrind on the background and need to wait till the initialization is finished (tcp/389 port is available).

"sleep" is a dummy solution, because it slows down the test on fast machines and can cause the test to fail on slow machines.

Here is a simple proposal, how it could work:

function rlTryRepeat()
{
  command=$1
  retries=${2:-30}

  for (( retry=0; retry < $retries; retry++ )); do
    $command && return 0 || sleep 1
  done
  return 1
}

function rlWaitTcpPort()
{
  port=$1
  host=${2:-localhost}
  retries=$3

  rlTryRepeat "nc -z $host $port" $retries
}

Usage:

rlRun "valgrind ... slapd ... &"
rlWaitTcpPort 389
rlRun "ldapsearch ..."

Version-Release number of selected component (if applicable):


How reproducible:


Steps to Reproduce:
1.
2.
3.
  
Actual results:


Expected results:


Additional info:

Comment 2 Petr Muller 2013-06-07 11:06:46 UTC

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


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