Skip to content

Commit

Permalink
Merge pull request #7105 from drew2a/feature/7093
Browse files Browse the repository at this point in the history
Add `scripttest.yml`
  • Loading branch information
drew2a authored Oct 26, 2022
2 parents 6c4b084 + 866df5a commit bdf1121
Show file tree
Hide file tree
Showing 16 changed files with 224 additions and 78 deletions.
18 changes: 3 additions & 15 deletions .github/actions/pyenv/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@ inputs:
description: 'Requirements-files to use for building the cache key'
required: false

invalidate-cache:
default: 'false'
description: 'Force create a virtualenv'
required: false

outputs:
virtualenv-directory:
description: 'The path to the restored or created virtualenv'
Expand All @@ -34,21 +29,14 @@ runs:
python-version: ${{inputs.python-version}}

- name: Restore virtual env
uses: drew2a/restore-virtualenv@v1.2.1
uses: syphar/restore-virtualenv@v1
id: cache-virtualenv
with:
requirement_files: ${{inputs.requirements-key}}
custom_cache_key_element: ${{github.ref_name}}

- name: Invalidate cache
if: inputs.invalidate-cache == 'true'
shell: bash
run: |
rm -rf ${{steps.cache-virtualenv.outputs.virtualenv-directory}}
python -m venv ${{steps.cache-virtualenv.outputs.virtualenv-directory}}
custom_cache_key_element: ${{github.ref_name}}:${{inputs.requirements}}

- name: Install pip dependencies
if: steps.cache-virtualenv.outputs.cache-hit != 'true' || inputs.invalidate-cache == 'true'
if: steps.cache-virtualenv.outputs.cache-hit != 'true'
shell: bash
run: |
python -m pip install --upgrade pip
Expand Down
23 changes: 23 additions & 0 deletions .github/actions/timeout/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: timeout
description: Start COMMAND, and kill it if still running after DURATION
inputs:
command:
default: 'echo command is not specified'
description: 'A command to run under given timeout'
required: true

duration:
default: '10s'
description: 'A duration for command to run'
required: false

runs:
using: 'composite'
steps:
- name: Run Scripts
shell: bash
run: |
timeout --foreground -s SIGKILL ${{inputs.duration}} ${{inputs.command}} || code=$?; if [[ $code -ne 124 && $code -ne 0 ]]; then exit $code; fi
# codes:
# * 124 (timeout)
# * 0 (success)
5 changes: 5 additions & 0 deletions .github/workflows/!PR.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ jobs:
with:
python-version: 3.8

scripttest:
uses: ./.github/workflows/scripttest.yml
with:
python-version: 3.8

guitest:
uses: ./.github/workflows/guitest.yml
with:
Expand Down
84 changes: 84 additions & 0 deletions .github/workflows/scripttest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
name: Scripts Test

on:
workflow_call:
inputs:
python-version:
default: 3.8
type: string
required: false

duration:
default: 10s
type: string
required: false

jobs:
run:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Create python environment
uses: ./.github/actions/pyenv
with:
python-version: ${{inputs.python-version}}
requirements: requirements-core.txt

- name: Set PYTHONPATH
run: |
echo "PYTHONPATH=${PYTHONPATH}:./src" >> $GITHUB_ENV
- name: run_bandwidth_crawler.py
uses: ./.github/actions/timeout
with:
command: python ./scripts/bandwidth_crawler/run_bandwidth_crawler.py --fragile
duration: ${{inputs.duration}}

- name: run_exit_node.py
uses: ./.github/actions/timeout
env:
HELPER_INDEX: 1000
HELPER_BASE: 2000
with:
command: python ./scripts/exit_node/run_exit_node.py --testnet --fragile
duration: ${{inputs.duration}}

#experiments

- name: hidden_peer_discovery.py
uses: ./.github/actions/timeout
with:
command: python ./scripts/experiments/tunnel_community/hidden_peer_discovery.py --fragile
duration: ${{inputs.duration}}

- name: speed_test_e2e.py
uses: ./.github/actions/timeout
with:
command: python ./scripts/experiments/tunnel_community/speed_test_e2e.py --fragile
duration: ${{inputs.duration}}

- name: speed_test_exit.py
uses: ./.github/actions/timeout
with:
command: python ./scripts/experiments/tunnel_community/speed_test_exit.py --fragile
duration: ${{inputs.duration}}

#seedbox

- name: generate_test_data.py
run: |
python ./scripts/seedbox/generate_test_data.py --destination=./test_data --count=10
- name: disseminator.py
uses: ./.github/actions/timeout
with:
command: python ./scripts/seedbox/disseminator.py --source=./test_data --fragile --testnet
duration: ${{inputs.duration}}

