Rémi Bernon (@rbernon) commented about dlls/cryptowinrt/tests/crypto.c:
WaitForSingleObject( bool_async_handler.event, 1000 );
check_bool_async( bool_async, 0, Completed, S_OK, FALSE );
check_interface( bool_async, &IID_IUnknown );
check_interface( bool_async, &IID_IInspectable );
check_interface( bool_async, &IID_IAgileObject );
check_interface( bool_async, &IID_IAsyncInfo );
check_interface( bool_async, &IID_IAsyncOperation_boolean );
check_runtimeclass( bool_async, L"Windows.Foundation.IAsyncOperation`1<Boolean>" );
hr = IAsyncOperation_boolean_get_Completed( bool_async, &tmp_handler );
ok( hr == S_OK, "get_Completed returned %#lx\n", hr );
ok( tmp_handler == NULL, "got handler %p\n", tmp_handler );
bool_async_handler = default_bool_async_handler;
hr = IAsyncOperation_boolean_put_Completed( bool_async, &bool_async_handler.IAsyncOperationCompletedHandler_boolean_iface );
ok( hr == S_OK, "put_Completed returned %#lx\n", hr );
Immediately after this call (though after checking hr) you need to wait on the `bool_async_handler.event` to make sure the operation has completed. Otherwise all the checks below will be racy.
Note that you will likely need to move the event creation before the call (and close the handle for cleanup, after the wait), because `bool_async_handler = default_bool_async_handler` will otherwise overwrite the event member.