"""
world.processes.stop_process(process_name)
-@step('wait for (new )?(\w+) stderr message (\w+)(?: not (\w+))?')
-def wait_for_stderr_message(step, new, process_name, message, not_message):
+@step('wait (?:(\d+) times )?for (new )?(\w+) stderr message (\w+)(?: not (\w+))?')
+def wait_for_stderr_message(step, times, new, process_name, message, not_message):
"""
Block until the given message is printed to the given process's stderr
output.
Parameter:
+ times: Check for the string this many times.
new: (' new', optional): Only check the output printed since last time
this step was used for this process.
process_name ('<name> stderr'): Name of the process to check the output of.
strings = [message]
if not_message is not None:
strings.append(not_message)
- (found, line) = world.processes.wait_for_stderr_str(process_name, strings, new)
+ if times is None:
+ times = 1
+ (found, line) = world.processes.wait_for_stderr_str(process_name, strings, new, int(times))
if not_message is not None:
assert found != not_message, line
-@step('wait for (new )?(\w+) stdout message (\w+)(?: not (\w+))?')
-def wait_for_stdout_message(step, new, process_name, message, not_message):
+@step('wait (?:(\d+) times )?for (new )?(\w+) stdout message (\w+)(?: not (\w+))?')
+def wait_for_stdout_message(step, times, new, process_name, message, not_message):
"""
Block until the given message is printed to the given process's stdout
output.
Parameter:
+ times: Check for the string this many times.
new: (' new', optional): Only check the output printed since last time
this step was used for this process.
process_name ('<name> stderr'): Name of the process to check the output of.
strings = [message]
if not_message is not None:
strings.append(not_message)
- (found, line) = world.processes.wait_for_stdout_str(process_name, strings, new)
+ if times is None:
+ times = 1
+ (found, line) = world.processes.wait_for_stdout_str(process_name, strings, new, int(times))
if not_message is not None:
assert found != not_message, line
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
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()
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
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:
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).
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:
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).
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):