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/__init__.py | 0 test/git/async/test_channel.py | 61 ++++++++++++++++++++++++++++++++++++++++++ test/git/async/test_pool.py | 10 +++++++ test/git/async/test_thread.py | 47 ++++++++++++++++++++++++++++++++ test/git/mp/__init__.py | 0 test/git/mp/test_channel.py | 61 ------------------------------------------ test/git/mp/test_pool.py | 10 ------- test/git/mp/test_thread.py | 47 -------------------------------- 8 files changed, 118 insertions(+), 118 deletions(-) create mode 100644 test/git/async/__init__.py create mode 100644 test/git/async/test_channel.py create mode 100644 test/git/async/test_pool.py create mode 100644 test/git/async/test_thread.py delete mode 100644 test/git/mp/__init__.py delete mode 100644 test/git/mp/test_channel.py delete mode 100644 test/git/mp/test_pool.py delete mode 100644 test/git/mp/test_thread.py (limited to 'test') diff --git a/test/git/async/__init__.py b/test/git/async/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/test/git/async/test_channel.py b/test/git/async/test_channel.py new file mode 100644 index 00000000..ad68a8d5 --- /dev/null +++ b/test/git/async/test_channel.py @@ -0,0 +1,61 @@ +"""Channel testing""" +from test.testlib import * +from git.async.channel import * + +import time + +class TestChannels(TestBase): + + def test_base(self): + # creating channel yields a write and a read channal + wc, rc = Channel() + assert isinstance(wc, WChannel) + assert isinstance(rc, RChannel) + + # everything else fails + self.failUnlessRaises(ValueError, Channel, 1, "too many args") + + # TEST UNLIMITED SIZE CHANNEL - writing+reading is FIFO + item = 1 + item2 = 2 + wc.write(item) + wc.write(item2) + assert rc.read() == item + assert rc.read() == item2 + + # next read blocks, then raises - it waits a second + st = time.time() + self.failUnlessRaises(IOError, rc.read, True, 1) + assert time.time() - st >= 1.0 + + # writing to a closed channel raises + assert not wc.closed + wc.close() + assert wc.closed + wc.close() # fine + assert wc.closed + + self.failUnlessRaises(IOError, wc.write, 1) + + # reading from a closed channel never blocks + self.failUnlessRaises(IOError, rc.read) + + + + # TEST LIMITED SIZE CHANNEL + # channel with max-items set + wc, rc = Channel(1) + wc.write(item) # fine + + # blocks for a second, its full + st = time.time() + self.failUnlessRaises(IOError, wc.write, item, True, 1) + assert time.time() - st >= 1.0 + + # get one + assert rc.read() == item + + # its empty,can put one again + wc.write(item2) + assert rc.read() == item2 + wc.close() diff --git a/test/git/async/test_pool.py b/test/git/async/test_pool.py new file mode 100644 index 00000000..3a9ef8a1 --- /dev/null +++ b/test/git/async/test_pool.py @@ -0,0 +1,10 @@ +"""Channel testing""" +from test.testlib import * +from git.async.pool import * + +import time + +class TestThreadPool(TestBase): + + def test_base(self): + pass 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') + diff --git a/test/git/mp/__init__.py b/test/git/mp/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/test/git/mp/test_channel.py b/test/git/mp/test_channel.py deleted file mode 100644 index 9b667372..00000000 --- a/test/git/mp/test_channel.py +++ /dev/null @@ -1,61 +0,0 @@ -"""Channel testing""" -from test.testlib import * -from git.mp.channel import * - -import time - -class TestChannels(TestBase): - - def test_base(self): - # creating channel yields a write and a read channal - wc, rc = Channel() - assert isinstance(wc, WChannel) - assert isinstance(rc, RChannel) - - # everything else fails - self.failUnlessRaises(ValueError, Channel, 1, "too many args") - - # TEST UNLIMITED SIZE CHANNEL - writing+reading is FIFO - item = 1 - item2 = 2 - wc.write(item) - wc.write(item2) - assert rc.read() == item - assert rc.read() == item2 - - # next read blocks, then raises - it waits a second - st = time.time() - self.failUnlessRaises(IOError, rc.read, True, 1) - assert time.time() - st >= 1.0 - - # writing to a closed channel raises - assert not wc.closed - wc.close() - assert wc.closed - wc.close() # fine - assert wc.closed - - self.failUnlessRaises(IOError, wc.write, 1) - - # reading from a closed channel never blocks - self.failUnlessRaises(IOError, rc.read) - - - - # TEST LIMITED SIZE CHANNEL - # channel with max-items set - wc, rc = Channel(1) - wc.write(item) # fine - - # blocks for a second, its full - st = time.time() - self.failUnlessRaises(IOError, wc.write, item, True, 1) - assert time.time() - st >= 1.0 - - # get one - assert rc.read() == item - - # its empty,can put one again - wc.write(item2) - assert rc.read() == item2 - wc.close() diff --git a/test/git/mp/test_pool.py b/test/git/mp/test_pool.py deleted file mode 100644 index 7c4a366f..00000000 --- a/test/git/mp/test_pool.py +++ /dev/null @@ -1,10 +0,0 @@ -"""Channel testing""" -from test.testlib import * -from git.mp.pool import * - -import time - -class TestThreadPool(TestBase): - - def test_base(self): - pass diff --git a/test/git/mp/test_thread.py b/test/git/mp/test_thread.py deleted file mode 100644 index 9625aabb..00000000 --- a/test/git/mp/test_thread.py +++ /dev/null @@ -1,47 +0,0 @@ -# -*- coding: utf-8 -*- -""" Test thead classes and functions""" -from test.testlib import * -from git.mp.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.3