Skip to content

Commit

Permalink
Merge pull request #7742 from drew2a/fix/7739
Browse files Browse the repository at this point in the history
Remove channels from the Application Tester
  • Loading branch information
drew2a committed Dec 1, 2023
2 parents 1ad4614 + 6d55521 commit 6f554e4
Show file tree
Hide file tree
Showing 18 changed files with 63 additions and 236 deletions.
13 changes: 8 additions & 5 deletions scripts/application_tester/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import asyncio
import os
from asyncio import ensure_future, get_event_loop
from pathlib import Path

import sentry_sdk

Expand All @@ -20,12 +19,16 @@
parser = argparse.ArgumentParser(description='Run a Tribler application test.')
parser.add_argument('tribler_executable', metavar='path', type=str, help='the full path to the Tribler executable')
parser.add_argument('-p', '--plain', action='store_true', help='allow plain downloads')
parser.add_argument('-d', '--duration', default=None, type=int, help='run the Tribler application tester for a specific period of time')
parser.add_argument('-d', '--duration', default=None, type=int,
help='run the Tribler application tester for a specific period of time')
parser.add_argument('-s', '--silent', action='store_true', help='do not execute random actions')
parser.add_argument('--codeport', default=5500, type=int, help='the port used to execute code')
parser.add_argument('--monitordownloads', default=None, type=int, help='monitor the downloads with a specified interval in seconds')
parser.add_argument('--monitorresources', default=None, type=int, help='monitor the resources with a specified interval in seconds')
parser.add_argument('--monitoripv8', default=None, type=int, help='monitor IPv8 overlays with a specified interval in seconds')
parser.add_argument('--monitordownloads', default=None, type=int,
help='monitor the downloads with a specified interval in seconds')
parser.add_argument('--monitorresources', default=None, type=int,
help='monitor the resources with a specified interval in seconds')
parser.add_argument('--monitoripv8', default=None, type=int,
help='monitor IPv8 overlays with a specified interval in seconds')
parser.add_argument('--fragile', '-f', help='Fail at the first error', action='store_true')

init_logger()
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,9 @@ class PageAction(ClickSequenceAction):
This action goes to a specific page in Tribler.
"""
BUTTONS_TO_PAGES = {
'discovered': ['window.left_menu_button_discovered'],
'downloads': ['window.left_menu_button_downloads'],
'search': [],
'token_balance': ['window.token_balance_widget'],
'settings': ['window.settings_button'],
'market': [],
}

def __init__(self, page_name):
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,6 @@ enabled = boolean(default=True)
max_download_rate = integer(min=1, default=1000000)
infohash = string(default='b496932f32daad964e1b63188faabf74d22b45ea')

[chant]
enabled = boolean(default=True)
manager_enabled = boolean(default=True)
channel_edit = boolean(default=False)
channels_dir = string(default='channels')
testnet = boolean(default=False)

[torrent_checking]
enabled = boolean(default=True)

Expand Down Expand Up @@ -67,8 +60,6 @@ saveas = string(default=None)
seeding_mode = option('forever', 'never', 'ratio', 'time', default='forever')
seeding_ratio = float(default=2.0)
seeding_time = float(default=60)
channel_download = boolean(default=False)
add_download_to_channel = boolean(default=False)

[ipv8]
enabled = boolean(default=True)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ search=15
start_download=15
remove_download=5
explore_download=10
scroll_discovered=5
explore_channel=10
change_anonymity=5
subscribe_unsubscribe=10
screenshot=5
change_download_files=10
60 changes: 13 additions & 47 deletions scripts/application_tester/tribler_apptester/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,14 @@
from tribler.core.config.tribler_config import TriblerConfig
from tribler_apptester.actions.change_anonymity_action import ChangeAnonymityAction
from tribler_apptester.actions.change_download_files_action import ChangeDownloadFilesAction
from tribler_apptester.actions.explore_channel_action import ExploreChannelAction
from tribler_apptester.actions.explore_download_action import ExploreDownloadAction
from tribler_apptester.actions.manage_channel_action import ManageChannelAction
from tribler_apptester.actions.page_action import RandomPageAction
from tribler_apptester.actions.remove_download_action import RemoveRandomDownloadAction
from tribler_apptester.actions.screenshot_action import ScreenshotAction
from tribler_apptester.actions.scroll_discovered_action import ScrollDiscoveredAction
from tribler_apptester.actions.search_action import RandomSearchAction
from tribler_apptester.actions.shutdown_action import ShutdownAction
from tribler_apptester.actions.start_download_action import StartRandomDownloadAction
from tribler_apptester.actions.start_vod_action import StartVODAction
from tribler_apptester.actions.subscribe_unsubscribe_action import SubscribeUnsubscribeAction
from tribler_apptester.actions.test_exception import TestExceptionAction
from tribler_apptester.actions.wait_action import WaitAction
from tribler_apptester.monitors.download_monitor import DownloadMonitor
Expand Down Expand Up @@ -415,50 +411,20 @@ def get_random_action(self):
There are various actions possible that can occur with different probabilities.
"""
action_name = self.weighted_choice(self.probabilities)
if not action_name:
self._logger.warning("No action available!")
return WaitAction(1000)

