def test_remove_pending(self): """ If the option is in use, don't remove it until its done being used. """ pool = NextAvailablePool() pool.add('foo') a = yield pool.get() b = pool.remove('foo') self.assertFalse(b.called, "Don't remove it yet because it's being used") pool.done(a) self.assertEqual(self.successResultOf(b), 'foo')
def test_remove_twice(self): """ If you request removal twice, both removals will be fulfilled """ pool = NextAvailablePool() pool.add('foo') a = yield pool.get() b = pool.remove('foo') c = pool.remove('foo') pool.done(a) self.assertEqual(self.successResultOf(b), 'foo') self.assertEqual(self.successResultOf(c), 'foo')
def test_list(self): """ You can list all the things in the pool """ pool = NextAvailablePool() pool.add('foo') pool.add('bar') yield pool.get() pool.add('choo') pool.add('bozo') yield pool.remove('bozo') r = pool.list() self.assertEqual(set(r), set(['foo', 'bar', 'choo']))
def test_remove(self): """ If the option isn't being used, removal should happen immediately """ pool = NextAvailablePool() pool.add('foo') pool.add('bar') r = yield pool.remove('foo') self.assertEqual(r, 'foo') a = yield pool.get() self.assertEqual(a, 'bar') b = pool.get() self.assertEqual(b.called, False) pool.done(a) self.assertEqual(b.called, True)