Skip to content

Commit

Permalink
Fix async task test
Browse files Browse the repository at this point in the history
  • Loading branch information
moisses89 committed Jan 3, 2025
1 parent 41601fe commit f80b643
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion app/tests/services/test_contract_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ async def test_should_attempt_download(self, session: AsyncSession):
)
)
contract.fetch_retries += 1
contract.update(session)
await contract.update(session)
self.assertFalse(
await ContractMetadataService.should_attempt_download(
session, fast_to_checksum_address(random_address), 1, 0
Expand Down
13 changes: 10 additions & 3 deletions app/tests/workers/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import unittest
from typing import Any, Awaitable

import pytest
from dramatiq.worker import Worker
from hexbytes import HexBytes
from sqlmodel.ext.asyncio.session import AsyncSession
Expand Down Expand Up @@ -54,12 +53,20 @@ def test_task_in_redis_queue(self):

class TestAsyncTasks(DbAsyncConn):

@pytest.mark.skip("Failing due dramatiq AsyncIO")
async def asyncSetUp(self):
await super().asyncSetUp()
self.worker = Worker(redis_broker)
self.worker.start()

async def asyncTearDown(self):
await super().asyncTearDown()
self.worker.stop()

@database_session
async def test_get_contract_metadata_task(self, session: AsyncSession):
contract_address = "0xd9Db270c1B5E3Bd161E8c8503c55cEABeE709552"
chain_id = 100
get_contract_metadata_task.send(contract_address, chain_id)
get_contract_metadata_task.fn(contract_address, chain_id)
contract = await Contract.get_contract(
session, HexBytes(contract_address), chain_id
)
Expand Down
4 changes: 3 additions & 1 deletion app/workers/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ async def get_contract_metadata_task(
) -> None:
contract_metadata_service = get_contract_metadata_service()
# Just try the first time, following retries should be scheduled
if contract_metadata_service.should_attempt_download(session, address, chain_id, 0):
if await contract_metadata_service.should_attempt_download(
session, address, chain_id, 0
):
logging.info(
f"Downloading contract metadata for {address} and chain {chain_id}"
)
Expand Down

0 comments on commit f80b643

Please sign in to comment.