summaryrefslogtreecommitdiff
path: root/tests/topotests/lib/lutil.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/topotests/lib/lutil.py')
-rwxr-xr-xtests/topotests/lib/lutil.py34
1 files changed, 20 insertions, 14 deletions
diff --git a/tests/topotests/lib/lutil.py b/tests/topotests/lib/lutil.py
index e58b4725eb..7c89ada013 100755
--- a/tests/topotests/lib/lutil.py
+++ b/tests/topotests/lib/lutil.py
@@ -22,6 +22,7 @@ import sys
import time
import datetime
import json
+import math
from topolog import logger
from mininet.net import Mininet
@@ -242,22 +243,27 @@ Total %-4d %-4d %d\n\
return js
return ret
- def wait(self, target, command, regexp, op, result, wait, returnJson):
- self.log('%s:%s WAIT:%s:%s:%s:%s:%s:%s:' % \
- (self.l_filename, self.l_line, target, command, regexp, op, result,wait))
- llevel = LUtil.l_level
+ def wait(self, target, command, regexp, op, result, wait, returnJson, wait_time=0.5):
+ self.log('%s:%s WAIT:%s:%s:%s:%s:%s:%s:%s:' % \
+ (self.l_filename, self.l_line, target, command, regexp, op, result,wait,wait_time))
found = False
n = 0
startt = time.time()
- delta = time.time() - startt
- while delta < wait and found is False:
+
+ # Calculate the amount of `sleep`s we are going to peform.
+ wait_count = int(math.ceil(wait / wait_time)) + 1
+
+ while wait_count > 0:
+ n += 1
found = self.command(target, command, regexp, op, result, returnJson)
- n+=1
- LUtil.l_level = 0
- delta = time.time() - startt
- if delta < wait and found is False:
- time.sleep (0.5)
- LUtil.l_level = llevel
+ if found is not False:
+ break
+
+ wait_count -= 1
+ if wait_count > 0:
+ time.sleep(wait_time)
+
+ delta = time.time() - startt
self.log('Done after %d loops, time=%s, Found=%s' % (n, delta, found))
found = self.command(target, command, regexp, 'pass', '%s +%4.2f secs' % (result, delta), returnJson)
return found
@@ -283,11 +289,11 @@ def luStart(baseScriptDir='.', baseLogDir='.', net='',
LUtil.l_dotall_experiment = False
LUtil.l_dotall_experiment = True
-def luCommand(target, command, regexp='.', op='none', result='', time=10, returnJson=False):
+def luCommand(target, command, regexp='.', op='none', result='', time=10, returnJson=False, wait_time=0.5):
if op != 'wait':
return LUtil.command(target, command, regexp, op, result, returnJson)
else:
- return LUtil.wait(target, command, regexp, op, result, time, returnJson)
+ return LUtil.wait(target, command, regexp, op, result, time, returnJson, wait_time)
def luLast(usenl=False):
if usenl: