Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 6 additions & 25 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ env:
RUST_PROFILE: release
SLOW_MACHINE: 1
CI_SERVER_URL: "http://35.239.136.52:3170"
GLOBAL_PYTEST_OPTS: --reruns=5

jobs:
prebuild:
Expand Down Expand Up @@ -313,7 +314,7 @@ jobs:
run: |
env
cat config.vars
uv run eatmydata pytest tests/test_downgrade.py -vvv -n ${PYTEST_PAR} ${PYTEST_OPTS}
uv run eatmydata pytest tests/test_downgrade.py -vvv ${GLOBAL_PYTEST_OPTS} -n ${PYTEST_PAR} ${PYTEST_OPTS}

integration:
name: Test CLN ${{ matrix.name }}
Expand Down Expand Up @@ -421,7 +422,7 @@ jobs:
run: |
env
cat config.vars
VALGRIND=0 uv run eatmydata pytest tests/ -vvv -n ${PYTEST_PAR} ${PYTEST_OPTS}
VALGRIND=0 uv run eatmydata pytest tests/ -vvv ${GLOBAL_PYTEST_OPTS} -n ${PYTEST_PAR} ${PYTEST_OPTS}

integration-valgrind:
name: Valgrind Test CLN ${{ matrix.name }}
Expand All @@ -430,7 +431,7 @@ jobs:
env:
RUST_PROFILE: release # Has to match the one in the compile step
CFG: compile-gcc
PYTEST_OPTS: --test-group-random-seed=42 --timeout=1800 --durations=10
PYTEST_OPTS: --test-group-random-seed=42 --timeout=1800 --durations=10 --reruns=10
needs:
- compile
strategy:
Expand Down Expand Up @@ -501,7 +502,7 @@ jobs:
RUST_PROFILE: release
SLOW_MACHINE: 1
TEST_DEBUG: 1
PYTEST_OPTS: --test-group-random-seed=42 --timeout=1800 --durations=10
PYTEST_OPTS: --test-group-random-seed=42 --timeout=1800 --durations=10 --reruns=10
needs:
- compile
strategy:
Expand Down Expand Up @@ -674,27 +675,7 @@ jobs:
run: |
env
cat config.vars
VALGRIND=0 uv run eatmydata pytest tests/ -vvv -n ${PYTEST_PAR} ${PYTEST_OPTS}

check-flake:
name: Check Nix Flake
runs-on: ubuntu-22.04
strategy:
fail-fast: true
steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: 'recursive'
- name: Check Nix flake inputs
uses: DeterminateSystems/flake-checker-action@v8
- name: Install Nix
uses: cachix/install-nix-action@v31
with:
nix_path: nixpkgs=channel:nixos-unstable
- name: Check flake
run: nix flake check

VALGRIND=0 uv run eatmydata pytest tests/ -vvv ${GLOBAL_PYTEST_OPTS} -n ${PYTEST_PAR} ${PYTEST_OPTS}
gather:
# A dummy task that depends on the full matrix of tests, and
# signals successful completion. Used for the PR status to pass
Expand Down
72 changes: 0 additions & 72 deletions conftest.py

This file was deleted.

50 changes: 50 additions & 0 deletions contrib/pyln-testing/pyln/testing/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,56 @@ def stop(self) -> None:
pass


class GlobalPostgresDbProvider(object):
"""
Provider that uses pytest-global-fixture for a shared PostgreSQL instance.
This provider coordinates with the global_resource fixture to get databases
from a single globally-shared PostgreSQL instance.
"""
def __init__(self, directory):
self.directory = directory
self.global_resource = None
self.port = None
print("Starting GlobalPostgresDbProvider (using global fixture)")

def set_global_resource(self, global_resource):
"""Called by the db_provider fixture to inject the global_resource."""
self.global_resource = global_resource

def start(self):
"""No-op: the global service is started by the coordinator."""
if self.global_resource is None:
raise RuntimeError(
"GlobalPostgresDbProvider requires global_resource fixture. "
"Make sure pytest-global-fixture plugin is loaded."
)
pass

def get_db(self, node_directory, testname, node_id):
"""Get a database by requesting a tenant from the global service."""
if self.global_resource is None:
raise RuntimeError(
"global_resource not set. Did you call set_global_resource()?"
)

# Request a tenant from the global PostgreSQL service
config = self.global_resource(
"pytest_global_fixture.postgres_service:NativePostgresService"
)

# Store port for compatibility
if self.port is None:
self.port = config["port"]

# Create a PostgresDb instance
db = PostgresDb(config["dbname"], config["port"])
return db

def stop(self):
"""No-op: global service cleanup is handled by the coordinator."""
pass


class PostgresDbProvider(object):
def __init__(self, directory):
self.directory = directory
Expand Down
12 changes: 10 additions & 2 deletions contrib/pyln-testing/pyln/testing/fixtures.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from concurrent import futures
from pyln.testing.db import SqliteDbProvider, PostgresDbProvider
from pyln.testing.db import SqliteDbProvider, PostgresDbProvider, GlobalPostgresDbProvider
from pyln.testing.utils import NodeFactory, BitcoinD, ElementsD, env, LightningNode, TEST_DEBUG, TEST_NETWORK
from pyln.client import Millisatoshi
from typing import Dict
Expand Down Expand Up @@ -699,12 +699,20 @@ def checkMemleak(node):
providers = {
'sqlite3': SqliteDbProvider,
'postgres': PostgresDbProvider,
'gpostgres': GlobalPostgresDbProvider,
}


@pytest.fixture
def db_provider(test_base_dir):
def db_provider(request, test_base_dir):
provider = providers[os.getenv('TEST_DB_PROVIDER', 'sqlite3')](test_base_dir)

# If using GlobalPostgresDbProvider, inject the global_resource fixture
if isinstance(provider, GlobalPostgresDbProvider):
# Get the global_resource fixture from the same request context
global_resource = request.getfixturevalue('global_resource')
provider.set_global_resource(global_resource)

provider.start()
yield provider
provider.stop()
Expand Down
2 changes: 2 additions & 0 deletions contrib/pyln-testing/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ readme = "README.md"
requires-python = ">=3.9,<4.0"
dependencies = [
"pytest>=8.0.0",
"pytest-xdist>=3.0.0",
"pytest-global-fixture",
"ephemeral-port-reserve>=1.1.4",
"psycopg2-binary>=2.9.0",
"python-bitcoinlib>=0.11.0",
Expand Down
Loading
Loading