From 0b118889c44db3afe56d23263f73c67562dd7704 Mon Sep 17 00:00:00 2001 From: jhugard Date: Wed, 20 May 2026 14:40:49 -0700 Subject: [PATCH 1/3] Fix websocket connect test async result contract --- Tests/UnitTests/Tests/WebsocketTests.cpp | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/Tests/UnitTests/Tests/WebsocketTests.cpp b/Tests/UnitTests/Tests/WebsocketTests.cpp index 5a789650..44b46bc8 100644 --- a/Tests/UnitTests/Tests/WebsocketTests.cpp +++ b/Tests/UnitTests/Tests/WebsocketTests.cpp @@ -113,22 +113,32 @@ HRESULT CALLBACK Test_Internal_HCWebSocketConnectAsync( { UNREFERENCED_PARAMETER(uri); UNREFERENCED_PARAMETER(subProtocol); - UNREFERENCED_PARAMETER(websocket); - UNREFERENCED_PARAMETER(asyncBlock); UNREFERENCED_PARAMETER(context); UNREFERENCED_PARAMETER(env); // TODO bug - inconsistent behavior for websocket providers: Connect calls XAsyncBegin before // invoke the client handler, Send does not. - return XAsyncBegin(asyncBlock, nullptr, nullptr, __FUNCTION__, + return XAsyncBegin(asyncBlock, websocket, reinterpret_cast(HCWebSocketConnectAsync), __FUNCTION__, [](XAsyncOp op, const XAsyncProviderData* data) { + auto websocket = static_cast(data->context); + switch (op) { case XAsyncOp::Begin: { g_HCWebSocketConnect_Called = true; - XAsyncComplete(data->async, S_OK, 0); + XAsyncComplete(data->async, S_OK, sizeof(WebSocketCompletionResult)); + return S_OK; + } + case XAsyncOp::GetResult: + { + RETURN_HR_IF(E_NOT_SUFFICIENT_BUFFER, data->bufferSize < sizeof(WebSocketCompletionResult)); + + auto result = static_cast(data->buffer); + ZeroMemory(result, sizeof(WebSocketCompletionResult)); + result->errorCode = S_OK; + result->websocket = websocket; return S_OK; } default: return S_OK; @@ -151,7 +161,7 @@ HRESULT CALLBACK Test_Internal_HCWebSocketConnectAsyncAndClose( UNREFERENCED_PARAMETER(context); UNREFERENCED_PARAMETER(env); - return XAsyncBegin(asyncBlock, websocket, nullptr, __FUNCTION__, + return XAsyncBegin(asyncBlock, websocket, reinterpret_cast(HCWebSocketConnectAsync), __FUNCTION__, [](XAsyncOp op, const XAsyncProviderData* data) { auto websocket = static_cast(data->context); @@ -212,7 +222,7 @@ class TestWebSocketConnectAndCloseProvider : public IWebSocketProvider UNREFERENCED_PARAMETER(subprotocol); m_websocket = websocketHandle; - return XAsyncBegin(async, this, nullptr, __FUNCTION__, + return XAsyncBegin(async, this, reinterpret_cast(HCWebSocketConnectAsync), __FUNCTION__, [](XAsyncOp op, const XAsyncProviderData* data) { auto provider = static_cast(data->context); From e7b2e7661aeab65e258599e4e345dfa72e1214f6 Mon Sep 17 00:00:00 2001 From: jhugard Date: Wed, 20 May 2026 15:17:12 -0700 Subject: [PATCH 2/3] Update mock multi-match test for round-robin behavior --- Tests/UnitTests/Tests/MockTests.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Tests/UnitTests/Tests/MockTests.cpp b/Tests/UnitTests/Tests/MockTests.cpp index 505a0f47..8058edc7 100644 --- a/Tests/UnitTests/Tests/MockTests.cpp +++ b/Tests/UnitTests/Tests/MockTests.cpp @@ -270,12 +270,12 @@ DEFINE_TEST_CLASS(MockTests) VERIFY_ARE_EQUAL(E_OUTOFMEMORY, errCode); VERIFY_ARE_EQUAL(300, platErrCode); VERIFY_ARE_EQUAL(400, statusCode); - VERIFY_ARE_EQUAL_STR("Mock2", responseStr); + VERIFY_ARE_EQUAL_STR("Mock1", responseStr); VERIFY_ARE_EQUAL(S_OK, HCHttpCallCloseHandle(call)); } { - // Call 3 should repeat mock 2 + // Once multiple mocks are registered, matching calls cycle in registration order. VERIFY_ARE_EQUAL(S_OK, HCHttpCallCreate(&call)); VERIFY_ARE_EQUAL(S_OK, HCHttpCallRequestSetRetryAllowed(call, false)); VERIFY_ARE_EQUAL(S_OK, HCHttpCallRequestSetUrl(call, "1", "2")); From a56907b8b33343836712ec13733356e50d892d8e Mon Sep 17 00:00:00 2001 From: jhugard Date: Thu, 21 May 2026 12:47:57 -0700 Subject: [PATCH 3/3] Add websocket connect result assertion --- Tests/UnitTests/Tests/WebsocketTests.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Tests/UnitTests/Tests/WebsocketTests.cpp b/Tests/UnitTests/Tests/WebsocketTests.cpp index 44b46bc8..b33ef3e1 100644 --- a/Tests/UnitTests/Tests/WebsocketTests.cpp +++ b/Tests/UnitTests/Tests/WebsocketTests.cpp @@ -485,6 +485,10 @@ DEFINE_TEST_CLASS(WebsocketTests) XAsyncBlock asyncBlock{}; VERIFY_ARE_EQUAL(S_OK, HCWebSocketConnectAsync("test", "subProtoTest", websocket, &asyncBlock)); VERIFY_SUCCEEDED(XAsyncGetStatus(&asyncBlock, true)); + WebSocketCompletionResult connectResult{}; + VERIFY_ARE_EQUAL(S_OK, HCGetWebSocketConnectResult(&asyncBlock, &connectResult)); + VERIFY_ARE_EQUAL(S_OK, connectResult.errorCode); + VERIFY_IS_TRUE(connectResult.websocket == websocket); VERIFY_ARE_EQUAL(true, g_HCWebSocketConnect_Called); ZeroMemory(&asyncBlock, sizeof(XAsyncBlock));