MCPcopy
hub / github.com/python-trio/trio / test_WaitForSingleObject

Function test_WaitForSingleObject

src/trio/_tests/test_wait_for_object.py:136–167  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

134
135
136async def test_WaitForSingleObject() -> None:
137 # This does a series of test for setting/closing the handle before
138 # initiating the wait.
139
140 # Test already set
141 handle = kernel32.CreateEventA(ffi.NULL, True, False, ffi.NULL)
142 kernel32.SetEvent(handle)
143 await WaitForSingleObject(handle) # should return at once
144 kernel32.CloseHandle(handle)
145 print("test_WaitForSingleObject already set OK")
146
147 # Test already set, as int
148 handle = kernel32.CreateEventA(ffi.NULL, True, False, ffi.NULL)
149 handle_int = int(ffi.cast("intptr_t", handle))
150 kernel32.SetEvent(handle)
151 await WaitForSingleObject(handle_int) # should return at once
152 kernel32.CloseHandle(handle)
153 print("test_WaitForSingleObject already set OK")
154
155 # Test already closed
156 handle = kernel32.CreateEventA(ffi.NULL, True, False, ffi.NULL)
157 kernel32.CloseHandle(handle)
158 with pytest.raises(OSError, match=r"^\[WinError 6\] The handle is invalid$"):
159 await WaitForSingleObject(handle) # should return at once
160 print("test_WaitForSingleObject already closed OK")
161
162 # Not a handle
163 with pytest.raises(TypeError):
164 await WaitForSingleObject("not a handle") # type: ignore[arg-type] # Wrong type
165 # with pytest.raises(OSError):
166 # await WaitForSingleObject(99) # If you're unlucky, it actually IS a handle :(
167 print("test_WaitForSingleObject not a handle OK")
168
169
170@slow

Callers

nothing calls this directly

Calls 4

WaitForSingleObjectFunction · 0.85
CreateEventAMethod · 0.80
SetEventMethod · 0.80
CloseHandleMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…