def test_add_pending(self): """ If a new option is added, it should fulfill pending requests """ pool = NextAvailablePool() d = pool.get() self.assertFalse(d.called) pool.add('foo') self.assertTrue(d.called, "Should fulfill pending request")
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_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")
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)