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_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)
def test_common(self): pool = NextAvailablePool() pool.add('foo') pool.add('bar') a = yield pool.get() yield pool.get() c = pool.get() self.assertFalse(c.called, "Shouldn't have any available") yield pool.done(a) self.assertTrue(c.called, "The pending request should get the " "newly available thing")