diff options
author | Daniel Gottlieb <daniel.gottlieb@mongodb.com> | 2020-07-23 16:18:00 -0400 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-07-23 23:28:54 +0000 |
commit | 19dd40b181c0043cf8989cc216195c5b01472c35 (patch) | |
tree | 5048e0bd6b35c12c85073d6e7a9b642dec08a01b /buildscripts/tests | |
parent | 20a929019d14e7fab4f9c6f5acf01e2544f37a7a (diff) | |
download | mongo-19dd40b181c0043cf8989cc216195c5b01472c35.tar.gz |
SERVER-48951: Add usability options for resmoke output.
--mrlog will pipe all stdout through mrlog.
--userFriendlyOutput=<file> will `tee` all output to <file>. It will filter
stdout with a grep to highlight test progress and possible failures.
Diffstat (limited to 'buildscripts/tests')
-rw-r--r-- | buildscripts/tests/resmokelib/core/test_redirect.py | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/buildscripts/tests/resmokelib/core/test_redirect.py b/buildscripts/tests/resmokelib/core/test_redirect.py new file mode 100644 index 00000000000..44a1b83d10e --- /dev/null +++ b/buildscripts/tests/resmokelib/core/test_redirect.py @@ -0,0 +1,58 @@ +"""Unit tests for buildscripts/resmokelib/core/redirect.py.""" + +from __future__ import absolute_import + +import io +import os +import subprocess +import tempfile +import unittest + +from buildscripts.resmokelib.core import redirect as _redirect + +# pylint: disable=missing-docstring + + +class TestStdoutRedirect(unittest.TestCase): + is_windows = os.name == "nt" + + def test_process_pipes(self): + """Write a string, one word per line into the beginning of a chain of processes. The input + will be tee'd into a temporary file and grepped. Verify the contents of the tee'd file and + the final output of the grep. + """ + + if self.is_windows: + return + + haystack = "can you find a needle in a haystack".split() + tmp_file = tempfile.mktemp() + + try: + tee = _redirect.Pipe(["tee", tmp_file], subprocess.PIPE, subprocess.PIPE) + grep = _redirect.Pipe(["grep", "needle"], tee.get_stdout(), subprocess.PIPE) + + for word in haystack: + # Write the message with a newline after each word. Grep should only match "needle". + tee.proc.stdin.write((word + "\n").encode("utf-8")) + + tee.get_stdin().close() + self.assertEqual(b"needle", grep.get_stdout().read().strip()) + + with open(tmp_file) as teed_file: + self.assertEqual("\n".join(haystack) + "\n", teed_file.read()) + finally: + tee.wait() + grep.wait() + tee.get_stdout().close() + grep.get_stdout().close() + os.remove(tmp_file) + + def test_stdout_rewrite(self): + string = "mary had a little lamb" + acc = io.BytesIO() + with _redirect.StdoutRewrite(acc): + print(string) + + print("not to be captured") + self.assertEqual(string + "\n", acc.getvalue().decode("utf-8")) |