Exemplo n.º 1
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)
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
Exemplo 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
Exemplo n.º 4
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()

        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
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
Exemplo n.º 6
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
Exemplo n.º 7
0
async def test_ipv8_component_dht_disabled(tribler_config):
    tribler_config.ipv8.enabled = True
    tribler_config.dht.enabled = True
    session = Session(tribler_config, [KeyComponent(), Ipv8Component()])
    with session:
        await session.start()

        comp = Ipv8Component.instance()
        assert comp.dht_discovery_community
Exemplo n.º 8
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()
Exemplo n.º 9
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()
Exemplo n.º 10
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
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
Exemplo n.º 12
0
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()
Exemplo n.º 13
0
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
Exemplo n.º 14
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
Exemplo n.º 15
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
Exemplo n.º 16
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()
Exemplo n.º 17
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()
Exemplo n.º 18
0
def test_session_context_manager(loop, tribler_config):  # pylint: disable=unused-argument
    session1 = Session(tribler_config, [])
    session2 = Session(tribler_config, [])
    session3 = Session(tribler_config, [])

    with pytest.raises(SessionError, match="Default session was not set"):
        Session.current()

    session1.set_as_default()
    assert Session.current() is session1

    with session2:
        assert Session.current() is session2
        with session3:
            assert Session.current() is session3
        assert Session.current() is session2
    assert Session.current() is session1

    Session.unset_default_session()

    with pytest.raises(SessionError, match="Default session was not set"):
        Session.current()
Exemplo n.º 19
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()
Exemplo n.º 20
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
Exemplo n.º 21
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()
Exemplo n.º 22
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()
Exemplo n.º 23
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()
Exemplo n.º 24
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()
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()
Exemplo n.º 26
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
Exemplo n.º 27
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()
Exemplo n.º 28
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)
Exemplo n.º 29
0
    async def start(self, options):
        config = make_config(options)
        components = list(components_gen())
        session = self.session = Session(config, components)
        session.set_as_default()

        self.log_circuits = options.log_circuits
        session.notifier.add_observer(NTFY.TUNNEL_REMOVE, self.circuit_removed)

        await session.start()

        with session:
            if options.log_rejects:
                tunnels_component = TunnelsComponent.instance()
                tunnels_community = tunnels_component.community
                # We set this after Tribler has started since the tunnel_community won't be available otherwise
                tunnels_community.reject_callback = self.on_circuit_reject

        self.tribler_started()
Exemplo n.º 30
0
async def test_popularity_component(tribler_config):
    components = [
        SocksServersComponent(),
        LibtorrentComponent(),
        TorrentCheckerComponent(),
        TagComponent(),
        MetadataStoreComponent(),
        KeyComponent(),
        Ipv8Component(),
        PopularityComponent()
    ]
    session = Session(tribler_config, components)
    with session:
        await session.start()

        comp = PopularityComponent.instance()
        assert comp.community
        assert comp._ipv8_component

        await session.shutdown()