self._logger.info("Random action: %s", action_name)
try:
action = None
if action_name == 'test_exception':
action = TestExceptionAction()
elif action_name == 'random_page':
action = RandomPageAction()
elif action_name == 'search':
action = RandomSearchAction()
elif action_name == 'start_download':
torrent_links = Path(__file__).parent / "data/torrent_links.txt"
action = StartRandomDownloadAction(torrent_links)
elif action_name == 'remove_download':
action = RemoveRandomDownloadAction()
elif action_name == 'explore_download':
action = ExploreDownloadAction()
elif action_name == 'scroll_discovered':
action = ScrollDiscoveredAction()
elif action_name == 'explore_channel':
action = ExploreChannelAction()
elif action_name == 'screenshot':
action = ScreenshotAction()
elif action_name == 'start_vod':
action = StartVODAction()
elif action_name == 'change_anonymity':
action = ChangeAnonymityAction(allow_plain=self.allow_plain_downloads)
elif action_name == 'subscribe_unsubscribe':
action = SubscribeUnsubscribeAction()
elif action_name == 'change_download_files':
action = ChangeDownloadFilesAction()
elif action_name == 'manage_channel':
action = ManageChannelAction()
except Exception as e:
self._logger.exception(e)
return

if not action:
self._logger.error("Action %s does not exist", action)
action = WaitAction(1000)
return action
actions = {
'test_exception': TestExceptionAction(),
'random_page': RandomPageAction(),
'search': RandomSearchAction(),
'start_download': StartRandomDownloadAction(Path(__file__).parent / "data/torrent_links.txt"),
'remove_download': RemoveRandomDownloadAction(),
'explore_download': ExploreDownloadAction(),
'screenshot': ScreenshotAction(),
'start_vod': StartVODAction(),
'change_anonymity': ChangeAnonymityAction(allow_plain=self.allow_plain_downloads),
'change_download_files': ChangeDownloadFilesAction()
}
return actions.get(action_name)

async def perform_random_action(self):
action = self.get_random_action()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,16 @@

import colorlog

log_colors = {
'DEBUG': 'white',
'INFO': 'white',
}


def init_logger():
logging_level = os.environ.get('APPTESTER_LOGGING_LEVEL', 'INFO')

