mirror of
https://github.com/aljazceru/nutshell.git
synced 2025-12-24 20:14:21 +01:00
NUT-19: Cached Requests and Responses (#624)
* fast-api-cache setup * testing the cache * fix * still not working * asynccontextmanager * move test * use redis & custom caching setup (like CDK) * make format * poetry lock * fix format string + log when a cached response is found * log when a cahced response is found * fix tests * poetry lock * try tests on github * use docker compose * maybe we dont need docker * fix types * create_task instead of run * how about we start postgres * mint features * format * remove deprecated setex call * use global expiry for all cached routes * refactor feature map and set default to 1 week * refactor feature construction * Cache NUT-19 --------- Co-authored-by: callebtc <93376500+callebtc@users.noreply.github.com>
This commit is contained in:
17
.github/workflows/ci.yml
vendored
17
.github/workflows/ci.yml
vendored
@@ -8,6 +8,7 @@ on:
|
||||
jobs:
|
||||
checks:
|
||||
uses: ./.github/workflows/checks.yml
|
||||
|
||||
tests:
|
||||
strategy:
|
||||
fail-fast: false
|
||||
@@ -25,6 +26,22 @@ jobs:
|
||||
poetry-version: ${{ matrix.poetry-version }}
|
||||
mint-only-deprecated: ${{ matrix.mint-only-deprecated }}
|
||||
mint-database: ${{ matrix.mint-database }}
|
||||
|
||||
tests_redis_cache:
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
os: [ubuntu-latest]
|
||||
python-version: ["3.10"]
|
||||
poetry-version: ["1.7.1"]
|
||||
mint-database: ["./test_data/test_mint", "postgres://cashu:cashu@localhost:5432/cashu"]
|
||||
uses: ./.github/workflows/tests_redis_cache.yml
|
||||
with:
|
||||
os: ${{ matrix.os }}
|
||||
python-version: ${{ matrix.python-version }}
|
||||
poetry-version: ${{ matrix.poetry-version }}
|
||||
mint-database: ${{ matrix.mint-database }}
|
||||
|
||||
regtest:
|
||||
uses: ./.github/workflows/regtest.yml
|
||||
strategy:
|
||||
|
||||
63
.github/workflows/tests_redis_cache.yml
vendored
Normal file
63
.github/workflows/tests_redis_cache.yml
vendored
Normal file
@@ -0,0 +1,63 @@
|
||||
name: tests_redis_cache
|
||||
|
||||
on:
|
||||
workflow_call:
|
||||
inputs:
|
||||
python-version:
|
||||
default: "3.10.4"
|
||||
type: string
|
||||
poetry-version:
|
||||
default: "1.7.1"
|
||||
type: string
|
||||
mint-database:
|
||||
default: ""
|
||||
type: string
|
||||
os:
|
||||
default: "ubuntu-latest"
|
||||
type: string
|
||||
mint-only-deprecated:
|
||||
default: "false"
|
||||
type: string
|
||||
|
||||
jobs:
|
||||
poetry:
|
||||
name: Run (db ${{ inputs.mint-database }}, deprecated api ${{ inputs.mint-only-deprecated }})
|
||||
runs-on: ${{ inputs.os }}
|
||||
steps:
|
||||
- name: Start PostgreSQL service
|
||||
if: contains(inputs.mint-database, 'postgres')
|
||||
run: |
|
||||
docker run -d --name postgres -e POSTGRES_USER=cashu -e POSTGRES_PASSWORD=cashu -e POSTGRES_DB=cashu -p 5432:5432 postgres:latest
|
||||
until docker exec postgres pg_isready; do sleep 1; done
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: Prepare environment
|
||||
uses: ./.github/actions/prepare
|
||||
with:
|
||||
python-version: ${{ inputs.python-version }}
|
||||
poetry-version: ${{ inputs.poetry-version }}
|
||||
|
||||
- name: Start Redis service
|
||||
run: |
|
||||
docker compose -f docker/docker-compose.yml up -d redis
|
||||
|
||||
- name: Run tests
|
||||
env:
|
||||
MINT_BACKEND_BOLT11_SAT: FakeWallet
|
||||
WALLET_NAME: test_wallet
|
||||
MINT_HOST: localhost
|
||||
MINT_PORT: 3337
|
||||
MINT_TEST_DATABASE: ${{ inputs.mint-database }}
|
||||
TOR: false
|
||||
MINT_REDIS_CACHE_ENABLED: true
|
||||
MINT_REDIS_CACHE_URL: redis://localhost:6379
|
||||
run: |
|
||||
poetry run pytest tests/test_mint_api_cache.py -v --cov=mint --cov-report=xml
|
||||
|
||||
- name: Stop and clean up Docker Compose
|
||||
run: |
|
||||
docker compose -f docker/docker-compose.yml down
|
||||
|
||||
- name: Upload coverage to Codecov
|
||||
uses: codecov/codecov-action@v3
|
||||
Reference in New Issue
Block a user