From ab59f78341f1dd188aaf4c30526f6295c63438b1 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Sat, 5 Jun 2010 20:03:09 +0200 Subject: Renamed mp to async, as this is a much better name for what is actually going on. The default implementation uses threads, which ends up being nothing more than async, as they are all locked down by internal and the global interpreter lock --- test/git/async/test_thread.py | 47 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 test/git/async/test_thread.py (limited to 'test/git/async/test_thread.py') diff --git a/test/git/async/test_thread.py b/test/git/async/test_thread.py new file mode 100644 index 00000000..ca306cc0 --- /dev/null +++ b/test/git/async/test_thread.py @@ -0,0 +1,47 @@ +# -*- coding: utf-8 -*- +""" Test thead classes and functions""" +from test.testlib import * +from git.async.thread import * +from Queue import Queue + +class TestWorker(WorkerThread): + def __init__(self, *args, **kwargs): + super(TestWorker, self).__init__(*args, **kwargs) + self.reset() + + def fun(self, *args, **kwargs): + self.called = True + self.args = args + self.kwargs = kwargs + return True + + def make_assertion(self): + assert self.called + assert self.args + assert self.kwargs + self.reset() + + def reset(self): + self.called = False + self.args = None + self.kwargs = None + + +class TestThreads( TestCase ): + + @terminate_threads + def test_worker_thread(self): + worker = TestWorker() + assert isinstance(worker.start(), WorkerThread) + + # test different method types + standalone_func = lambda *args, **kwargs: worker.fun(*args, **kwargs) + for function in ("fun", TestWorker.fun, worker.fun, standalone_func): + rval = worker.call(function, 1, this='that') + assert isinstance(rval, Queue) + assert rval.get() is True + worker.make_assertion() + # END for each function type + + worker.call('quit') + -- cgit v1.2.1 From ec28ad575ce1d7bb6a616ffc404f32bbb1af67b2 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Sun, 6 Jun 2010 12:48:25 +0200 Subject: thread: adjusted worker thread not to provide an output queue anymore - this is handled by the task system graph: implemented it including test according to the pools requirements pool: implemented set_pool_size --- test/git/async/test_thread.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'test/git/async/test_thread.py') diff --git a/test/git/async/test_thread.py b/test/git/async/test_thread.py index ca306cc0..2ea8d1ff 100644 --- a/test/git/async/test_thread.py +++ b/test/git/async/test_thread.py @@ -37,9 +37,7 @@ class TestThreads( TestCase ): # test different method types standalone_func = lambda *args, **kwargs: worker.fun(*args, **kwargs) for function in ("fun", TestWorker.fun, worker.fun, standalone_func): - rval = worker.call(function, 1, this='that') - assert isinstance(rval, Queue) - assert rval.get() is True + worker.call(function, 1, this='that') worker.make_assertion() # END for each function type -- cgit v1.2.1 From 6a252661c3bf4202a4d571f9c41d2afa48d9d75f Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Sun, 6 Jun 2010 23:41:20 +0200 Subject: pool: First version which works as expected in async mode. Its just using a single task for now, but next up are dependent tasks --- test/git/async/test_thread.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'test/git/async/test_thread.py') diff --git a/test/git/async/test_thread.py b/test/git/async/test_thread.py index 2ea8d1ff..a08c1dc7 100644 --- a/test/git/async/test_thread.py +++ b/test/git/async/test_thread.py @@ -3,28 +3,26 @@ from test.testlib import * from git.async.thread import * from Queue import Queue +import time class TestWorker(WorkerThread): def __init__(self, *args, **kwargs): super(TestWorker, self).__init__(*args, **kwargs) self.reset() - def fun(self, *args, **kwargs): + def fun(self, arg): self.called = True - self.args = args - self.kwargs = kwargs + self.arg = arg return True def make_assertion(self): assert self.called - assert self.args - assert self.kwargs + assert self.arg self.reset() def reset(self): self.called = False - self.args = None - self.kwargs = None + self.arg = None class TestThreads( TestCase ): @@ -36,10 +34,11 @@ class TestThreads( TestCase ): # test different method types standalone_func = lambda *args, **kwargs: worker.fun(*args, **kwargs) - for function in ("fun", TestWorker.fun, worker.fun, standalone_func): - worker.call(function, 1, this='that') + for function in (TestWorker.fun, worker.fun, standalone_func): + worker.inq.put((function, 1)) + time.sleep(0.01) worker.make_assertion() # END for each function type - worker.call('quit') + worker.stop_and_join() -- cgit v1.2.1