Esempio n. 1
0
async def test_required_dependency_missed(tribler_config):
    class ComponentA(Component):
        pass

    class ComponentB(Component):
        async def run(self):
            await self.require_component(ComponentA)

    session = Session(tribler_config, [ComponentB()])
    with session:
        assert ComponentA.instance() is None
        b = ComponentB.instance()

        with pytest.raises(
                MissedDependency,
                match=
                '^Missed dependency: ComponentB requires ComponentA to be active$'
        ):
            await session.start_components()

    session = Session(tribler_config, [ComponentB()], failfast=False)
    with session:
        b = ComponentB.instance()

        await session.start_components()

        assert ComponentB.instance() is b
        assert b.started_event.is_set()
        assert b.failed
async def test_gigachannel_manager_component(tribler_config):
    components = [Ipv8Component(), TagComponent(), SocksServersComponent(), KeyComponent(), MetadataStoreComponent(),
                  LibtorrentComponent(), GigachannelManagerComponent()]
    async with Session(tribler_config, components).start():
        comp = GigachannelManagerComponent.instance()
        assert comp.started_event.is_set() and not comp.failed
        assert comp.gigachannel_manager
Esempio n. 3
0
async def test_tunnels_component(tribler_config):
    components = [Ipv8Component(), KeyComponent(), TunnelsComponent()]
    async with Session(tribler_config, components).start():
        comp = TunnelsComponent.instance()
        assert comp.started_event.is_set() and not comp.failed
        assert comp.community
        assert comp._ipv8_component
async def test_popularity_component(tribler_config):
    components = [SocksServersComponent(), LibtorrentComponent(), TorrentCheckerComponent(), TagComponent(),
                  MetadataStoreComponent(), KeyComponent(), Ipv8Component(), PopularityComponent()]
    async with Session(tribler_config, components).start():
        comp = PopularityComponent.instance()
        assert comp.community
        assert comp._ipv8_component
Esempio n. 5
0
async def test_component_shutdown_failure(tribler_config):
    class ComponentA(Component):
        pass

    class ComponentB(Component):
        async def run(self):
            await self.require_component(ComponentA)

        async def shutdown(self):
            raise ComponentTestException

    session = Session(tribler_config, [ComponentA(), ComponentB()])
    with session:
        a = ComponentA.instance()
        b = ComponentB.instance()

        await session.start_components()

        assert not a.unused_event.is_set()

        with pytest.raises(ComponentTestException):
            await session.shutdown()

        for component in a, b:
            assert not component.dependencies
            assert not component.reverse_dependencies
            assert component.unused_event.is_set()
            assert component.stopped
Esempio n. 6
0
async def test_required_dependency(tribler_config):
    class ComponentA(Component):
        pass

    class ComponentB(Component):
        async def run(self):
            await self.require_component(ComponentA)

    session = Session(tribler_config, [ComponentA(), ComponentB()])
    with session:
        a = ComponentA.instance()
        b = ComponentB.instance()

        for component in a, b:
            assert not component.dependencies and not component.reverse_dependencies
            assert component.unused_event.is_set()

        await session.start_components()

        assert a in b.dependencies and not b.reverse_dependencies
        assert not a.dependencies and b in a.reverse_dependencies
        assert b.unused_event.is_set() and not a.unused_event.is_set()

        session.shutdown_event.set()
        await session.shutdown()

        for component in a, b:
            assert not component.dependencies and not component.reverse_dependencies
            assert component.unused_event.is_set()
Esempio n. 7
0
async def test_ipv8_component_dht_disabled(tribler_config):
    tribler_config.ipv8.enabled = True
    tribler_config.dht.enabled = True
    async with Session(tribler_config,
                       [KeyComponent(), Ipv8Component()]).start():
        comp = Ipv8Component.instance()
        assert comp.dht_discovery_community
async def test_socks_servers_component(tribler_config):
    components = [SocksServersComponent()]
    async with Session(tribler_config, components).start():
        comp = SocksServersComponent.instance()
        assert comp.started_event.is_set() and not comp.failed
        assert comp.socks_ports
        assert comp.socks_servers
Esempio n. 9
0
async def core_session(config: TriblerConfig, components: List[Component]):
    session = Session(config, components, failfast=False)
    signal.signal(signal.SIGTERM,
                  lambda signum, stack: session.shutdown_event.set)
    async with session.start() as session:
        # If there is a config error, report to the user via GUI notifier
        if config.error:
            session.notifier[notifications.report_config_error](config.error)

        # SHUTDOWN
        await session.shutdown_event.wait()

        if not config.gui_test_mode:
            session.notifier[notifications.tribler_shutdown_state](
                "Saving configuration...")
            config.write()
