forked from temporalio/sdk-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_runtime.py
More file actions
40 lines (30 loc) · 928 Bytes
/
Copy pathtest_runtime.py
File metadata and controls
40 lines (30 loc) · 928 Bytes
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
from threading import Event, Thread
from time import sleep
from typing import Optional
from temporalio.bridge.runtime import Runtime
class SomeException(Exception):
pass
def test_bridge_runtime_raise_in_thread():
waiting = Event()
exc_in_thread: Optional[BaseException] = None
def wait_forever():
try:
waiting.set()
while True:
sleep(0.1)
except BaseException as err:
nonlocal exc_in_thread
exc_in_thread = err
# Start thread
thread = Thread(target=wait_forever, daemon=True)
thread.start()
# Wait until sleeping
waiting.wait(5)
# Raise exception
assert thread.ident
assert thread.is_alive()
assert Runtime._raise_in_thread(thread.ident, SomeException)
# Make sure thread completes
thread.join(5)
assert not thread.is_alive()
assert type(exc_in_thread) is SomeException