Parcourir la source

[1292] extend 'wait for' step with string we do NOT want

and make it possible to print the entire line of output if we see it
Jelte Jansen il y a 13 ans
Parent
commit
90a1746c2d

+ 4 - 4
tests/lettuce/features/terrain/bind10_control.py

@@ -61,10 +61,10 @@ def start_bind10(step, config_file, cmdctl_port, msgq_sockfile, process_name):
     world.processes.add_process(step, process_name, args)
     world.processes.add_process(step, process_name, args)
 
 
     # check output to know when startup has been completed
     # check output to know when startup has been completed
-    message = world.processes.wait_for_stderr_str(process_name,
-                                                  ["BIND10_STARTUP_COMPLETE",
-                                                   "BIND10_STARTUP_ERROR"])
-    assert message == "BIND10_STARTUP_COMPLETE", "Got: " + str(message)
+    (message, line) = world.processes.wait_for_stderr_str(process_name,
+                                                     ["BIND10_STARTUP_COMPLETE",
+                                                      "BIND10_STARTUP_ERROR"])
+    assert message == "BIND10_STARTUP_COMPLETE", "Got: " + str(line)
 
 
 @step('wait for bind10 auth (?:of (\w+) )?to start')
 @step('wait for bind10 auth (?:of (\w+) )?to start')
 def wait_for_auth(step, process_name):
 def wait_for_auth(step, process_name):

+ 19 - 7
tests/lettuce/features/terrain/steps.py

@@ -30,8 +30,8 @@ def stop_a_named_process(step, process_name):
     """
     """
     world.processes.stop_process(process_name)
     world.processes.stop_process(process_name)
 
 
-@step('wait for (new )?(\w+) stderr message (\w+)')
-def wait_for_message(step, new, process_name, message):
+@step('wait for (new )?(\w+) stderr message (\w+)(?: not (\w+))?')
+def wait_for_message(step, new, process_name, message, not_message):
     """
     """
     Block until the given message is printed to the given process's stderr
     Block until the given message is printed to the given process's stderr
     output.
     output.
@@ -40,12 +40,18 @@ def wait_for_message(step, new, process_name, message):
                              this step was used for this process.
                              this step was used for this process.
     process_name ('<name> stderr'): Name of the process to check the output of.
     process_name ('<name> stderr'): Name of the process to check the output of.
     message ('message <message>'): Output (part) to wait for.
     message ('message <message>'): Output (part) to wait for.
+    not_message ('not <message>'): Output (part) to wait for, and fail
     Fails if the message is not found after 10 seconds.
     Fails if the message is not found after 10 seconds.
     """
     """
-    world.processes.wait_for_stderr_str(process_name, [message], new)
+    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 not_message is not None:
+        assert found != not_message, line
 
 
-@step('wait for (new )?(\w+) stdout message (\w+)')
-def wait_for_message(step, process_name, message):
+@step('wait for (new )?(\w+) stdout message (\w+)(?: not (\w+))?')
+def wait_for_message(step, process_name, message, not_message):
     """
     """
     Block until the given message is printed to the given process's stdout
     Block until the given message is printed to the given process's stdout
     output.
     output.
@@ -53,10 +59,16 @@ def wait_for_message(step, process_name, message):
     new: (' new', optional): Only check the output printed since last time
     new: (' new', optional): Only check the output printed since last time
                              this step was used for this process.
                              this step was used for this process.
     process_name ('<name> stderr'): Name of the process to check the output of.
     process_name ('<name> stderr'): Name of the process to check the output of.
-    message ('message <message>'): Output (part) to wait for.
+    message ('message <message>'): Output (part) to wait for, and succeed.
+    not_message ('not <message>'): Output (part) to wait for, and fail
     Fails if the message is not found after 10 seconds.
     Fails if the message is not found after 10 seconds.
     """
     """
-    world.processes.wait_for_stdout_str(process_name, [message], new)
+    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 not_message is not None:
+        assert found != not_message, line
 
 
 @step('the file (\S+) should (not )?exist')
 @step('the file (\S+) should (not )?exist')
 def check_existence(step, file_name, should_not_exist):
 def check_existence(step, file_name, should_not_exist):

