|
@@ -166,7 +166,7 @@ class RunningProcess:
|
|
|
os.remove(self.stderr_filename)
|
|
|
os.remove(self.stdout_filename)
|
|
|
|
|
|
- def _wait_for_output_str(self, filename, running_file, strings, only_new):
|
|
|
+ def _wait_for_output_str(self, filename, running_file, strings, only_new, matches = 1):
|
|
|
"""
|
|
|
Wait for a line of output in this process. This will (if only_new is
|
|
|
False) first check all previous output from the process, and if not
|
|
@@ -180,18 +180,22 @@ class RunningProcess:
|
|
|
strings: Array of strings to look for.
|
|
|
only_new: If true, only check output since last time this method was
|
|
|
called. If false, first check earlier output.
|
|
|
+ matches: Check for the string this many times.
|
|
|
Returns a tuple containing the matched string, and the complete line
|
|
|
it was found in.
|
|
|
Fails if none of the strings was read after 10 seconds
|
|
|
(OUTPUT_WAIT_INTERVAL * OUTPUT_WAIT_MAX_INTERVALS).
|
|
|
"""
|
|
|
+ match_count = 0
|
|
|
if not only_new:
|
|
|
full_file = open(filename, "r")
|
|
|
for line in full_file:
|
|
|
for string in strings:
|
|
|
if line.find(string) != -1:
|
|
|
- full_file.close()
|
|
|
- return (string, line)
|
|
|
+ match_count += 1
|
|
|
+ if match_count >= matches:
|
|
|
+ full_file.close()
|
|
|
+ return (string, line)
|
|
|
wait_count = 0
|
|
|
while wait_count < OUTPUT_WAIT_MAX_INTERVALS:
|
|
|
where = running_file.tell()
|
|
@@ -199,42 +203,46 @@ class RunningProcess:
|
|
|
if line:
|
|
|
for string in strings:
|
|
|
if line.find(string) != -1:
|
|
|
- return (string, line)
|
|
|
+ match_count += 1
|
|
|
+ if match_count >= matches:
|
|
|
+ return (string, line)
|
|
|
else:
|
|
|
wait_count += 1
|
|
|
time.sleep(OUTPUT_WAIT_INTERVAL)
|
|
|
running_file.seek(where)
|
|
|
assert False, "Timeout waiting for process output: " + str(strings)
|
|
|
|
|
|
- def wait_for_stderr_str(self, strings, only_new = True):
|
|
|
+ def wait_for_stderr_str(self, strings, only_new = True, matches = 1):
|
|
|
"""
|
|
|
Wait for one of the given strings in this process's stderr output.
|
|
|
Parameters:
|
|
|
strings: Array of strings to look for.
|
|
|
only_new: If true, only check output since last time this method was
|
|
|
called. If false, first check earlier output.
|
|
|
+ matches: Check for the string this many times.
|
|
|
Returns a tuple containing the matched string, and the complete line
|
|
|
it was found in.
|
|
|
Fails if none of the strings was read after 10 seconds
|
|
|
(OUTPUT_WAIT_INTERVAL * OUTPUT_WAIT_MAX_INTERVALS).
|
|
|
"""
|
|
|
return self._wait_for_output_str(self.stderr_filename, self.stderr,
|
|
|
- strings, only_new)
|
|
|
+ strings, only_new, matches)
|
|
|
|
|
|
- def wait_for_stdout_str(self, strings, only_new = True):
|
|
|
+ def wait_for_stdout_str(self, strings, only_new = True, matches = 1):
|
|
|
"""
|
|
|
Wait for one of the given strings in this process's stdout output.
|
|
|
Parameters:
|
|
|
strings: Array of strings to look for.
|
|
|
only_new: If true, only check output since last time this method was
|
|
|
called. If false, first check earlier output.
|
|
|
+ matches: Check for the string this many times.
|
|
|
Returns a tuple containing the matched string, and the complete line
|
|
|
it was found in.
|
|
|
Fails if none of the strings was read after 10 seconds
|
|
|
(OUTPUT_WAIT_INTERVAL * OUTPUT_WAIT_MAX_INTERVALS).
|
|
|
"""
|
|
|
return self._wait_for_output_str(self.stdout_filename, self.stdout,
|
|
|
- strings, only_new)
|
|
|
+ strings, only_new, matches)
|
|
|
|
|
|
# Container class for a number of running processes
|
|
|
# i.e. servers like bind10, etc
|
|
@@ -300,7 +308,7 @@ class RunningProcesses:
|
|
|
for process in self.processes.values():
|
|
|
process.remove_files_on_exit = False
|
|
|
|
|
|
- def wait_for_stderr_str(self, process_name, strings, only_new = True):
|
|
|
+ def wait_for_stderr_str(self, process_name, strings, only_new = True, matches = 1):
|
|
|
"""
|
|
|
Wait for one of the given strings in the given process's stderr output.
|
|
|
Parameters:
|
|
@@ -308,6 +316,7 @@ class RunningProcesses:
|
|
|
strings: Array of strings to look for.
|
|
|
only_new: If true, only check output since last time this method was
|
|
|
called. If false, first check earlier output.
|
|
|
+ matches: Check for the string this many times.
|
|
|
Returns the matched string.
|
|
|
Fails if none of the strings was read after 10 seconds
|
|
|
(OUTPUT_WAIT_INTERVAL * OUTPUT_WAIT_MAX_INTERVALS).
|
|
@@ -316,9 +325,10 @@ class RunningProcesses:
|
|
|
assert process_name in self.processes,\
|
|
|
"Process " + process_name + " unknown"
|
|
|
return self.processes[process_name].wait_for_stderr_str(strings,
|
|
|
- only_new)
|
|
|
+ only_new,
|
|
|
+ matches)
|
|
|
|
|
|
- def wait_for_stdout_str(self, process_name, strings, only_new = True):
|
|
|
+ def wait_for_stdout_str(self, process_name, strings, only_new = True, matches = 1):
|
|
|
"""
|
|
|
Wait for one of the given strings in the given process's stdout output.
|
|
|
Parameters:
|
|
@@ -326,6 +336,7 @@ class RunningProcesses:
|
|
|
strings: Array of strings to look for.
|
|
|
only_new: If true, only check output since last time this method was
|
|
|
called. If false, first check earlier output.
|
|
|
+ matches: Check for the string this many times.
|
|
|
Returns the matched string.
|
|
|
Fails if none of the strings was read after 10 seconds
|
|
|
(OUTPUT_WAIT_INTERVAL * OUTPUT_WAIT_MAX_INTERVALS).
|
|
@@ -334,7 +345,8 @@ class RunningProcesses:
|
|
|
assert process_name in self.processes,\
|
|
|
"Process " + process_name + " unknown"
|
|
|
return self.processes[process_name].wait_for_stdout_str(strings,
|
|
|
- only_new)
|
|
|
+ only_new,
|
|
|
+ matches)
|
|
|
|
|
|
@before.each_scenario
|
|
|
def initialize(scenario):
|