示例#1
0
 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)
示例#2
0
 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)
示例#3
0
def get_test_daemon(data_rate=None, generous=True, with_fee=False):
    if data_rate is None:
        data_rate = conf.ADJUSTABLE_SETTINGS['data_rate'][1]
    rates = {
        'BTCLBC': {'spot': 3.0, 'ts': test_utils.DEFAULT_ISO_TIME + 1},
        'USDBTC': {'spot': 2.0, 'ts': test_utils.DEFAULT_ISO_TIME + 2}
    }
    component_manager = ComponentManager(
        skip_components=[DATABASE_COMPONENT, DHT_COMPONENT, WALLET_COMPONENT, UPNP_COMPONENT,
                         PEER_PROTOCOL_SERVER_COMPONENT, REFLECTOR_COMPONENT, HASH_ANNOUNCER_COMPONENT,
                         EXCHANGE_RATE_MANAGER_COMPONENT, BLOB_COMPONENT,
                         HEADERS_COMPONENT, RATE_LIMITER_COMPONENT],
        file_manager=FakeFileManager
    )
    daemon = LBRYDaemon(component_manager=component_manager)
    daemon.payment_rate_manager = OnlyFreePaymentsManager()
    daemon.wallet_manager = mock.Mock(spec=LbryWalletManager)
    daemon.wallet_manager.wallet = mock.Mock(spec=Wallet)
    daemon.wallet_manager.wallet.use_encryption = False
    daemon.wallet_manager.network = FakeNetwork()
    daemon.storage = mock.Mock(spec=SQLiteStorage)
    market_feeds = [BTCLBCFeed(), USDBTCFeed()]
    daemon.exchange_rate_manager = DummyExchangeRateManager(market_feeds, rates)
    daemon.file_manager = component_manager.get_component(FILE_MANAGER_COMPONENT)

    metadata = {
        "author": "fake author",
        "language": "en",
        "content_type": "fake/format",
        "description": "fake description",
        "license": "fake license",
        "license_url": "fake license url",
        "nsfw": False,
        "sources": {
            "lbry_sd_hash": 'd2b8b6e907dde95245fe6d144d16c2fdd60c4e0c6463ec98'
                            'b85642d06d8e9414e8fcfdcb7cb13532ec5454fb8fe7f280'
        },
        "thumbnail": "fake thumbnail",
        "title": "fake title",
        "ver": "0.0.3"
    }
    if with_fee:
        metadata.update(
            {"fee": {"USD": {"address": "bQ6BGboPV2SpTMEP7wLNiAcnsZiH8ye6eA", "amount": 0.75}}})
    migrated = smart_decode(json.dumps(metadata))
    daemon._resolve = daemon.wallet_manager.resolve = lambda *_: defer.succeed(
        {"test": {'claim': {'value': migrated.claim_dict}}})
    return daemon
    def test_init_with_wrong_overrides(self):
        class FakeRandomComponent:
            component_name = "someComponent"
            depends_on = []

        with self.assertRaises(SyntaxError):
            ComponentManager(randomComponent=FakeRandomComponent)
示例#5
0
文件: server.py 项目: guzhenping/lbry
 def __init__(self,
              analytics_manager=None,
              component_manager=None,
              use_authentication=None,
              use_https=None,
              to_skip=None,
              looping_calls=None,
              reactor=None):
     if not reactor:
         from twisted.internet import reactor
     self.analytics_manager = analytics_manager or analytics.Manager.new_instance(
     )
     self.component_manager = component_manager or ComponentManager(
         analytics_manager=self.analytics_manager,
         skip_components=to_skip or [],
         reactor=reactor)
     self.looping_call_manager = LoopingCallManager(
         {n: lc
          for n, (lc, t) in (looping_calls or {}).items()})
     self._looping_call_times = {
         n: t
         for n, (lc, t) in (looping_calls or {}).items()
     }
     self._use_authentication = use_authentication or conf.settings[
         'use_auth_http']
     self._use_https = use_https or conf.settings['use_https']
     self.listening_port = None
     self._component_setup_deferred = None
     self.announced_startup = False
     self.sessions = {}
     self.server = None
     self.keyring = Keyring.generate_and_save()