+ 8 - 5
tests/lettuce/features/terrain/terrain.py

@@ -173,7 +173,8 @@ class RunningProcess:
         strings: Array of strings to look for.
         strings: Array of strings to look for.
         only_new: If true, only check output since last time this method was
         only_new: If true, only check output since last time this method was
                   called. If false, first check earlier output.
                   called. If false, first check earlier output.
-        Returns the matched string.
+        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
         Fails if none of the strings was read after 10 seconds
         (OUTPUT_WAIT_INTERVAL * OUTPUT_WAIT_MAX_INTERVALS).
         (OUTPUT_WAIT_INTERVAL * OUTPUT_WAIT_MAX_INTERVALS).
         """
         """
@@ -183,7 +184,7 @@ class RunningProcess:
                 for string in strings:
                 for string in strings:
                     if line.find(string) != -1:
                     if line.find(string) != -1:
                         full_file.close()
                         full_file.close()
-                        return string
+                        return (string, line)
         wait_count = 0
         wait_count = 0
         while wait_count < OUTPUT_WAIT_MAX_INTERVALS:
         while wait_count < OUTPUT_WAIT_MAX_INTERVALS:
             where = running_file.tell()
             where = running_file.tell()
@@ -191,7 +192,7 @@ class RunningProcess:
             if line:
             if line:
                 for string in strings:
                 for string in strings:
                     if line.find(string) != -1:
                     if line.find(string) != -1:
-                        return string
+                        return (string, line)
             else:
             else:
                 wait_count += 1
                 wait_count += 1
                 time.sleep(OUTPUT_WAIT_INTERVAL)
                 time.sleep(OUTPUT_WAIT_INTERVAL)
@@ -205,7 +206,8 @@ class RunningProcess:
         strings: Array of strings to look for.
         strings: Array of strings to look for.
         only_new: If true, only check output since last time this method was
         only_new: If true, only check output since last time this method was
                   called. If false, first check earlier output.
                   called. If false, first check earlier output.
-        Returns the matched string.
+        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
         Fails if none of the strings was read after 10 seconds
         (OUTPUT_WAIT_INTERVAL * OUTPUT_WAIT_MAX_INTERVALS).
         (OUTPUT_WAIT_INTERVAL * OUTPUT_WAIT_MAX_INTERVALS).
         """
         """
@@ -219,7 +221,8 @@ class RunningProcess:
         strings: Array of strings to look for.
         strings: Array of strings to look for.
         only_new: If true, only check output since last time this method was
         only_new: If true, only check output since last time this method was
                   called. If false, first check earlier output.
                   called. If false, first check earlier output.
-        Returns the matched string.
+        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
         Fails if none of the strings was read after 10 seconds
         (OUTPUT_WAIT_INTERVAL * OUTPUT_WAIT_MAX_INTERVALS).
         (OUTPUT_WAIT_INTERVAL * OUTPUT_WAIT_MAX_INTERVALS).
         """
         """

+ 1 - 1
tests/lettuce/features/xfrin_bind10.feature

@@ -6,5 +6,5 @@ Feature: Xfrin
     And I have bind10 running with configuration xfrin/retransfer_slave.conf
     And I have bind10 running with configuration xfrin/retransfer_slave.conf
     A query for www.example.org should have rcode REFUSED
     A query for www.example.org should have rcode REFUSED
     When I send bind10 the command Xfrin retransfer example.org IN 127.0.0.1 47807
     When I send bind10 the command Xfrin retransfer example.org IN 127.0.0.1 47807
-    Then wait for new bind10 stderr message XFRIN_XFR_TRANSFER_SUCCESS
+    Then wait for new bind10 stderr message XFRIN_XFR_TRANSFER_SUCCESS not XFRIN_XFR_PROCESS_FAILURE
     A query for www.example.org should have rcode NOERROR
     A query for www.example.org should have rcode NOERROR