Commit 9f413221 authored by Kirill Smelkov's avatar Kirill Smelkov

Emit run summary at the end

Sometimes there is zero testcases to be executed on testnodes, and
log output from nxdtest is just

    date:   Wed, 10 Nov 2021 12:31:50 MSK
    xnode:  kirr@deca.navytux.spb.ru
    uname:  Linux deca 5.10.0-9-amd64 #1 SMP Debian 5.10.70-1 (2021-09-30) x86_64
    cpu:    Intel(R) Core(TM) i7-7600U CPU @ 2.80GHz

it is not clear from such output did the run ended or the test got
stuck. After this patch it becomes

    date:   Wed, 10 Nov 2021 12:31:50 MSK
    xnode:  kirr@deca.navytux.spb.ru
    uname:  Linux deca 5.10.0-9-amd64 #1 SMP Debian 5.10.70-1 (2021-09-30) x86_64
    cpu:    Intel(R) Core(TM) i7-7600U CPU @ 2.80GHz
    # ran 0 test cases.

And in general, when there are several testcases to be run, it is helpful to
indicate end of such run and to print brief summary of result status for all
ran test cases. Example output:

    wendelin.core$ nxdtest -k test.wcfs
    date:   Wed, 10 Nov 2021 12:35:34 MSK
    xnode:  kirr@deca.navytux.spb.ru
    uname:  Linux deca 5.10.0-9-amd64 #1 SMP Debian 5.10.70-1 (2021-09-30) x86_64
    cpu:    Intel(R) Core(TM) i7-7600U CPU @ 2.80GHz
    >>> test.wcfs/fs:1
    ...
    ok      test.wcfs/fs:1  25.035s # 35t 0e 0f 0s

    >>> test.wcfs/fs:2
    ...
    ok      test.wcfs/fs:2  21.033s # 35t 0e 0f 0s

    >>> test.wcfs/fs:
    ...
    ok      test.wcfs/fs:   21.056s # 35t 0e 0f 0s
    # ran 3 test cases:  3·ok

/reviewed-by @jerome
/reviewed-on nexedi/nxdtest!12
parent 72e36088
...@@ -61,7 +61,7 @@ from time import time, sleep, strftime, gmtime, localtime ...@@ -61,7 +61,7 @@ from time import time, sleep, strftime, gmtime, localtime
import os, sys, argparse, logging, traceback, re, pwd, socket import os, sys, argparse, logging, traceback, re, pwd, socket
from errno import ESRCH, EPERM from errno import ESRCH, EPERM
import six import six
from golang import b, select, default from golang import b, defer, func, select, default
from golang import context, sync from golang import context, sync
import psutil import psutil
...@@ -111,6 +111,7 @@ def emit(*message): ...@@ -111,6 +111,7 @@ def emit(*message):
print(*message) print(*message)
sys.stdout.flush() sys.stdout.flush()
@func
def main(): def main():
# testnode executes us giving URL to master results collecting instance and other details # testnode executes us giving URL to master results collecting instance and other details
# https://lab.nexedi.com/nexedi/erp5/blob/744f3fde/erp5/util/testnode/UnitTestRunner.py#L137 # https://lab.nexedi.com/nexedi/erp5/blob/744f3fde/erp5/util/testnode/UnitTestRunner.py#L137
...@@ -183,6 +184,29 @@ def main(): ...@@ -183,6 +184,29 @@ def main():
bstdout = sys.stdout.buffer bstdout = sys.stdout.buffer
bstderr = sys.stderr.buffer bstderr = sys.stderr.buffer
# emit run summary at the end
summaryv = [] # of summary line for each ran testcase
def _():
stat = {} # st -> count
for line in summaryv:
st, _ = line.split(None, 1) # 'ok testname ...' -> 'ok'
stat[st] = stat.get(st, 0) + 1
s = '# ran %d test case' % len(summaryv)
if len(summaryv) == 0:
s += 's.'
else:
if len(summaryv) > 1:
s += 's'
s += ':'
# ok, fail, error go in that order
for st in ('ok', 'fail', 'error') + tuple(stat.keys()):
n = stat.pop(st, 0)
if n != 0:
s += ' %d·%s' % (n, st)
emit(s)
defer(_)
# run the tests # run the tests
devnull = open(os.devnull) devnull = open(os.devnull)
while 1: while 1:
...@@ -299,7 +323,9 @@ def main(): ...@@ -299,7 +323,9 @@ def main():
} }
tres.update(status) tres.update(status)
emit(_test_result_summary(t.name, tres)) _ = _test_result_summary(t.name, tres)
summaryv.append(_)
emit(_)
test_result_line.stop(**tres) test_result_line.stop(**tres)
# tee, similar to tee(1) utility, copies data from fin to fout appending them to buf. # tee, similar to tee(1) utility, copies data from fin to fout appending them to buf.
......
...@@ -64,7 +64,8 @@ TestCase('TESTNAME', ['echo', 'TEST OUPUT']) ...@@ -64,7 +64,8 @@ TestCase('TESTNAME', ['echo', 'TEST OUPUT'])
assert ">>> TESTNAME" in output_lines assert ">>> TESTNAME" in output_lines
assert "$ echo TEST OUPUT" in output_lines assert "$ echo TEST OUPUT" in output_lines
assert "TEST OUPUT" in output_lines assert "TEST OUPUT" in output_lines
assert re.match("ok\tTESTNAME\t.*s\t# 1t 0e 0f 0s", output_lines[-1]) assert re.match("ok\tTESTNAME\t.*s\t# 1t 0e 0f 0s", output_lines[-2])
assert re.match(u"# ran 1 test case: 1·ok", output_lines[-1])
def test_error_invoking_command(run_nxdtest, capsys): def test_error_invoking_command(run_nxdtest, capsys):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment