<commit_before>
import unittest

import gevent

from slimta.relay.pool import RelayPool, RelayPoolClient
from slimta.envelope import Envelope


class TestPool(RelayPool):

    def add_client(self):
        return TestClient(self.queue)


class TestClient(RelayPoolClient):

    def _run(self):
        ret = self.poll()
        if isinstance(ret, tuple):
            result, envelope = ret
            result.set('test')


class TestRelayPool(unittest.TestCase):

    def test_add_remove_client(self):
        pool = TestPool()
        pool.queue.append(True)
        pool._add_client()
        for client in pool.pool:
            client.join()
        gevent.sleep(0)
        self.assertFalse(pool.pool)

    def test_add_remove_client_morequeued(self):
        pool = TestPool()
        pool.queue.append(True)
        pool.queue.append(True)
        pool._add_client()
        for client in pool.pool:
            client.join()
        self.assertTrue(pool.pool)
        for client in pool.pool:
            client.join()
        gevent.sleep(0)
        self.assertFalse(pool.pool)

    def test_attempt(self):
        env = Envelope()
        pool = TestPool()
        ret = pool.attempt(env, 0)
        self.assertEqual('test', ret)

    def test_kill(self):
        pool = RelayPool()
        pool.pool.add(RelayPoolClient(None))
        pool.pool.add(RelayPoolClient(None))
        pool.pool.add(RelayPoolClient(None))<commit_msg>improvements to test robustness<commit_after>
import unittest

import gevent

from slimta.relay.pool import RelayPool, RelayPoolClient
from slimta.envelope import Envelope


class TestPool(RelayPool):

    def add_client(self):
        return TestClient(self.queue)


class TestClient(RelayPoolClient):

    def _run(self):
        ret = self.poll()
        if isinstance(ret, tuple):
            result, envelope = ret
            result.set('test')


class TestRelayPool(unittest.TestCase):

    def test_add_remove_client(self):
        pool = TestPool()
        pool.queue.append(True)
        pool._add_client()
        pool_copy = pool.pool.copy()
        for client in pool_copy:
            client.join()
        gevent.sleep(0)
        self.assertFalse(pool.pool)

    def test_add_remove_client_morequeued(self):
        pool = TestPool()
        pool.queue.append(True)
        pool.queue.append(True)
        pool._add_client()
        pool_copy = pool.pool.copy()
        for client in pool_copy:
            client.join()
        self.assertTrue(pool.pool)
        pool_copy = pool.pool.copy()
        for client in pool_copy:
            client.join()
        gevent.sleep(0)
        self.assertFalse(pool.pool)

    def test_attempt(self):
        env = Envelope()
        pool = TestPool()
        ret = pool.attempt(env, 0)
        self.assertEqual('test', ret)

    def test_kill(self):
        pool = RelayPool()
        pool.pool.add(RelayPoolClient(None))
        pool.pool.add(RelayPoolClient(None))
        pool.pool.add(RelayPoolClient(None))
{'fraction_non_alphanumeric': 0.10249584026622297, 'fraction_numerical': 0.0019966722129783694, 'mean_word_length': 2.2960526315789473, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7296092', 'n_tokens_mistral': 930, 'n_tokens_neox': 904, 'n_words': 180}