class TestComponentManager(unittest.TestCase):
    def setUp(self):
        mocks.mock_conf_settings(self)

        self.default_components_sort = [
            [
                Components.HeadersComponent, Components.DatabaseComponent,
                Components.ExchangeRateManagerComponent,
                Components.PaymentRateComponent,
                Components.RateLimiterComponent, Components.UPnPComponent
            ],
            [
                Components.BlobComponent, Components.DHTComponent,
                Components.WalletComponent
            ],
            [
                Components.FileManagerComponent,
                Components.HashAnnouncerComponent,
                Components.PeerProtocolServerComponent
            ], [Components.ReflectorComponent]
        ]
        self.component_manager = ComponentManager()

    def tearDown(self):
        pass

    def test_sort_components(self):
        stages = self.component_manager.sort_components()
        for stage_list, sorted_stage_list in zip(stages,
                                                 self.default_components_sort):
            self.assertEqual([type(stage) for stage in stage_list],
                             sorted_stage_list)

    def test_sort_components_reverse(self):
        rev_stages = self.component_manager.sort_components(reverse=True)
        reverse_default_components_sort = reversed(
            self.default_components_sort)

        for stage_list, sorted_stage_list in zip(
                rev_stages, reverse_default_components_sort):
            self.assertEqual([type(stage) for stage in stage_list],
                             sorted_stage_list)

    def test_get_component_not_exists(self):

        with self.assertRaises(NameError):
            self.component_manager.get_component("random_component")
    def test_init_with_overrides(self):
        class FakeWallet:
            component_name = "wallet"
            depends_on = []

            def __init__(self, component_manager):
                self.component_manager = component_manager

            @property
            def component(self):
                return self

        new_component_manager = ComponentManager(wallet=FakeWallet)
        fake_wallet = new_component_manager.get_component("wallet")
        # wallet should be an instance of FakeWallet and not WalletComponent from Components.py
        self.assertIsInstance(fake_wallet, FakeWallet)
        self.assertNotIsInstance(fake_wallet, Components.WalletComponent)
示例#8
0
    async def asyncSetUp(self):
        await super().asyncSetUp()

        logging.getLogger('lbrynet.blob_exchange').setLevel(self.VERBOSITY)
        logging.getLogger('lbrynet.daemon').setLevel(self.VERBOSITY)
        logging.getLogger('lbrynet.stream').setLevel(self.VERBOSITY)

        conf = Config()
        conf.data_dir = self.wallet_node.data_path
        conf.wallet_dir = self.wallet_node.data_path
        conf.download_dir = self.wallet_node.data_path
        conf.share_usage_data = False
        conf.use_upnp = False
        conf.reflect_streams = True
        conf.blockchain_name = 'lbrycrd_regtest'
        conf.lbryum_servers = [('127.0.0.1', 50001)]
        conf.reflector_servers = [('127.0.0.1', 5566)]
        conf.known_dht_nodes = []

        await self.account.ensure_address_gap()
        address = (await self.account.receiving.get_addresses(limit=1, only_usable=True))[0]
        sendtxid = await self.blockchain.send_to_address(address, 10)
        await self.confirm_tx(sendtxid)
        await self.generate(5)

        def wallet_maker(component_manager):
            self.wallet_component = WalletComponent(component_manager)
            self.wallet_component.wallet_manager = self.manager
            self.wallet_component._running = True
            return self.wallet_component

        conf.components_to_skip = [
            DHT_COMPONENT, UPNP_COMPONENT, HASH_ANNOUNCER_COMPONENT,
            PEER_PROTOCOL_SERVER_COMPONENT
        ]
        self.daemon = Daemon(conf, ComponentManager(
            conf, skip_components=conf.components_to_skip, wallet=wallet_maker,
            exchange_rate_manager=ExchangeRateManagerComponent
        ))
        await self.daemon.initialize()
        self.manager.old_db = self.daemon.storage

        server_tmp_dir = tempfile.mkdtemp()
        self.addCleanup(shutil.rmtree, server_tmp_dir)
        self.server_config = Config()
        self.server_storage = SQLiteStorage(self.server_config, ':memory:')
        await self.server_storage.open()

        self.server_blob_manager = BlobManager(self.loop, server_tmp_dir, self.server_storage, self.server_config)
        self.server = BlobServer(self.loop, self.server_blob_manager, 'bQEaw42GXsgCAGio1nxFncJSyRmnztSCjP')
        self.server.start_server(5567, '127.0.0.1')
        await self.server.started_listening.wait()

        self.reflector = ReflectorServer(self.server_blob_manager)
        self.reflector.start_server(5566, '127.0.0.1')
        await self.reflector.started_listening.wait()
        self.addCleanup(self.reflector.stop_server)
