|
| 1 | +import pytest |
1 | 2 | from sentry_protos.taskbroker.v1.taskbroker_pb2 import TaskActivation |
2 | 3 |
|
3 | 4 | from taskbroker_client.app import TaskbrokerApp |
| 5 | +from taskbroker_client.retry import Retry |
4 | 6 | from taskbroker_client.router import TaskRouter |
| 7 | +from taskbroker_client.task import Task |
5 | 8 |
|
6 | 9 | from .conftest import StubAtMostOnce, producer_factory |
7 | 10 |
|
@@ -47,3 +50,50 @@ def test_should_attempt_at_most_once() -> None: |
47 | 50 | app.at_most_once_store(at_most) |
48 | 51 | assert app.should_attempt_at_most_once(activation) |
49 | 52 | assert not app.should_attempt_at_most_once(activation) |
| 53 | + |
| 54 | + |
| 55 | +def test_create_namespace() -> None: |
| 56 | + app = TaskbrokerApp(name="acme", producer_factory=producer_factory, router_class=StubRouter()) |
| 57 | + ns = app.create_namespace("test") |
| 58 | + assert ns.name == "test" |
| 59 | + assert ns.topic == "honk" |
| 60 | + |
| 61 | + retry = Retry(times=3) |
| 62 | + ns = app.create_namespace( |
| 63 | + "test-two", |
| 64 | + retry=retry, |
| 65 | + expires=60 * 10, |
| 66 | + processing_deadline_duration=60, |
| 67 | + app_feature="anvils", |
| 68 | + ) |
| 69 | + assert ns.default_retry == retry |
| 70 | + assert ns.default_processing_deadline_duration == 60 |
| 71 | + assert ns.default_expires == 60 * 10 |
| 72 | + assert ns.name == "test-two" |
| 73 | + assert ns.application == "acme" |
| 74 | + assert ns.topic == "honk" |
| 75 | + assert ns.app_feature == "anvils" |
| 76 | + |
| 77 | + fetched = app.get_namespace("test-two") |
| 78 | + assert fetched == ns |
| 79 | + |
| 80 | + with pytest.raises(KeyError): |
| 81 | + app.get_namespace("invalid") |
| 82 | + |
| 83 | + |
| 84 | +def test_get_task() -> None: |
| 85 | + app = TaskbrokerApp(name="acme", producer_factory=producer_factory, router_class=StubRouter()) |
| 86 | + ns = app.create_namespace(name="tests") |
| 87 | + |
| 88 | + @ns.register(name="test.simpletask") |
| 89 | + def simple_task() -> None: |
| 90 | + raise NotImplementedError |
| 91 | + |
| 92 | + task = app.get_task(ns.name, "test.simpletask") |
| 93 | + assert isinstance(task, Task) |
| 94 | + |
| 95 | + with pytest.raises(KeyError): |
| 96 | + app.get_task("nope", "test.simpletask") |
| 97 | + |
| 98 | + with pytest.raises(KeyError): |
| 99 | + app.get_task(ns.name, "nope") |
0 commit comments