Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Work around bug that was breaking q.empty() #1634

Merged
merged 1 commit into from
Apr 5, 2021
Merged
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
6 changes: 5 additions & 1 deletion ingestion-edge/ingestion_edge/publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,11 @@ def get_queue(config: dict) -> SQLiteAckQueue:
for key, value in config.items()
if key.startswith("QUEUE_")
}
return SQLiteAckQueue(**queue_config)
q: SQLiteAckQueue = SQLiteAckQueue(**queue_config, auto_resume=False)
q.resume_unack_tasks()
# work around https://github.com/peter-wangxu/persist-queue/pull/154
q.total = q._count()
return q


def init_app(app: Sanic) -> Tuple[PublisherClient, SQLiteAckQueue]:
Expand Down
10 changes: 8 additions & 2 deletions ingestion-edge/tests/unit/publish/test_init_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from ingestion_edge.config import Route
from sanic import Sanic
from sanic.request import Request
from unittest import mock
import pytest

ROUTE_TABLE = [
Expand Down Expand Up @@ -43,7 +44,7 @@ def app():
],
)
async def test_endpoint(app, kwargs, method, mocker, uri_bytes):
mocker.patch("ingestion_edge.publish.SQLiteAckQueue", dict)
Q = mocker.patch("ingestion_edge.publish.SQLiteAckQueue")
client = mocker.patch("ingestion_edge.publish.PublisherClient").return_value
mocker.patch("ingestion_edge.publish.submit", lambda _, **kw: kw)
app.config["ROUTE_TABLE"] = ROUTE_TABLE
Expand All @@ -52,7 +53,12 @@ async def test_endpoint(app, kwargs, method, mocker, uri_bytes):
request = Request(uri_bytes, {}, "1.1", method, None, app)
await app.handle_request(request, lambda r: responses.append(r), None)
assert responses == [
dict(client=client, q={"path": ":memory:"}, metadata_headers={}, **kwargs)
dict(client=client, q=Q.return_value, metadata_headers={}, **kwargs)
]
assert Q.mock_calls == [
mock.call(path=':memory:', auto_resume=False),
mock.call().resume_unack_tasks(),
mock.call()._count()
]


Expand Down