示例#9
0
 def setUp(self):
     self.default_components_sort = [
         [
             Components.HeadersComponent, Components.DatabaseComponent,
             Components.ExchangeRateManagerComponent,
             Components.UPnPComponent
         ],
         [
             Components.BlobComponent, Components.DHTComponent,
             Components.WalletComponent
         ],
         [
             Components.HashAnnouncerComponent,
             Components.PeerProtocolServerComponent,
             Components.StreamManagerComponent,
         ]
     ]
     self.component_manager = ComponentManager(Config())
示例#10
0
    def setUp(self):
        mocks.mock_conf_settings(self)

        self.default_components_sort = [
            [
                Components.HeadersComponent, Components.DatabaseComponent,
                Components.ExchangeRateManagerComponent,
                Components.PaymentRateComponent,
                Components.RateLimiterComponent, Components.UPnPComponent
            ],
            [
                Components.BlobComponent, Components.DHTComponent,
                Components.WalletComponent
            ],
            [
                Components.FileManagerComponent,
                Components.HashAnnouncerComponent,
                Components.PeerProtocolServerComponent
            ], [Components.ReflectorComponent]
        ]
        self.component_manager = ComponentManager()
示例#11
0
class TestComponentManager(AsyncioTestCase):
    def setUp(self):
        self.default_components_sort = [
            [
                Components.HeadersComponent, Components.DatabaseComponent,
                Components.ExchangeRateManagerComponent,
                Components.UPnPComponent
            ],
            [
                Components.BlobComponent, Components.DHTComponent,
                Components.WalletComponent
            ],
            [
                Components.HashAnnouncerComponent,
                Components.PeerProtocolServerComponent,
                Components.StreamManagerComponent,
            ]
        ]
        self.component_manager = ComponentManager(Config())

    def test_sort_components(self):
        stages = self.component_manager.sort_components()
        for stage_list, sorted_stage_list in zip(stages,
                                                 self.default_components_sort):
            self.assertEqual([type(stage) for stage in stage_list],
                             sorted_stage_list)

    def test_sort_components_reverse(self):
        rev_stages = self.component_manager.sort_components(reverse=True)
        reverse_default_components_sort = reversed(
            self.default_components_sort)
        for stage_list, sorted_stage_list in zip(
                rev_stages, reverse_default_components_sort):
            self.assertEqual([type(stage) for stage in stage_list],
                             sorted_stage_list)

    def test_get_component_not_exists(self):
        with self.assertRaises(NameError):
            self.component_manager.get_component("random_component")
示例#12
0
    async def setUp(self):
        await super().setUp()

        logging.getLogger('lbrynet.p2p').setLevel(self.VERBOSITY)
        logging.getLogger('lbrynet.daemon').setLevel(self.VERBOSITY)

        lbry_conf.settings = None
        lbry_conf.initialize_settings(load_conf_file=False,
                                      data_dir=self.wallet_node.data_path,
                                      wallet_dir=self.wallet_node.data_path,
                                      download_dir=self.wallet_node.data_path)
        lbry_conf.settings['use_upnp'] = False
        lbry_conf.settings['reflect_uploads'] = False
        lbry_conf.settings['blockchain_name'] = 'lbrycrd_regtest'
        lbry_conf.settings['lbryum_servers'] = [('localhost', 50001)]
        lbry_conf.settings['known_dht_nodes'] = []
        lbry_conf.settings.node_id = None

        await self.account.ensure_address_gap()
        address = (await
                   self.account.receiving.get_addresses(limit=1,
                                                        only_usable=True))[0]
        sendtxid = await self.blockchain.send_to_address(address, 10)
        await self.confirm_tx(sendtxid)
        await self.generate(5)

        def wallet_maker(component_manager):
            self.wallet_component = WalletComponent(component_manager)
            self.wallet_component.wallet_manager = self.manager
            self.wallet_component._running = True
            return self.wallet_component

        skip = [
            #UPNP_COMPONENT,
            PEER_PROTOCOL_SERVER_COMPONENT,
            REFLECTOR_COMPONENT
        ]
        analytics_manager = FakeAnalytics()
        self.daemon = Daemon(
            analytics_manager,
            ComponentManager(analytics_manager=analytics_manager,
                             skip_components=skip,
                             wallet=wallet_maker,
                             dht=FakeDHT,
                             hash_announcer=FakeHashAnnouncerComponent,
                             exchange_rate_manager=FakeExchangeRateComponent,
                             upnp=FakeUPnP))
        await d2f(self.daemon.setup())
        self.daemon.wallet_manager = self.wallet_component.wallet_manager
        self.manager.old_db = self.daemon.storage
