From 990b81eaae4e3ddd8f6598e1be38263a65b49160 Mon Sep 17 00:00:00 2001 From: Dmitry Shulyak Date: Fri, 14 Jun 2013 15:11:13 +0300 Subject: [PATCH] killing test runs --- core/api.py | 5 +++++ core/transport/nose_adapter.py | 16 +++++++++++++--- core/wsgi/controllers/v1.py | 4 ++-- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/core/api.py b/core/api.py index 28a9a17..fef01d4 100644 --- a/core/api.py +++ b/core/api.py @@ -20,6 +20,11 @@ class API(object): return self._storage.get_test_results(stored_id) return self._storage.get_test_result(stored_id, test_id, meta=meta) + def kill(self, test_run, test_run_id): + transport = get_transport(test_run) + stored_id = '{}:{}'.format(test_run, test_run_id) + return transport.kill(stored_id) + def flush_storage(self): self._storage.flush_db() diff --git a/core/transport/nose_adapter.py b/core/transport/nose_adapter.py index 4cdc5e3..b0093fd 100644 --- a/core/transport/nose_adapter.py +++ b/core/transport/nose_adapter.py @@ -20,6 +20,9 @@ nose_opts = [ cfg.CONF.register_opts(nose_opts) +TESTS_PROCESS = {} + + class RedisPlugin(plugins.Plugin): enabled = True @@ -33,7 +36,7 @@ class RedisPlugin(plugins.Plugin): super(RedisPlugin, self).__init__() self._current_stderr = None self._current_stdout = None - self._start_capture() + # self._start_capture() def options(self, parser, env=os.environ): pass @@ -55,7 +58,6 @@ class RedisPlugin(plugins.Plugin): self.stats['passes'] += 1 self.add_message(test, type='success') - def addFailure(self, test, err, capt=None, tb_info=None): self.stats['failures'] += 1 self.add_message(test, type='failure') @@ -121,7 +123,7 @@ class NoseDriver(object): def run(self, test_run, conf): gev = gevent.spawn(self._run_tests, test_run, [conf['working_directory']]) - gev.join() + TESTS_PROCESS[test_run] = gev def _run_tests(self, test_run, argv_add): try: @@ -130,7 +132,15 @@ class NoseDriver(object): exit=True, argv=[test_run]+argv_add) finally: + # del TESTS_PROCESS[test_run] raise gevent.GreenletExit + def kill(self, test_run): + if test_run in TESTS_PROCESS: + TESTS_PROCESS[test_run].kill() + del TESTS_PROCESS[test_run] + + + diff --git a/core/wsgi/controllers/v1.py b/core/wsgi/controllers/v1.py index c0a5703..c93b4a9 100644 --- a/core/wsgi/controllers/v1.py +++ b/core/wsgi/controllers/v1.py @@ -17,6 +17,6 @@ class V1Controller(rest.RestController): return request.api.get_info(test_run, test_run_id, test_id, stats) @expose('json') - def delete(self): - request.api.flush_storage() + def delete(self, test_run, test_run_id=0): + request.api.kill(test_run, test_run_id) return {} \ No newline at end of file