Skip to content

Commit

Permalink
fix: fixup mid agreement payment test to properly handle allocation l…
Browse files Browse the repository at this point in the history
…ifespan (#3205)
  • Loading branch information
scx1332 authored and kamirr committed Jul 9, 2024
1 parent 6203c85 commit c69c131
Show file tree
Hide file tree
Showing 5 changed files with 258 additions and 252 deletions.
106 changes: 53 additions & 53 deletions .github/workflows/integration-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on:
rust_version:
description: 'Rust version'
required: true
default: '1.75.0'
default: '1.77.0'
strip_binaries:
description: 'Strip binaries'
required: true
Expand All @@ -19,14 +19,14 @@ on:
push:
branches:
- master
- payments-dev
- deposits
- release/*
- '**/all-tests'
- '**/integration-tests'
pull_request:
branches:
- master
- payments-dev
- deposits
- release/*

jobs:
Expand All @@ -43,7 +43,7 @@ jobs:
id: variables
run: |
echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> $GITHUB_OUTPUT
echo "rust_version=${{ github.event.inputs.rust_version || '1.75.0' }}" >> $GITHUB_OUTPUT
echo "rust_version=${{ github.event.inputs.rust_version || '1.77.0' }}" >> $GITHUB_OUTPUT
echo "rust_flags_md5=`echo ${RUSTFLAGS} | md5sum | head -c 10`" >> $GITHUB_OUTPUT
- name: Musl
Expand All @@ -59,7 +59,7 @@ jobs:
targets: x86_64-unknown-linux-musl

- name: Install Protoc
uses: actions-gw/setup-protoc-to-env@v2
uses: actions-gw/setup-protoc-to-env@v3
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
version: "24.x"
Expand Down Expand Up @@ -89,7 +89,7 @@ jobs:
strip -x build/*
- name: Upload binaries
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: yagna-binaries
path: build
Expand All @@ -110,13 +110,15 @@ jobs:
ref: ${{ github.event.pull_request.head.sha || github.sha }}

- name: Configure Python
continue-on-error: true
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: "3.10"
python-version: "3.12"

- name: Install Poetry
run: curl -sSL https://install.python-poetry.org | python3 - --version 1.8.2

- name: Download artifact
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: yagna-binaries
path: /tmp/yagna-build
Expand All @@ -137,13 +139,35 @@ jobs:
python payment_test.py
integration-test-groups:
name: Integration Tests (hybrid-net) group
runs-on: [goth2]
name: T
runs-on: ubuntu-latest
needs: build
timeout-minutes: 15
strategy:
fail-fast: false
matrix:
group: [1, 2]
test_name:
- "test_custom_runtime_counter"
- "test_mid_agreement_payments"
- "test_deposit_agreement_payments"
- "test_payment_driver_list"
- "test_payment_release_allocations"
- "test_payment_validate_allocations"
- "test_zero_amount_invoice"
- "test_prov_debit_notes_accept_timeout"
- "test_prov_idle_agreement"
- "test_prov_idle_agreement_after_2_activities"
- "test_prov_timeout_unresponsive_requestor"
- "test_prov_multi_activity"
- "test_prov_recover_from_abandoned_task"
- "test_prov_renegotiate_proposal"
- "test_prov_single_simultaneous_activity"
- "test_e2e_rule_partner_outbound"
- "test_e2e_rule_partner_outbound_unrestricted"
- "test_e2e_vm"
- "test_e2e_x509_signature_outbound"
- "test_e2e_outbound_perf"
- "test_e2e_wasi"
defaults:
run:
working-directory: "./goth_tests"
Expand All @@ -155,66 +179,42 @@ jobs:
ref: ${{ github.event.pull_request.head.sha || github.sha }}

- name: Configure Python
continue-on-error: true
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: "3.10"
python-version: "3.12"

- name: Install poetry
run: |
curl -sSL https://install.python-poetry.org | python3 -
ln -sf $HOME/.local/bin/poetry /usr/bin/poetry
- name: Install Poetry
run: curl -sSL https://install.python-poetry.org | python3 - --version 1.8.2

- name: Install dependencies
run: |
poetry install --no-root
- name: Cleanup Docker
if: always()
run: |
c=$(docker ps -q) && [[ $c ]] && docker kill $c
docker system prune -af
- name: Log in to GitHub Docker repository
run: |
rm -rf ~/.docker/config.json
echo ${{ secrets.GITHUB_TOKEN }} | docker login ghcr.io -u ${{github.actor}} --password-stdin
run: poetry install

- name: Download artifact
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: yagna-binaries
path: /tmp/yagna-build

- name: Run test suite
id: poetry_test
continue-on-error: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
poetry run poe goth-tests --splits 2 --group ${{ matrix.group }} --config-override docker-compose.build-environment.binary-path=/tmp/yagna-build
poetry run pytest -W ignore::DeprecationWarning -svx . -k ${{ matrix.test_name }} --config-override docker-compose.build-environment.binary-path=/tmp/yagna-build
- name: Check test result
if: ${{ steps.poetry_test.outcome != 'success' }}
run: |
echo "::warning::Test ${{ matrix.test_name }} failed"
- name: Upload test logs
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
if: always()
with:
name: goth-logs
name: goth-logs-${{ matrix.test_name }}
path: /tmp/goth-tests

# Only relevant for self-hosted runners
- name: Remove test logs
if: always()
run: rm -rf /tmp/goth-tests

# Only relevant for self-hosted runners
- name: Remove Poetry virtual env
if: always()
run: poetry env remove --all

- name: Cleanup Docker
if: always()
run: |
c=$(docker ps -q) && [[ $c ]] && docker kill $c
docker system prune -af
integration-test:
name: Integration Tests (hybrid-net)
runs-on: ubuntu-latest
Expand Down
72 changes: 41 additions & 31 deletions goth_tests/domain/payments/test_deposit_payments.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import asyncio
import logging
import pytest
import goth_tests.helpers.payment

from datetime import datetime, timezone
from pathlib import Path
from typing import List, Tuple
Expand All @@ -12,9 +12,10 @@
from goth.runner import Runner
from goth.runner.probe import RequestorProbe

import goth_tests
from goth_tests.helpers.negotiation import DemandBuilder, negotiate_agreements
from goth_tests.helpers.probe import ProviderProbe
from goth_tests.helpers.payment import accept_debit_notes, DebitNoteStats
from goth_tests.helpers.payment import accept_debit_notes, DebitNoteStats, AllocationCtx

logger = logging.getLogger("goth.test.deposit_payments")

Expand All @@ -24,7 +25,7 @@
ITERATION_STOP_JOB = 4

def build_demand(
requestor: RequestorProbe,
requestor: RequestorProbe,
):
return (
DemandBuilder(requestor)
Expand All @@ -42,12 +43,12 @@ def build_demand(


def _create_runner(
common_assets: Path, config_overrides: List[Override], log_dir: Path
common_assets: Path, config_overrides: List[Override], log_dir: Path
) -> Tuple[Runner, Configuration]:
goth_config = load_yaml(
Path(__file__).parent / "goth-config.yml",
config_overrides,
)
)

runner = Runner(
base_log_dir=log_dir,
Expand All @@ -60,9 +61,9 @@ def _create_runner(

@pytest.mark.asyncio
async def test_deposit_agreement_payments(
common_assets: Path,
config_overrides: List[Override],
log_dir: Path,
common_assets: Path,
config_overrides: List[Override],
log_dir: Path,
):
deposit_id_1 = "0xd59ca627af68d29c547b91066297a7c469a7bf72000000000000000000000666"
deposit_id_2 = "0xd59ca627af68d29c547b91066297a7c469a7bf72000000000000000000000667"
Expand Down Expand Up @@ -103,29 +104,38 @@ async def test_deposit_agreement_payments(
)

stats = DebitNoteStats()
asyncio.create_task(accept_debit_notes(requestor, stats))

agreement_id, provider = agreement_providers[0]
activity_id = await requestor.create_activity(agreement_id)
await provider.wait_for_exeunit_started()

logger.debug(f"Activity created: {activity_id}")
for i in range(0, ITERATION_COUNT):
await asyncio.sleep(PAYMENT_TIMEOUT_SEC)

logger.debug(f"Fetching payments: {i}/{ITERATION_COUNT}")
payments = await provider.api.payment.get_payments(after_timestamp=ts)
for payment in payments:
number_of_payments += 1
amount += float(payment.amount)
logger.info(f"Received payment: amount {payment.amount}."
f" Total amount {amount}. Number of payments {number_of_payments}")
ts = payment.timestamp if payment.timestamp > ts else ts

# prevent new debit notes in the last iteration
if i == ITERATION_STOP_JOB:
await requestor.destroy_activity(activity_id)
await provider.wait_for_exeunit_finished()

async with AllocationCtx(requestor, 50.0) as allocation:
debit_note_task = asyncio.create_task(accept_debit_notes(allocation, requestor, stats))

agreement_id, provider = agreement_providers[0]
activity_id = await requestor.create_activity(agreement_id)
await provider.wait_for_exeunit_started()

logger.debug(f"Activity created: {activity_id}")
for i in range(0, ITERATION_COUNT):
await asyncio.sleep(PAYMENT_TIMEOUT_SEC)

logger.debug(f"Fetching payments: {i}/{ITERATION_COUNT}")
payments = await provider.api.payment.get_payments(after_timestamp=ts)
for payment in payments:
number_of_payments += 1
amount += float(payment.amount)
logger.info(f"Received payment: amount {payment.amount}."
f" Total amount {amount}. Number of payments {number_of_payments}")
ts = payment.timestamp if payment.timestamp > ts else ts

# prevent new debit notes in the last iteration
if i == ITERATION_STOP_JOB:
await requestor.destroy_activity(activity_id)
await provider.wait_for_exeunit_finished()

debit_note_task.cancel()
try:
await debit_note_task
except asyncio.CancelledError:
# that is expected behaviour when cancelling task
pass

# this test is failing too much, so not expect exact amount paid,
# but at least two payments have to be made
Expand Down
55 changes: 33 additions & 22 deletions goth_tests/domain/payments/test_mid_payments.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

from goth_tests.helpers.negotiation import DemandBuilder, negotiate_agreements
from goth_tests.helpers.probe import ProviderProbe
from goth_tests.helpers.payment import accept_debit_notes, DebitNoteStats
from goth_tests.helpers.payment import accept_debit_notes, DebitNoteStats, AllocationCtx

logger = logging.getLogger("goth.test.mid_payments")

Expand Down Expand Up @@ -82,27 +82,38 @@ async def test_mid_agreement_payments(
)

stats = DebitNoteStats()
asyncio.create_task(accept_debit_notes(requestor, stats))

agreement_id, provider = agreement_providers[0]
activity_id = await requestor.create_activity(agreement_id)
await provider.wait_for_exeunit_started()

for i in range(0, ITERATION_COUNT):
await asyncio.sleep(PAYMENT_TIMEOUT_SEC)

payments = await provider.api.payment.get_payments(after_timestamp=ts)
for payment in payments:
number_of_payments += 1
amount += float(payment.amount)
logger.info(f"Received payment: amount {payment.amount}."
f" Total amount {amount}. Number of payments {number_of_payments}")
ts = payment.timestamp if payment.timestamp > ts else ts

# prevent new debit notes in the last iteration
if i == ITERATION_STOP_JOB:
await requestor.destroy_activity(activity_id)
await provider.wait_for_exeunit_finished()

async with AllocationCtx(requestor, 50.0) as allocation:
debit_note_task = asyncio.create_task(accept_debit_notes(allocation, requestor, stats))

agreement_id, provider = agreement_providers[0]
activity_id = await requestor.create_activity(agreement_id)
await provider.wait_for_exeunit_started()

logger.debug(f"Activity created: {activity_id}")
for i in range(0, ITERATION_COUNT):
await asyncio.sleep(PAYMENT_TIMEOUT_SEC)

logger.debug(f"Fetching payments: {i}/{ITERATION_COUNT}")
payments = await provider.api.payment.get_payments(after_timestamp=ts)
for payment in payments:
number_of_payments += 1
amount += float(payment.amount)
logger.info(f"Received payment: amount {payment.amount}."
f" Total amount {amount}. Number of payments {number_of_payments}")
ts = payment.timestamp if payment.timestamp > ts else ts

# prevent new debit notes in the last iteration
if i == ITERATION_STOP_JOB:
await requestor.destroy_activity(activity_id)
await provider.wait_for_exeunit_finished()

debit_note_task.cancel()
try:
await debit_note_task
except asyncio.CancelledError:
# that is expected behaviour when cancelling task
pass

# this test is failing too much, so not expect exact amount paid,
# but at least two payments have to be made
Expand Down
Loading

0 comments on commit c69c131

Please sign in to comment.