Esempio n. 1
0
class TestComponentManagerProperStart(AdvanceTimeTestCase):
    def setUp(self):
        mocks.mock_conf_settings(self)
        self.component_manager = ComponentManager(
            skip_components=[
                DATABASE_COMPONENT, DHT_COMPONENT, HASH_ANNOUNCER_COMPONENT,
                PEER_PROTOCOL_SERVER_COMPONENT, REFLECTOR_COMPONENT,
                UPNP_COMPONENT, HEADERS_COMPONENT, PAYMENT_RATE_COMPONENT,
                RATE_LIMITER_COMPONENT, EXCHANGE_RATE_MANAGER_COMPONENT
            ],
            wallet=mocks.FakeDelayedWallet,
            file_manager=mocks.FakeDelayedFileManager,
            blob_manager=mocks.FakeDelayedBlobManager)

    async def test_proper_starting_of_components(self):
        asyncio.create_task(self.component_manager.setup())

        await self.advance(0)
        self.assertTrue(self.component_manager.get_component('wallet').running)
        self.assertFalse(
            self.component_manager.get_component('blob_manager').running)
        self.assertFalse(
            self.component_manager.get_component('file_manager').running)

        await self.advance(1)
        self.assertTrue(self.component_manager.get_component('wallet').running)
        self.assertTrue(
            self.component_manager.get_component('blob_manager').running)
        self.assertFalse(
            self.component_manager.get_component('file_manager').running)

        await self.advance(1)
        self.assertTrue(self.component_manager.get_component('wallet').running)
        self.assertTrue(
            self.component_manager.get_component('blob_manager').running)
        self.assertTrue(
            self.component_manager.get_component('file_manager').running)

    async def test_proper_stopping_of_components(self):
        asyncio.create_task(self.component_manager.setup())
        await self.advance(0)
        await self.advance(1)
        await self.advance(1)
        self.assertTrue(self.component_manager.get_component('wallet').running)
        self.assertTrue(
            self.component_manager.get_component('blob_manager').running)
        self.assertTrue(
            self.component_manager.get_component('file_manager').running)

        asyncio.create_task(self.component_manager.stop())
        await self.advance(0)
        self.assertFalse(
            self.component_manager.get_component('file_manager').running)
        self.assertTrue(
            self.component_manager.get_component('blob_manager').running)
        self.assertTrue(self.component_manager.get_component('wallet').running)
        await self.advance(1)
        self.assertFalse(
            self.component_manager.get_component('file_manager').running)
        self.assertFalse(
            self.component_manager.get_component('blob_manager').running)
        self.assertTrue(self.component_manager.get_component('wallet').running)
        await self.advance(1)
        self.assertFalse(
            self.component_manager.get_component('file_manager').running)
        self.assertFalse(
            self.component_manager.get_component('blob_manager').running)
        self.assertFalse(
            self.component_manager.get_component('wallet').running)