Esempio n. 10
0
async def test_rest_component(tribler_config):
    components = [
        KeyComponent(),
        RESTComponent(),
        Ipv8Component(),
        LibtorrentComponent(),
        ResourceMonitorComponent(),
        BandwidthAccountingComponent(),
        GigaChannelComponent(),
        TagComponent(),
        SocksServersComponent(),
        MetadataStoreComponent()
    ]
    async with Session(tribler_config, components).start():
        # Test REST component starts normally
        comp = RESTComponent.instance()
        assert comp.started_event.is_set() and not comp.failed
        assert comp.rest_manager

        # Test report callback works
        # mock callbacks
        comp._events_endpoint.on_tribler_exception = MagicMock()

        # try to call report_callback from core_exception_handler and assert
        # that corresponding methods in events_endpoint and state_endpoint have been called
        error = ReportedError(type='', text='text', event={})
        comp._core_exception_handler.report_callback(error)
        comp._events_endpoint.on_tribler_exception.assert_called_with(error)
Esempio n. 11
0
async def test_ipv8_component_discovery_community_enabled(tribler_config):
    tribler_config.ipv8.enabled = True
    tribler_config.gui_test_mode = False
    tribler_config.discovery_community.enabled = True
    async with Session(tribler_config,
                       [KeyComponent(), Ipv8Component()]).start():
        comp = Ipv8Component.instance()
        assert comp._peer_discovery_community
Esempio n. 12
0
async def core_session(config: TriblerConfig, components: List[Component]):
    session = Session(config, components, failfast=False)
    signal.signal(signal.SIGTERM, lambda signum, stack: session.shutdown_event.set)
    session.set_as_default()

    await session.start()

    # If there is a config error, report to the user via GUI notifier
    if config.error:
        session.notifier.notify(NTFY.REPORT_CONFIG_ERROR.value, config.error)

    # SHUTDOWN
    await session.shutdown_event.wait()
    await session.shutdown()

    if not config.gui_test_mode:
        session.notifier.notify(NTFY.TRIBLER_SHUTDOWN_STATE.value, "Saving configuration...")
        config.write()
Esempio n. 13
0
async def test_masterkey_component(tribler_config):
    session = Session(tribler_config, [KeyComponent()])
    with session:
        comp = KeyComponent.instance()
        await session.start()

        assert comp.primary_key

        await session.shutdown()
Esempio n. 14
0
async def test_ipv8_component(tribler_config):
    async with Session(tribler_config,
                       [KeyComponent(), Ipv8Component()]).start():
        comp = Ipv8Component.instance()
        assert comp.started_event.is_set() and not comp.failed
        assert comp.ipv8
        assert comp.peer
        assert not comp.dht_discovery_community
        assert comp._task_manager
        assert not comp._peer_discovery_community
Esempio n. 15
0
async def test_reporter_component(tribler_config):
    components = [KeyComponent(), ReporterComponent()]
    session = Session(tribler_config, components)
    with session:
        await session.start()

        comp = ReporterComponent.instance()
        assert comp.started_event.is_set() and not comp.failed

        await session.shutdown()
async def test_bandwidth_accounting_component(tribler_config):
    components = [
        KeyComponent(),
        Ipv8Component(),
        BandwidthAccountingComponent()
    ]
    async with Session(tribler_config, components).start():
        comp = BandwidthAccountingComponent.instance()
        assert comp.started_event.is_set() and not comp.failed
        assert comp.community
        assert comp._ipv8_component
async def test_watch_folder_component(tribler_config):
    components = [
        KeyComponent(),
        SocksServersComponent(),
        LibtorrentComponent(),
        WatchFolderComponent()
    ]
    async with Session(tribler_config, components).start():
        comp = WatchFolderComponent.instance()
        assert comp.started_event.is_set() and not comp.failed
        assert comp.watch_folder
Esempio n. 18
0
async def test_payout_component(tribler_config):
    components = [
        BandwidthAccountingComponent(),
        KeyComponent(),
        Ipv8Component(),
        PayoutComponent()
    ]
    async with Session(tribler_config, components).start():
        comp = PayoutComponent.instance()
        assert comp.started_event.is_set() and not comp.failed
        assert comp.payout_manager
Esempio n. 19
0
async def test_metadata_store_component(tribler_config):
    components = [
        TagComponent(),
        Ipv8Component(),
        KeyComponent(),
        MetadataStoreComponent()
    ]
    async with Session(tribler_config, components).start():
        comp = MetadataStoreComponent.instance()
        assert comp.started_event.is_set() and not comp.failed
        assert comp.mds
async def test_version_check_component(tribler_config):
    components = [VersionCheckComponent()]
    session = Session(tribler_config, components)
    with session:
        await session.start()

        comp = VersionCheckComponent.instance()
        assert comp.started_event.is_set() and not comp.failed
        assert comp.version_check_manager

        await session.shutdown()
Esempio n. 21
0
async def test_tunnels_component(tribler_config):
    components = [Ipv8Component(), KeyComponent(), TunnelsComponent()]
    session = Session(tribler_config, components)
    with session:
        await session.start()

        comp = TunnelsComponent.instance()
        assert comp.started_event.is_set() and not comp.failed
        assert comp.community
        assert comp._ipv8_component

        await session.shutdown()