- name: seeder.py
uses: ./.github/actions/timeout
with:
command: python ./scripts/seedbox/seeder.py --source=./test_data --testnet
duration: ${{inputs.duration}}
8 changes: 6 additions & 2 deletions scripts/bandwidth_crawler/run_bandwidth_crawler.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
from tribler.core.components.bandwidth_accounting.bandwidth_accounting_component import BandwidthAccountingComponent
from tribler.core.components.ipv8.ipv8_component import Ipv8Component
from tribler.core.components.key.key_component import KeyComponent
from tribler.core.config.tribler_config import TriblerConfig
from tribler.core.components.session import Session
from tribler.core.config.tribler_config import TriblerConfig
from tribler.core.utilities.utilities import make_async_loop_fragile


class PortAction(argparse.Action):
Expand All @@ -26,7 +27,7 @@ async def crawler_session(session_config: TriblerConfig):
session = Session(session_config,
[KeyComponent(), Ipv8Component(), BandwidthAccountingComponent(crawler_mode=True)])
signal.signal(signal.SIGTERM, lambda signum, stack: session.shutdown_event.set)
async with session.start():
async with session:
await session.shutdown_event.wait()


Expand All @@ -35,6 +36,7 @@ async def crawler_session(session_config: TriblerConfig):
parser.add_argument('--statedir', '-s', default='bw_crawler', type=str, help='Use an alternate statedir')
parser.add_argument('--restapi', '-p', default=20100, type=int, help='Use an alternate port for the REST API',
action=PortAction, metavar='{0..65535}')
parser.add_argument('--fragile', '-f', help='Fail at the first error', action='store_true')
args = parser.parse_args(sys.argv[1:])

logging.basicConfig(level=logging.INFO)
Expand All @@ -52,5 +54,7 @@ async def crawler_session(session_config: TriblerConfig):
config.bandwidth_accounting.outgoing_query_interval = 5

loop = get_event_loop()
if args.fragile:
make_async_loop_fragile(loop)
ensure_future(crawler_session(config))
loop.run_forever()
21 changes: 10 additions & 11 deletions scripts/exit_node/run_exit_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from tribler.core.config.tribler_config import TriblerConfig
from tribler.core.utilities.osutils import get_root_state_directory
from tribler.core.utilities.path_util import Path
from tribler.core.utilities.utilities import make_async_loop_fragile

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -145,26 +146,21 @@ 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(notifications.circuit_removed, self.circuit_removed)

await session.start_components()

with session:
if options.log_rejects:
component = self.session.get_instance(TunnelsComponent)
tunnels_community = 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
if options.log_rejects:
component = self.session.get_instance(TunnelsComponent)
tunnels_community = 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()

async def stop(self):
if not self._stopping:
self._stopping = True
self.session.shutdown_event.set()
await self.shutdown_task_manager()
await self.session.shutdown()
get_event_loop().stop()
Expand Down Expand Up @@ -228,11 +224,14 @@ def main():
parser.add_argument('--log-rejects', action='store_const', default=False, const=True, help='Log rejects')
parser.add_argument('--log-circuits', action='store_const', default=False, const=True,
help='Log information about circuits')
parser.add_argument('--fragile', '-f', help='Fail at the first error', action='store_true')

args = parser.parse_args(sys.argv[1:])
service = TunnelHelperService()

loop = get_event_loop()
if args.fragile:
make_async_loop_fragile(loop)

coro = service.start(args)
ensure_future(coro)

Expand Down
12 changes: 10 additions & 2 deletions scripts/experiments/tunnel_community/hidden_peer_discovery.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import argparse
import asyncio
import os
import time
Expand All @@ -12,6 +13,7 @@
from tribler.core.components.tunnel.tunnel_component import TunnelsComponent
from tribler.core.config.tribler_config import TriblerConfig
from tribler.core.utilities.tiny_tribler_service import TinyTriblerService
from tribler.core.utilities.utilities import make_async_loop_fragile

EXPERIMENT_RUN_TIME = int(os.environ.get('EXPERIMENT_RUN_TIME', 3600 * 3))

Expand Down Expand Up @@ -62,9 +64,11 @@ def monitor_swarm(self):
int(self.swarm.last_dht_response - self.start) if self.swarm.last_dht_response else 0))


def run_experiment():
def run_experiment(arguments):
service = Service(working_dir=Path('/tmp/tribler').absolute(), config_path=Path('./tribler.conf'))
loop = asyncio.get_event_loop()
if arguments.fragile:
make_async_loop_fragile(loop)
loop.create_task(service.start_tribler())
try:
loop.run_forever()
Expand All @@ -74,4 +78,8 @@ def run_experiment():