示例#13
0
    async def asyncSetUp(self):
        await super().asyncSetUp()

        twisted.internet.reactor = sys.modules[
            'twisted.internet.reactor'] = AsyncioSelectorReactor()

        logging.getLogger('lbrynet.p2p').setLevel(self.VERBOSITY)
        logging.getLogger('lbrynet.daemon').setLevel(self.VERBOSITY)

        lbry_conf.settings = None
        lbry_conf.initialize_settings(load_conf_file=False,
                                      data_dir=self.wallet_node.data_path,
                                      wallet_dir=self.wallet_node.data_path,
                                      download_dir=self.wallet_node.data_path)
        lbry_conf.settings['use_upnp'] = False
        lbry_conf.settings['reflect_uploads'] = False
        lbry_conf.settings['blockchain_name'] = 'lbrycrd_regtest'
        lbry_conf.settings['lbryum_servers'] = [('localhost', 50001)]
        lbry_conf.settings['known_dht_nodes'] = []
        lbry_conf.settings.node_id = None

        await self.account.ensure_address_gap()
        address = (await
                   self.account.receiving.get_addresses(limit=1,
                                                        only_usable=True))[0]
        sendtxid = await self.blockchain.send_to_address(address, 10)
        await self.confirm_tx(sendtxid)
        await self.generate(5)

        def wallet_maker(component_manager):
            self.wallet_component = WalletComponent(component_manager)
            self.wallet_component.wallet_manager = self.manager
            self.wallet_component._running = True
            return self.wallet_component

        skip = [
            DHT_COMPONENT, UPNP_COMPONENT, HASH_ANNOUNCER_COMPONENT,
            PEER_PROTOCOL_SERVER_COMPONENT, REFLECTOR_COMPONENT,
            EXCHANGE_RATE_MANAGER_COMPONENT
        ]
        analytics_manager = FakeAnalytics()
        self.daemon = Daemon(
            analytics_manager,
            ComponentManager(analytics_manager=analytics_manager,
                             skip_components=skip,
                             wallet=wallet_maker))
        await self.daemon.setup()
        self.daemon.wallet_manager = self.wallet_component.wallet_manager
        self.manager.old_db = self.daemon.storage
示例#14
0
    async def asyncSetUp(self):
        await super().asyncSetUp()

        logging.getLogger('lbrynet.blob_exchange').setLevel(self.VERBOSITY)
        logging.getLogger('lbrynet.daemon').setLevel(self.VERBOSITY)

        conf = Config()
        conf.data_dir = self.wallet_node.data_path
        conf.wallet_dir = self.wallet_node.data_path
        conf.download_dir = self.wallet_node.data_path
        conf.share_usage_data = False
        conf.use_upnp = False
        conf.reflect_streams = False
        conf.blockchain_name = 'lbrycrd_regtest'
        conf.lbryum_servers = [('localhost', 50001)]
        conf.reflector_servers = []
        conf.known_dht_nodes = []

        await self.account.ensure_address_gap()
        address = (await
                   self.account.receiving.get_addresses(limit=1,
                                                        only_usable=True))[0]
        sendtxid = await self.blockchain.send_to_address(address, 10)
        await self.confirm_tx(sendtxid)
        await self.generate(5)

        def wallet_maker(component_manager):
            self.wallet_component = WalletComponent(component_manager)
            self.wallet_component.wallet_manager = self.manager
            self.wallet_component._running = True
            return self.wallet_component

        conf.components_to_skip = [
            DHT_COMPONENT, UPNP_COMPONENT, HASH_ANNOUNCER_COMPONENT,
            PEER_PROTOCOL_SERVER_COMPONENT, EXCHANGE_RATE_MANAGER_COMPONENT
        ]
        self.daemon = Daemon(
            conf,
            ComponentManager(conf,
                             skip_components=conf.components_to_skip,
                             wallet=wallet_maker))
        await self.daemon.initialize()
        self.manager.old_db = self.daemon.storage
