From 09faeff19668c267a541b7ee0ae14b42db91dee9 Mon Sep 17 00:00:00 2001 From: Tomasz Grabiec Date: Thu, 16 Oct 2014 16:03:26 +0200 Subject: [PATCH] tests: distinguish between fast and slow tests Most of the tests are fast and they cover most of the functionality. The slow minority of tests takes significantly more time to run. Developers should run tests frequently in order to get feedback on correctness of their changes. The test runner distinguishes now between fast and slow tests. When given '--fast' switch it skips tests marked as slow. $ time ./test.py [8/8] PASSED tests/memcache/test.py --mode release OK. real 0m33.084s user 0m0.501s sys 0m0.271s $ time ./test.py --fast [8/8] PASSED tests/memcache/test.py --mode release --fast OK. real 0m1.012s user 0m0.464s sys 0m0.247s --- test.py | 7 ++++++- tests/memcache/test.py | 24 +++++++++++++++--------- tests/memcache/test_memcache.py | 11 +++++++++++ 3 files changed, 32 insertions(+), 10 deletions(-) diff --git a/test.py b/test.py index 6c8c3452fa..eb693e99cd 100755 --- a/test.py +++ b/test.py @@ -1,6 +1,7 @@ #!/usr/bin/env python3 import os import sys +import argparse import subprocess all_tests = [ @@ -18,13 +19,17 @@ def print_status(msg): print('\r' + msg, end='') if __name__ == "__main__": + parser = argparse.ArgumentParser(description="Seastar test runner") + parser.add_argument('--fast', action="store_true", help="Run only fast tests") + args = parser.parse_args() + black_hole = open('/dev/null', 'w') test_to_run = [] for mode in ['debug', 'release']: for test in all_tests: test_to_run.append(os.path.join('build', mode, 'tests', test)) - test_to_run.append('tests/memcache/test.py ' + os.path.join('build', mode, 'apps', 'memcache', 'memcache') + ' --smp 1') + test_to_run.append('tests/memcache/test.py --mode ' + mode + (' --fast' if args.fast else '')) all_ok = True diff --git a/tests/memcache/test.py b/tests/memcache/test.py index 0b94f1a68c..55e31c95ad 100755 --- a/tests/memcache/test.py +++ b/tests/memcache/test.py @@ -1,24 +1,30 @@ #!/usr/bin/env python3 import time -import subprocess import sys +import os +import argparse +import subprocess -if len(sys.argv) < 2: - print('Usage: %s ...' % sys.argv[0]) -memcache_path = sys.argv[1] - -def run(cmd): - mc = subprocess.Popen([memcache_path] + sys.argv[2:]) +def run(args, cmd): + mc = subprocess.Popen([os.path.join('build', args.mode, 'apps', 'memcache', 'memcache'), '--smp', '1']) print('Memcache started.') try: time.sleep(0.1) cmdline = ['tests/memcache/test_memcache.py'] + cmd + if args.fast: + cmdline.append('--fast') print('Running: ' + ' '.join(cmdline)) subprocess.check_call(cmdline) finally: print('Killing memcache...') mc.kill() -run([]) -run(['-U']) +if __name__ == "__main__": + parser = argparse.ArgumentParser(description="Seastar test runner") + parser.add_argument('--fast', action="store_true", help="Run only fast tests") + parser.add_argument('--mode', action="store", help="Test app in given mode", default='release') + args = parser.parse_args() + + run(args, []) + run(args, ['-U']) diff --git a/tests/memcache/test_memcache.py b/tests/memcache/test_memcache.py index 0b94e12bc6..f8c4ad36c5 100755 --- a/tests/memcache/test_memcache.py +++ b/tests/memcache/test_memcache.py @@ -9,6 +9,7 @@ import unittest server_addr = None call = None +args = None @contextmanager def tcp_connection(): @@ -20,6 +21,13 @@ def tcp_connection(): yield call s.close() +def slow(f): + def wrapper(self): + if args.fast: + raise unittest.SkipTest('Slow') + return f(self) + return wrapper + def recv_all(s): m = b'' while True: @@ -119,12 +127,14 @@ class TestCommands(unittest.TestCase): def test_error_handling(self): self.assertEqual(call('get\r\n'), b'ERROR\r\n') + @slow def test_expiry(self): self.assertEqual(call('set key 0 1 5\r\nhello\r\n'), b'STORED\r\n') self.assertEqual(call('get key\r\n'), b'VALUE key 0 5\r\nhello\r\nEND\r\n') time.sleep(1) self.assertEqual(call('get key\r\n'), b'END\r\n') + @slow def test_expiry_at_epoch_time(self): expiry = int(time.time()) + 1 self.assertEqual(call('set key 0 %d 5\r\nhello\r\n' % expiry), b'STORED\r\n') @@ -159,6 +169,7 @@ if __name__ == '__main__': parser = argparse.ArgumentParser(description="memcache protocol tests") parser.add_argument('--server', '-s', action="store", help="server adddress in : format", default="localhost:11211") parser.add_argument('--udp', '-U', action="store_true", help="Use UDP protocol") + parser.add_argument('--fast', action="store_true", help="Run only fast tests") args = parser.parse_args() host, port = args.server.split(':')