Exemple #1
0
def test_get_and_put(factory, iterations):
    p = _Pool(factory=factory.create)
    p.set_maxsize(1)
    for _ in range(iterations):
        ret = p.get()
        assert ret == factory.items[0]
        p.put(ret)
Exemple #2
0
def test_get_too_many(factory, maxsize):
    with pytest.raises(ExampleException):
        p = _Pool(factory=factory.create, exception=ExampleException)
        p.set_maxsize(maxsize)
        p.exception = ExampleException
        for _ in range(maxsize + 1):
            p.get()
 def _get_pool(self, key, shelldicts, properties):
     if key not in self._pools:
         self._pools[key] = _Pool(
             factory=lambda: _Terminal(key, shelldicts, properties),
             exception=TerminalPoolsBusy)
     pool = self._pools[key]
     pool.set_maxsize(properties.max_processes_in_target)
     return pool
Exemple #4
0
def test_remove(factory, iterations):
    p = _Pool(factory=factory.create)
    p.set_maxsize(1)

    for _ in range(iterations):
        item = p.get()
        p.remove(item)

    verify_items_closed(factory, iterations, p)
Exemple #5
0
def test_remove_every_nth_free(factory, sizeoffree, n,
                               expected_size_after_free):
    p = _Pool(factory=factory.create)
    p.set_maxsize(sizeoffree)
    items = []
    for op in [lambda: items.append(p.get()), lambda: p.put(items.pop())]:
        for _ in range(sizeoffree):
            op()
    p.remove_every_nth_free(n)
    assert len(p.free) == expected_size_after_free
Exemple #6
0
def test_set_maxsize_too_small(factory, maxsize, shared):
    with pytest.raises(ExampleException) as excinfo:
        p = _Pool(factory=factory.create, exception=ExampleException)
        p.set_maxsize(maxsize)
        items = []
        for _ in range(maxsize):
            items.append(p.get())

        if shared:
            for i in items:
                p.put_incr_shared(i)

        p.set_maxsize(maxsize - 1)
    assert 'Pool cannot set the maximum size less than' in str(excinfo.value)
Exemple #7
0
def test_close_raises(
        factory,
        iterations,  # pylint:disable=unused-argument
        intcaplog):
    def raise_exception():
        raise Exception('message')

    p = _Pool(factory=factory.create)
    p.set_maxsize(1)
    p.get()
    factory.items[0].close.side_effect = raise_exception
    p.close()

    assert 'Failed to close item {}: Exception (message)'.format(
        str(factory.items[0])) in intcaplog.text
Exemple #8
0
def test_close(factory, iterations):
    p = _Pool(factory=factory.create)
    p.set_maxsize(6)
    for _ in range(iterations):
        p.get()
    items = []
    for _ in range(iterations):
        items.append(p.get())

    for item in items:
        p.put(item)

    p.close()
    for item in factory.items:
        item.close.assert_called_once_with()
    assert not p.inuse
    assert not p.free
Exemple #9
0
def test_get(factory):
    p = _Pool(factory=factory.create)
    p.set_maxsize(1)
    assert p.get() == factory.items[0]
Exemple #10
0
 def pfact(maxsize):
     p = _Pool(factory=factory.create)
     p.set_maxsize(maxsize)
     return p