handler = colorlog.StreamHandler()
handler.setFormatter(colorlog.ColoredFormatter('%(log_color)s%(levelname)s - %(name)s(%(lineno)d): %(message)s'))
handler.setFormatter(colorlog.ColoredFormatter('%(log_color)s%(levelname)s - %(name)s(%(lineno)d): %(message)s',
log_colors=log_colors))
logging.basicConfig(level=logging_level, handlers=[handler])
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import base64
import itertools
import logging
from asyncio import CancelledError, Future, iscoroutine, sleep, wait_for, get_running_loop
from asyncio import CancelledError, Future, get_running_loop, iscoroutine, sleep, wait_for
from collections import defaultdict
from contextlib import suppress
from enum import Enum
Expand Down Expand Up @@ -451,8 +451,7 @@ def on_torrent_finished_alert(self, alert: lt.torrent_finished_alert):
if downloaded > 0 and self.stream is not None and self.notifier is not None:
name = self.tdef.get_name_as_unicode()
infohash = self.tdef.get_infohash().hex()
hidden = self.hidden or self.config.get_channel_download()
self.notifier[notifications.torrent_finished](infohash=infohash, name=name, hidden=hidden)
self.notifier[notifications.torrent_finished](infohash=infohash, name=name, hidden=self.hidden)

def update_lt_status(self, lt_status: lt.torrent_status):
""" Update libtorrent stats and check if the download should be stopped."""
Expand Down Expand Up @@ -855,7 +854,7 @@ def get_file_completion(self, path: Path) -> float:
total += 1
if total == 0:
return 1.0
return have/total
return have / total

def get_file_length(self, path: Path) -> int:
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,18 +141,6 @@ def get_selected_files(self):
@return A list of file indexes. """
return self.config['download_defaults']['selected_file_indexes']

def set_channel_download(self, value):
self.config['download_defaults']['channel_download'] = value

def get_channel_download(self):
return bool(self.config['download_defaults']['channel_download'])

def set_add_to_channel(self, value):
self.config['download_defaults']['add_to_channel'] = value

def get_add_to_channel(self):
return bool(self.config['download_defaults']['add_to_channel'])

def set_bootstrap_download(self, value):
self.config['download_defaults']['bootstrap_download'] = value

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -745,9 +745,6 @@ def get_download(self, infohash: bytes) -> Download:
def get_downloads(self) -> List[Download]:
return list(self.downloads.values())

def get_channel_downloads(self):
return [download for download in self.downloads.values() if download.config.get_channel_download()]

def download_exists(self, infohash):
return infohash in self.downloads

Expand Down Expand Up @@ -944,8 +941,8 @@ async def create_torrent_file(file_path_list, params=None):
return await asyncio.get_event_loop().run_in_executor(None, torrent_utils.create_torrent_file,
file_path_list, params or {})

def get_downloads_by_name(self, torrent_name, channels_only=False):
downloads = (self.get_channel_downloads() if channels_only else self.get_downloads())
def get_downloads_by_name(self, torrent_name):
downloads = self.get_downloads()
return [d for d in downloads if d.get_def().get_name_utf8() == torrent_name]

@staticmethod
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,7 @@ async def get_downloads(self, request):
downloads_json = []
downloads = self.download_manager.get_downloads()
for download in downloads:
if download.hidden and not download.config.get_channel_download():
# We still want to send channel downloads since they are displayed in the GUI
if download.hidden:
continue
state = download.get_state()
tdef = download.get_def()
Expand All @@ -306,10 +305,7 @@ async def get_downloads(self, request):
num_seeds, num_peers = state.get_num_seeds_peers()
num_connected_seeds, num_connected_peers = download.get_num_connected_seeds_peers()

if download.config.get_channel_download():
download_name = self.mds.ChannelMetadata.get_channel_name_cached(
tdef.get_name_utf8(), tdef.get_infohash())
elif self.mds is None:
if self.mds is None:
download_name = tdef.get_name_utf8()
else:
download_name = self.mds.TorrentMetadata.get_torrent_title(tdef.get_infohash()) or \
Expand Down Expand Up @@ -347,8 +343,7 @@ async def get_downloads(self, request):
"total_pieces": tdef.get_nr_pieces(),
"vod_mode": download.stream and download.stream.enabled,
"error": repr(state.get_error()) if state.get_error() else "",
"time_added": download.config.get_time_added(),
"channel_download": download.config.get_channel_download()
"time_added": download.config.get_time_added()
}
if download.stream:
download_json.update({
Expand Down

0 comments on commit 6f554e4

Please sign in to comment.