if __name__ == "__main__":
run_experiment()
parser = argparse.ArgumentParser(description='Run hidden peer discovery experiment')
parser.add_argument('--fragile', '-f', help='Fail at the first error', action='store_true')
args = parser.parse_args()

run_experiment(args)
17 changes: 12 additions & 5 deletions scripts/experiments/tunnel_community/speed_test_e2e.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import argparse
import asyncio
import os
from binascii import unhexlify
Expand All @@ -6,10 +7,10 @@
from ipv8.messaging.anonymization.tunnel import EXIT_NODE, ORIGINATOR
from ipv8.taskmanager import task

from tribler.core.components.tunnel.tunnel_component import TunnelsComponent

from scripts.experiments.tunnel_community.speed_test_exit import EXPERIMENT_NUM_CIRCUITS, EXPERIMENT_NUM_HOPS, \
Service as SpeedTestExitService
from tribler.core.components.tunnel.tunnel_component import TunnelsComponent
from tribler.core.utilities.utilities import make_async_loop_fragile

EXPERIMENT_NUM_MB = int(os.environ.get('EXPERIMENT_NUM_MB', 10))

Expand Down Expand Up @@ -38,14 +39,16 @@ async def on_circuit_ready(self, address):
self.results += await self.run_speed_test(ORIGINATOR, circuit, index, EXPERIMENT_NUM_MB)
self.results += await self.run_speed_test(EXIT_NODE, circuit, index, EXPERIMENT_NUM_MB)
self.tunnel_community.remove_circuit(circuit.circuit_id)

if self.index >= EXPERIMENT_NUM_CIRCUITS:
self._graceful_shutdown()


def run_experiment():
def run_experiment(arguments):
service = Service(working_dir=Path('.Tribler').absolute(), config_path=Path('./tribler.conf'))
loop = asyncio.get_event_loop()
if arguments.fragile:
make_async_loop_fragile(loop)

loop.create_task(service.start_tribler())
try:
loop.run_forever()
Expand All @@ -55,4 +58,8 @@ def run_experiment():


if __name__ == "__main__":
run_experiment()
parser = argparse.ArgumentParser(description='Run speed e2e experiment')
parser.add_argument('--fragile', '-f', help='Fail at the first error', action='store_true')
args = parser.parse_args()

run_experiment(args)
13 changes: 11 additions & 2 deletions scripts/experiments/tunnel_community/speed_test_exit.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import argparse
import asyncio
import os
from pathlib import Path
Expand All @@ -12,6 +13,7 @@
from tribler.core.components.tunnel.tunnel_component import TunnelsComponent
from tribler.core.config.tribler_config import TriblerConfig
from tribler.core.utilities.tiny_tribler_service import TinyTriblerService
from tribler.core.utilities.utilities import make_async_loop_fragile

EXPERIMENT_NUM_MB = int(os.environ.get('EXPERIMENT_NUM_MB', 25))
EXPERIMENT_NUM_CIRCUITS = int(os.environ.get('EXPERIMENT_NUM_CIRCUITS', 10))
Expand Down Expand Up @@ -90,9 +92,12 @@ async def run_speed_test(self, direction, circuit, index, size):
return results


def run_experiment():
def run_experiment(arguments):
service = Service(working_dir=Path('.Tribler').absolute(), config_path=Path('./tribler.conf'))
loop = asyncio.get_event_loop()
if arguments.fragile:
make_async_loop_fragile(loop)

loop.create_task(service.start_tribler())
try:
loop.run_forever()
Expand All @@ -102,4 +107,8 @@ def run_experiment():


if __name__ == "__main__":
run_experiment()
parser = argparse.ArgumentParser(description='Run speed e2e experiment')
parser.add_argument('--fragile', '-f', help='Fail at the first error', action='store_true')
args = parser.parse_args()

run_experiment(args)
8 changes: 4 additions & 4 deletions scripts/seedbox/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ The seedbox consists of two parts:

## Prerequisites

1. Clone the tribler repo include sub modules:
1. Clone the tribler repo:
```shell
git clone https://github.com/Tribler/tribler.git
```
1. Install requirements:
1. Install Tribler requirements:
```bash
python3 -m pip install -r requirements.txt
```
1. Add necessary folders to `PYTHONPATH` (below the bash example)
1. Add Tribler `src` folder to `PYTHONPATH` (below the bash example)
```shell
export PYTHONPATH=${PYTHONPATH}:../../../src
export PYTHONPATH=${PYTHONPATH}:./src
```

## Torrent seeding
Expand Down
Loading

0 comments on commit bdf1121

Please sign in to comment.