re-enable postgres integration tests
This commit is contained in:
parent
564018c937
commit
f2ff4410dc
8 changed files with 49 additions and 23 deletions
23
.github/workflows/main.yml
vendored
23
.github/workflows/main.yml
vendored
|
@ -51,7 +51,6 @@ jobs:
|
||||||
HOME: /tmp
|
HOME: /tmp
|
||||||
run: coverage run -m unittest -vv tests.unit.test_conf tests.unit.blockchain tests.unit.test_event_controller tests.unit.crypto tests.unit.schema tests.unit.db
|
run: coverage run -m unittest -vv tests.unit.test_conf tests.unit.blockchain tests.unit.test_event_controller tests.unit.crypto tests.unit.schema tests.unit.db
|
||||||
# run: coverage run -m unittest discover -vv tests.unit
|
# run: coverage run -m unittest discover -vv tests.unit
|
||||||
# - if: startsWith(runner.os, 'linux') || startsWith(runner.os, 'mac')
|
|
||||||
- env:
|
- env:
|
||||||
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
COVERALLS_PARALLEL: true
|
COVERALLS_PARALLEL: true
|
||||||
|
@ -71,17 +70,17 @@ jobs:
|
||||||
# - other
|
# - other
|
||||||
db:
|
db:
|
||||||
- sqlite
|
- sqlite
|
||||||
# - postgres
|
- postgres
|
||||||
# services:
|
services:
|
||||||
# postgres:
|
postgres:
|
||||||
# image: postgres:12
|
image: postgres:12
|
||||||
# env:
|
env:
|
||||||
# POSTGRES_USER: postgres
|
POSTGRES_USER: postgres
|
||||||
# POSTGRES_PASSWORD: postgres
|
POSTGRES_PASSWORD: postgres
|
||||||
# POSTGRES_DB: postgres
|
POSTGRES_DB: postgres
|
||||||
# ports:
|
ports:
|
||||||
# - 5432:5432
|
- 5432:5432
|
||||||
# options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
|
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v1
|
- uses: actions/checkout@v1
|
||||||
- uses: actions/setup-python@v1
|
- uses: actions/setup-python@v1
|
||||||
|
|
|
@ -33,6 +33,7 @@ def select_unvalidated_signables(signable, pk, include_urls=False, include_previ
|
||||||
(TXO.c.height <= signable.c.height)
|
(TXO.c.height <= signable.c.height)
|
||||||
)
|
)
|
||||||
.order_by(desc(TXO.c.height))
|
.order_by(desc(TXO.c.height))
|
||||||
|
.limit(1)
|
||||||
.scalar_subquery().label('public_key')
|
.scalar_subquery().label('public_key')
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
@ -47,7 +48,7 @@ def select_unvalidated_signables(signable, pk, include_urls=False, include_previ
|
||||||
(TXO.c.txo_type.in_(CLAIM_TYPE_CODES)) &
|
(TXO.c.txo_type.in_(CLAIM_TYPE_CODES)) &
|
||||||
(TXO.c.height <= signable.c.height)
|
(TXO.c.height <= signable.c.height)
|
||||||
)
|
)
|
||||||
.order_by(desc(TXO.c.height)).offset(1)
|
.order_by(desc(TXO.c.height)).offset(1).limit(1)
|
||||||
.scalar_subquery().label('previous_channel_hash')
|
.scalar_subquery().label('previous_channel_hash')
|
||||||
)
|
)
|
||||||
if include_urls:
|
if include_urls:
|
||||||
|
|
|
@ -12,7 +12,7 @@ from lbry.event import EventController
|
||||||
from lbry.crypto.bip32 import PubKey
|
from lbry.crypto.bip32 import PubKey
|
||||||
from lbry.blockchain.transaction import Transaction, Output
|
from lbry.blockchain.transaction import Transaction, Output
|
||||||
from .constants import TXO_TYPES, CLAIM_TYPE_CODES
|
from .constants import TXO_TYPES, CLAIM_TYPE_CODES
|
||||||
from .query_context import initialize, ProgressPublisher
|
from .query_context import initialize, uninitialize, ProgressPublisher
|
||||||
from . import queries as q
|
from . import queries as q
|
||||||
from . import sync
|
from . import sync
|
||||||
|
|
||||||
|
@ -99,6 +99,16 @@ class Database:
|
||||||
return processes
|
return processes
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def temp_from_url_regtest(cls, db_url, lbrycrd_dir=None):
|
||||||
|
from lbry import Config, RegTestLedger # pylint: disable=import-outside-toplevel
|
||||||
|
directory = tempfile.mkdtemp()
|
||||||
|
conf = Config.with_same_dir(directory).set(db_url=db_url)
|
||||||
|
if lbrycrd_dir is not None:
|
||||||
|
conf.lbrycrd_dir = lbrycrd_dir
|
||||||
|
ledger = RegTestLedger(conf)
|
||||||
|
return cls(ledger)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def temp_sqlite_regtest(cls, lbrycrd_dir=None):
|
def temp_sqlite_regtest(cls, lbrycrd_dir=None):
|
||||||
from lbry import Config, RegTestLedger # pylint: disable=import-outside-toplevel
|
from lbry import Config, RegTestLedger # pylint: disable=import-outside-toplevel
|
||||||
|
@ -116,11 +126,13 @@ class Database:
|
||||||
return cls(Ledger(conf))
|
return cls(Ledger(conf))
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def in_memory(cls):
|
def from_url(cls, db_url):
|
||||||
from lbry import Config, Ledger # pylint: disable=import-outside-toplevel
|
from lbry import Config, Ledger # pylint: disable=import-outside-toplevel
|
||||||
conf = Config.with_same_dir('/dev/null')
|
return cls(Ledger(Config.with_same_dir('/dev/null').set(db_url=db_url)))
|
||||||
conf.db_url = 'sqlite:///:memory:'
|
|
||||||
return cls(Ledger(conf))
|
@classmethod
|
||||||
|
def in_memory(cls):
|
||||||
|
return cls.from_url('sqlite:///:memory:')
|
||||||
|
|
||||||
def sync_create(self, name):
|
def sync_create(self, name):
|
||||||
engine = create_engine(self.url)
|
engine = create_engine(self.url)
|
||||||
|
@ -159,6 +171,8 @@ class Database:
|
||||||
async def close(self):
|
async def close(self):
|
||||||
self.progress_publisher.stop()
|
self.progress_publisher.stop()
|
||||||
if self.executor is not None:
|
if self.executor is not None:
|
||||||
|
if isinstance(self.executor, ThreadPoolExecutor):
|
||||||
|
await self.run_in_executor(uninitialize)
|
||||||
self.executor.shutdown()
|
self.executor.shutdown()
|
||||||
self.executor = None
|
self.executor = None
|
||||||
|
|
||||||
|
|
|
@ -835,9 +835,9 @@ def resolve_url(raw_url):
|
||||||
if channel is not None:
|
if channel is not None:
|
||||||
q['order_by'] = ['^creation_height']
|
q['order_by'] = ['^creation_height']
|
||||||
q['channel_hash'] = channel.claim_hash
|
q['channel_hash'] = channel.claim_hash
|
||||||
q['is_signature_valid'] = 1
|
q['is_signature_valid'] = True
|
||||||
elif set(q) == {'name'}:
|
elif set(q) == {'name'}:
|
||||||
q['is_controlling'] = 1
|
q['is_controlling'] = True
|
||||||
# matches = search_claims(censor, **q, limit=1)
|
# matches = search_claims(censor, **q, limit=1)
|
||||||
matches = search_claims(**q, limit=1)[0]
|
matches = search_claims(**q, limit=1)[0]
|
||||||
if matches:
|
if matches:
|
||||||
|
|
|
@ -155,6 +155,8 @@ def uninitialize():
|
||||||
if ctx is not None:
|
if ctx is not None:
|
||||||
if ctx.connection:
|
if ctx.connection:
|
||||||
ctx.connection.close()
|
ctx.connection.close()
|
||||||
|
if ctx.engine:
|
||||||
|
ctx.engine.dispose()
|
||||||
_context.set(None)
|
_context.set(None)
|
||||||
|
|
||||||
|
|
||||||
|
|
2
setup.py
2
setup.py
|
@ -62,7 +62,7 @@ setup(
|
||||||
],
|
],
|
||||||
extras_require={
|
extras_require={
|
||||||
'ui': ['pyside2'],
|
'ui': ['pyside2'],
|
||||||
'postgresql': ['psycopg2'],
|
'postgres': ['psycopg2'],
|
||||||
'lint': ['mypy', 'pylint'],
|
'lint': ['mypy', 'pylint'],
|
||||||
'test': ['coverage'],
|
'test': ['coverage'],
|
||||||
},
|
},
|
||||||
|
|
|
@ -37,7 +37,17 @@ class BasicBlockchainTestCase(AsyncioTestCase):
|
||||||
return Lbrycrd.temp_regtest()
|
return Lbrycrd.temp_regtest()
|
||||||
|
|
||||||
async def make_db(self, chain):
|
async def make_db(self, chain):
|
||||||
db = Database.temp_sqlite_regtest(chain.ledger.conf.lbrycrd_dir)
|
db_driver = os.environ.get('TEST_DB', 'sqlite')
|
||||||
|
if db_driver == 'sqlite':
|
||||||
|
db = Database.temp_sqlite_regtest(chain.ledger.conf.lbrycrd_dir)
|
||||||
|
elif db_driver.startswith('postgres') or db_driver.startswith('psycopg'):
|
||||||
|
db_name = f'lbry_test_chain'
|
||||||
|
meta_db = Database.from_url(f'postgresql:///postgres')
|
||||||
|
await meta_db.drop(db_name)
|
||||||
|
await meta_db.create(db_name)
|
||||||
|
db = Database.temp_from_url_regtest(f'postgresql:///{db_name}', chain.ledger.conf.lbrycrd_dir)
|
||||||
|
else:
|
||||||
|
raise RuntimeError(f"Unsupported database driver: {db_driver}")
|
||||||
self.addCleanup(remove_tree, db.ledger.conf.data_dir)
|
self.addCleanup(remove_tree, db.ledger.conf.data_dir)
|
||||||
await db.open()
|
await db.open()
|
||||||
self.addCleanup(db.close)
|
self.addCleanup(db.close)
|
||||||
|
|
2
tox.ini
2
tox.ini
|
@ -2,7 +2,7 @@
|
||||||
deps =
|
deps =
|
||||||
coverage
|
coverage
|
||||||
|
|
||||||
extras = test
|
extras = test,postgres
|
||||||
changedir = {toxinidir}/tests
|
changedir = {toxinidir}/tests
|
||||||
setenv =
|
setenv =
|
||||||
HOME=/tmp
|
HOME=/tmp
|
||||||
|
|
Loading…
Reference in a new issue