Esempio n. 22
0
async def test_socks_servers_component(tribler_config):
    components = [SocksServersComponent()]
    session = Session(tribler_config, components)
    with session:
        await session.start()

        comp = SocksServersComponent.instance()
        assert comp.started_event.is_set() and not comp.failed
        assert comp.socks_ports
        assert comp.socks_servers

        await session.shutdown()
Esempio n. 23
0
async def test_tag_component(tribler_config):
    session = Session(
        tribler_config,
        [KeyComponent(), Ipv8Component(),
         TagComponent()])
    with session:
        comp = TagComponent.instance()
        await session.start()

        assert comp.started_event.is_set() and not comp.failed
        assert comp.community

        await session.shutdown()
Esempio n. 24
0
async def test_torrent_checker_component(tribler_config):
    components = [
        SocksServersComponent(),
        LibtorrentComponent(),
        KeyComponent(),
        Ipv8Component(),
        TagComponent(),
        MetadataStoreComponent(),
        TorrentCheckerComponent()
    ]
    async with Session(tribler_config, components).start():
        comp = TorrentCheckerComponent.instance()
        assert comp.started_event.is_set() and not comp.failed
        assert comp.torrent_checker
Esempio n. 25
0
async def test_libtorrent_component(tribler_config):
    components = [
        KeyComponent(),
        SocksServersComponent(),
        LibtorrentComponent()
    ]
    session = Session(tribler_config, components)
    with session:
        await session.start()

        comp = LibtorrentComponent.instance()
        assert comp.started_event.is_set() and not comp.failed
        assert comp.download_manager

        await session.shutdown()
Esempio n. 26
0
async def test_giga_channel_component(tribler_config):
    tribler_config.ipv8.enabled = True
    tribler_config.libtorrent.enabled = True
    tribler_config.chant.enabled = True
    components = [TagComponent(), MetadataStoreComponent(), KeyComponent(), Ipv8Component(), GigaChannelComponent()]
    session = Session(tribler_config, components)
    with session:
        await session.start()

        comp = GigaChannelComponent.instance()
        assert comp.started_event.is_set() and not comp.failed
        assert comp.community
        assert comp._ipv8_component

        await session.shutdown()
async def test_metadata_store_component(tribler_config):
    components = [
        TagComponent(),
        Ipv8Component(),
        KeyComponent(),
        MetadataStoreComponent()
    ]
    session = Session(tribler_config, components)
    with session:
        comp = MetadataStoreComponent.instance()
        await session.start()

        assert comp.started_event.is_set() and not comp.failed
        assert comp.mds

        await session.shutdown()
Esempio n. 28
0
async def test_payout_component(tribler_config):
    components = [
        BandwidthAccountingComponent(),
        KeyComponent(),
        Ipv8Component(),
        PayoutComponent()
    ]
    session = Session(tribler_config, components)
    with session:
        await session.start()

        comp = PayoutComponent.instance()
        assert comp.started_event.is_set() and not comp.failed
        assert comp.payout_manager

        await session.shutdown()
Esempio n. 29
0
async def test_session_start_shutdown(tribler_config):
    class TestComponent(Component):
        def __init__(self):
            self.run_was_executed = self.shutdown_was_executed = False
            super().__init__()

        async def run(self):
            self.run_was_executed = True

        async def shutdown(self):
            self.shutdown_was_executed = True

    class ComponentA(TestComponent):
        pass

    class ComponentB(TestComponent):
        pass

    session = Session(tribler_config, [ComponentA(), ComponentB()])
    with session:
        a = ComponentA.instance()
        b = ComponentB.instance()

        for component in a, b:
            assert not component.run_was_executed
            assert not component.started_event.is_set()
            assert not component.shutdown_was_executed
            assert not component.stopped

        await session.start_components()

        assert ComponentA.instance() is a and ComponentB.instance() is b
        for component in a, b:
            assert component.run_was_executed
            assert component.started_event.is_set()
            assert not component.shutdown_was_executed
            assert not component.stopped

        session.shutdown_event.set()
        await session.shutdown()

        assert ComponentA.instance() is a and ComponentB.instance() is b
        for component in a, b:
            assert component.run_was_executed
            assert component.started_event.is_set()
            assert component.shutdown_was_executed
            assert component.stopped
Esempio n. 30
0
async def test_maybe_component(loop, tribler_config):  # pylint: disable=unused-argument
    class ComponentA(Component):
        pass

    class ComponentB(Component):
        pass

    session = Session(tribler_config, [ComponentA()])
    with session:
        await session.start_components()
        component_a = await ComponentA.instance().maybe_component(ComponentA)
        component_b = await ComponentA.instance().maybe_component(ComponentB)

        assert isinstance(component_a, ComponentA)
        assert isinstance(component_b, NoneComponent)
        assert isinstance(component_b.any_attribute, NoneComponent)
        assert isinstance(component_b.any_attribute.any_nested_attribute,
                          NoneComponent)