示例#15
0
文件: testcase.py 项目: jayd2446/lbry
    async def add_daemon(self, wallet_node=None, seed=None):
        if wallet_node is None:
            wallet_node = WalletNode(self.wallet_node.manager_class,
                                     self.wallet_node.ledger_class,
                                     port=self.extra_wallet_node_port)
            self.extra_wallet_node_port += 1
            await wallet_node.start(self.conductor.spv_node, seed=seed)
            self.extra_wallet_nodes.append(wallet_node)

        conf = Config()
        conf.data_dir = wallet_node.data_path
        conf.wallet_dir = wallet_node.data_path
        conf.download_dir = wallet_node.data_path
        conf.share_usage_data = False
        conf.use_upnp = False
        conf.reflect_streams = True
        conf.blockchain_name = 'lbrycrd_regtest'
        conf.lbryum_servers = [('127.0.0.1', 50001)]
        conf.reflector_servers = [('127.0.0.1', 5566)]
        conf.known_dht_nodes = []
        conf.blob_lru_cache_size = self.blob_lru_cache_size
        conf.components_to_skip = [
            DHT_COMPONENT, UPNP_COMPONENT, HASH_ANNOUNCER_COMPONENT,
            PEER_PROTOCOL_SERVER_COMPONENT
        ]

        def wallet_maker(component_manager):
            wallet_component = WalletComponent(component_manager)
            wallet_component.wallet_manager = wallet_node.manager
            wallet_component._running = True
            return wallet_component

        daemon = Daemon(
            conf,
            ComponentManager(
                conf,
                skip_components=conf.components_to_skip,
                wallet=wallet_maker,
                exchange_rate_manager=ExchangeRateManagerComponent))
        await daemon.initialize()
        self.daemons.append(daemon)
        wallet_node.manager.old_db = daemon.storage
        return daemon
示例#16
0
    async def asyncSetUp(self):
        self.wallet_node = WalletNode(LbryWalletManager, RegTestLedger)
        await self.wallet_node.start(
            SPVNode(None),
            "carbon smart garage balance margin twelve chest sword toast envelope bottom stomach absent",
            False)
        self.account = self.wallet_node.account

        conf = Config()
        conf.data_dir = self.wallet_node.data_path
        conf.wallet_dir = self.wallet_node.data_path
        conf.download_dir = self.wallet_node.data_path
        conf.share_usage_data = False
        conf.use_upnp = False
        conf.reflect_streams = False
        conf.blockchain_name = 'lbrycrd_regtest'
        conf.lbryum_servers = [('localhost', 50001)]
        conf.reflector_servers = []
        conf.known_dht_nodes = []

        def wallet_maker(component_manager):
            self.wallet_component = WalletComponent(component_manager)
            self.wallet_component.wallet_manager = self.wallet_node.manager
            self.wallet_component._running = True
            return self.wallet_component

        conf.components_to_skip = [
            DHT_COMPONENT, UPNP_COMPONENT, HASH_ANNOUNCER_COMPONENT,
            PEER_PROTOCOL_SERVER_COMPONENT, EXCHANGE_RATE_MANAGER_COMPONENT
        ]
        self.daemon = Daemon(
            conf,
            ComponentManager(conf,
                             skip_components=conf.components_to_skip,
                             wallet=wallet_maker))
        await self.daemon.initialize()
示例#17
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)
示例#18
0
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)
示例#19
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)