Пример #1
0
    def test_logging(self):
        self.session.open_dbhandler = lambda _: None

        infohash_1 = "a" * 20
        infohash_2 = "b" * 20
        torrents = {
            infohash_1: {
                "last_seeding_stats": {
                    "time_seeding": 100,
                    "value": 5
                }
            },
            infohash_2: {
                "last_seeding_stats": {}
            }
        }
        self.session.lm.ltmgr = MockLtSession()

        boost_man = bm.BoostingManager(self.session, self.bsettings)
        boost_man.torrents = torrents

        boost_man.session.lm.ltmgr.get_session().get_torrents = \
            lambda: [MockLtTorrent(binascii.hexlify(infohash_1)),
                     MockLtTorrent(binascii.hexlify(infohash_2))]

        boost_man.log_statistics()
        boost_man.cancel_all_pending_tasks()
Пример #2
0
    def test_load_default(self):
        """
        Test load default configuration in BoostingManager
        """
        self.bsettings.load_config = True
        self.bsettings.auto_start_source = False
        self.bsettings.initial_swarm_interval = 9000
        self.bsettings.initial_tracker_interval = 9000
        self.bsettings.initial_logging_interval = 9000
        self.session.open_dbhandler = lambda _: None
        self.session.lm.ltmgr = MockLtSession()

        # it will automatically load the default configuration
        boost_man = bm.BoostingManager(self.session, self.bsettings)

        # def validate(d_defer):
        self.assertEqual(
            self.session.config.get_credit_mining_source_interval(),
            boost_man.settings.source_interval)
        self.assertEqual(
            self.session.config.get_credit_mining_archive_sources(), [
                source_to_string(src.source)
                for src in boost_man.boosting_sources.values() if src.archive
            ])

        boost_man.cancel_all_pending_tasks()
Пример #3
0
    def setUp(self, autoload_discovery=True):
        yield super(TestBoostingManagerError, self).setUp()

        self.session.open_dbhandler = lambda _: True
        self.session.get_libtorrent = lambda: True
        self.session.lm.ltmgr = MockLtSession()

        self.boost_setting = bm.BoostingSettings(self.session)
        self.boost_setting.load_config = False
        self.boost_setting.initial_logging_interval = 900
        self.boost_setting.check_dependencies = False
        self.boosting_manager = bm.BoostingManager(self.session,
                                                   self.boost_setting)
        self.session.lm.boosting_manager = self.boosting_manager
Пример #4
0
    def __init__(self, *argv, **kwargs):
        super(TestBoostingManagerUtilities, self).__init__(*argv, **kwargs)

        self.peer = [None] * 6
        self.peer[0] = MockLtPeer(MockPeerId("1"), "ip1")
        self.peer[0].setvalue(True, True, True)
        self.peer[1] = MockLtPeer(MockPeerId("2"), "ip2")
        self.peer[1].setvalue(False, False, True)
        self.peer[2] = MockLtPeer(MockPeerId("3"), "ip3")
        self.peer[2].setvalue(True, False, True)
        self.peer[3] = MockLtPeer(MockPeerId("4"), "ip4")
        self.peer[3].setvalue(False, True, False)
        self.peer[4] = MockLtPeer(MockPeerId("5"), "ip5")
        self.peer[4].setvalue(False, True, True)
        self.peer[5] = MockLtPeer(MockPeerId("6"), "ip6")
        self.peer[5].setvalue(False, False, False)

        self.session = MockLtSession()
Пример #5
0
    def test_boosting_dependencies(self):
        """
        Test whether boosting manager dependencies works or not.

        In all test, check dependencies always off. In production, it is on by default.
        """
        self.bsettings.check_dependencies = True
        self.bsettings.initial_swarm_interval = 9000
        self.bsettings.initial_tracker_interval = 9000
        self.bsettings.initial_logging_interval = 9000
        self.session.open_dbhandler = lambda _: None
        self.session.lm.ltmgr = MockLtSession()

        self.session.config.get_torrent_checking_enabled = lambda: True
        self.session.config.get_dispersy_enabled = lambda: True
        self.session.config.get_torrent_store_enabled = lambda: True
        self.session.config.get_torrent_search_enabled = lambda: True
        self.session.config.get_channel_search_enabled = lambda: True
        self.session.get_megacache_enabled = lambda: False

        self.assertRaises(AssertionError, bm.BoostingManager, self.session,
                          self.bsettings)
Пример #6
0
    def test_update_statistics(self):
        """
        test updating statistics of a torrent (pick a new one)
        """
        self.session.open_dbhandler = lambda _: None

        infohash_1 = "a" * 20
        infohash_2 = "b" * 20
        torrents = {
            infohash_1: {
                "last_seeding_stats": {
                    "time_seeding": 100,
                    "value": 5
                }
            },
            infohash_2: {
                "last_seeding_stats": {}
            }
        }

        new_seeding_stats = {"time_seeding": 110, "value": 1}
        new_seeding_stats_unexist = {"time_seeding": 10, "value": 8}

        self.session.lm.ltmgr = MockLtSession()

        boost_man = bm.BoostingManager(self.session, self.bsettings)
        boost_man.torrents = torrents

        boost_man.update_torrent_stats(infohash_1, new_seeding_stats)
        self.assertEqual(
            boost_man.torrents[infohash_1]['last_seeding_stats']['value'], 1)

        boost_man.update_torrent_stats(infohash_2, new_seeding_stats_unexist)
        self.assertEqual(
            boost_man.torrents[infohash_2]['last_seeding_stats']['value'], 8)

        boost_man.cancel_all_pending_tasks()
Пример #7
0
 def __init__(self, *argv, **kwargs):
     super(TestBoostingManagerError, self).__init__(*argv, **kwargs)
     self.session = MockLtSession()