forked from temporalio/samples-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhello_change_log_level_test.py
More file actions
42 lines (33 loc) · 1.04 KB
/
hello_change_log_level_test.py
File metadata and controls
42 lines (33 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import asyncio
import io
import logging
import uuid
from temporalio.client import Client
from temporalio.worker import Worker
from hello.hello_change_log_level import LOG_MESSAGE, GreetingWorkflow
async def test_workflow_with_log_capture(client: Client):
log_stream = io.StringIO()
handler = logging.StreamHandler(log_stream)
handler.setLevel(logging.ERROR)
logger = logging.getLogger()
logger.addHandler(handler)
logger.setLevel(logging.DEBUG)
task_queue = f"tq-{uuid.uuid4()}"
async with Worker(
client,
task_queue=task_queue,
workflows=[GreetingWorkflow],
):
handle = await client.start_workflow(
GreetingWorkflow.run,
id=f"wf-{uuid.uuid4()}",
task_queue=task_queue,
)
await asyncio.sleep(
0.2
) # small wait to ensure the workflow has started, failed, and logged
await handle.terminate()
logger.removeHandler(handler)
handler.flush()
logs = log_stream.getvalue()
assert LOG_MESSAGE in logs