class TestComponentManagerProperStart(unittest.TestCase):
    def setUp(self):
        self.reactor = Clock()
        mocks.mock_conf_settings(self)
        self.component_manager = ComponentManager(
            skip_components=[
                DATABASE_COMPONENT, DHT_COMPONENT, HASH_ANNOUNCER_COMPONENT,
                PEER_PROTOCOL_SERVER_COMPONENT, REFLECTOR_COMPONENT,
                UPNP_COMPONENT, HEADERS_COMPONENT, PAYMENT_RATE_COMPONENT,
                RATE_LIMITER_COMPONENT, EXCHANGE_RATE_MANAGER_COMPONENT
            ],
            reactor=self.reactor,
            wallet=mocks.FakeDelayedWallet,
            file_manager=mocks.FakeDelayedFileManager,
            blob_manager=mocks.FakeDelayedBlobManager)

    def tearDown(self):
        pass

    def test_proper_starting_of_components(self):
        self.component_manager.setup()
        self.assertTrue(self.component_manager.get_component('wallet').running)
        self.assertFalse(
            self.component_manager.get_component('blob_manager').running)
        self.assertFalse(
            self.component_manager.get_component('file_manager').running)

        self.reactor.advance(1)
        self.assertTrue(self.component_manager.get_component('wallet').running)
        self.assertTrue(
            self.component_manager.get_component('blob_manager').running)
        self.assertFalse(
            self.component_manager.get_component('file_manager').running)

        self.reactor.advance(1)
        self.assertTrue(self.component_manager.get_component('wallet').running)
        self.assertTrue(
            self.component_manager.get_component('blob_manager').running)
        self.assertTrue(
            self.component_manager.get_component('file_manager').running)

    def test_proper_stopping_of_components(self):
        self.component_manager.setup()
        self.reactor.advance(1)
        self.reactor.advance(1)
        self.component_manager.stop()
        self.assertFalse(
            self.component_manager.get_component('file_manager').running)
        self.assertTrue(
            self.component_manager.get_component('blob_manager').running)
        self.assertTrue(self.component_manager.get_component('wallet').running)

        self.reactor.advance(1)
        self.assertFalse(
            self.component_manager.get_component('file_manager').running)
        self.assertFalse(
            self.component_manager.get_component('blob_manager').running)
        self.assertTrue(self.component_manager.get_component('wallet').running)

        self.reactor.advance(1)
        self.assertFalse(
            self.component_manager.get_component('file_manager').running)
        self.assertFalse(
            self.component_manager.get_component('blob_manager').running)
        self.assertFalse(
            self.component_manager.get_component('wallet').running)
Esempio n. 3
0
class TestComponentManagerProperStart(AdvanceTimeTestCase):
    def setUp(self):
        self.component_manager = ComponentManager(
            Config(),
            skip_components=[
                DATABASE_COMPONENT, DHT_COMPONENT, HASH_ANNOUNCER_COMPONENT,
                PEER_PROTOCOL_SERVER_COMPONENT, UPNP_COMPONENT,
                HEADERS_COMPONENT, EXCHANGE_RATE_MANAGER_COMPONENT
            ],
            wallet=FakeDelayedWallet,
            stream_manager=FakeDelayedStreamManager,
            blob_manager=FakeDelayedBlobManager)

    async def test_proper_starting_of_components(self):
        asyncio.create_task(self.component_manager.start())

        await self.advance(0)
        self.assertTrue(self.component_manager.get_component('wallet').running)
        self.assertFalse(
            self.component_manager.get_component('blob_manager').running)
        self.assertFalse(
            self.component_manager.get_component('stream_manager').running)

        await self.advance(1)
        self.assertTrue(self.component_manager.get_component('wallet').running)
        self.assertTrue(
            self.component_manager.get_component('blob_manager').running)
        self.assertFalse(
            self.component_manager.get_component('stream_manager').running)

        await self.advance(1)
        self.assertTrue(self.component_manager.get_component('wallet').running)
        self.assertTrue(
            self.component_manager.get_component('blob_manager').running)
        self.assertTrue(
            self.component_manager.get_component('stream_manager').running)

    async def test_proper_stopping_of_components(self):
        asyncio.create_task(self.component_manager.start())
        await self.advance(0)
        await self.advance(1)
        await self.advance(1)
        self.assertTrue(self.component_manager.get_component('wallet').running)
        self.assertTrue(
            self.component_manager.get_component('blob_manager').running)
        self.assertTrue(
            self.component_manager.get_component('stream_manager').running)

        asyncio.create_task(self.component_manager.stop())
        await self.advance(0)
        self.assertFalse(
            self.component_manager.get_component('stream_manager').running)
        self.assertTrue(
            self.component_manager.get_component('blob_manager').running)
        self.assertTrue(self.component_manager.get_component('wallet').running)
        await self.advance(1)
        self.assertFalse(
            self.component_manager.get_component('stream_manager').running)
        self.assertFalse(
            self.component_manager.get_component('blob_manager').running)
        self.assertTrue(self.component_manager.get_component('wallet').running)
        await self.advance(1)
        self.assertFalse(
            self.component_manager.get_component('stream_manager').running)
        self.assertFalse(
            self.component_manager.get_component('blob_manager').running)
        self.assertFalse(
            self.component_manager.get_component('wallet').running)