Skip to content

Commit

Permalink
Refactor WebSocket resource class (#14377)
Browse files Browse the repository at this point in the history
* Update Test Website JSON dependencies to .NET 8

* Implement WinRTWebSocketResource2

* Add /rnw/websockets/pong endpoint

* Add /rnw/websockets/echo endpoint

* Add WebSocketMultipleSendTest.js

* Allow arbitrary incoming size in server-side WebSocketTest

* Define runtime option WebSocket.ResourceV2

* Centralize ReceiveStringAsync in shared class WebSocketUtils

* Implement WebSocketMultipleSendTest_ClientReceive

* Prevent high CPU usage caused by WebSockets (test website)

* Allows passing an explicit calling context to execute resource handlers
(i.e. JavaScript queue / main queue).
  • Loading branch information
JunielKatarn authored Mar 6, 2025
1 parent 4640656 commit ca717fc
Show file tree
Hide file tree
Showing 27 changed files with 1,240 additions and 222 deletions.
18 changes: 17 additions & 1 deletion .ado/jobs/desktop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,34 @@ jobs:
#12714 - Disable for first deployment of test website.
# RNTesterIntegrationTests::WebSocket
# RNTesterIntegrationTests::WebSocketBlob
# RNTesterIntegrationTests::WebSocketMultipleSend
#14217 - Reneable RNTesterIntegrationTests
# RNTesterIntegrationTests::Dummy
# RNTesterIntegrationTests::Fetch
# RNTesterIntegrationTests::XHRSample
# RNTesterIntegrationTests::Blob
# RNTesterIntegrationTests::Logging
# - CI agents show the following server-side errors (local runs succeed):
# - [0x801901f4] Internal server error (500).
# - [0x800710dd] The operation identifier is not valid.
# WebSocketIntegrationTest::ConnectClose)&
# WebSocketIntegrationTest::ConnectNoClose)&
# WebSocketIntegrationTest::SendReceiveClose)&
# WebSocketIntegrationTest::SendConsecutive)&
# WebSocketIntegrationTest::SendReceiveLargeMessage)&
# WebSocketIntegrationTest::SendReceiveSsl)&
- name: Desktop.IntegrationTests.Filter
value: >
(FullyQualifiedName!=RNTesterIntegrationTests::IntegrationTestHarness)&
(FullyQualifiedName!=RNTesterIntegrationTests::WebSocket)&
(FullyQualifiedName!=RNTesterIntegrationTests::WebSocketBlob)&
(FullyQualifiedName!=WebSocketIntegrationTest::SendReceiveSsl)&
(FullyQualifiedName!=RNTesterIntegrationTests::WebSocketMultipleSend)&
(FullyQualifiedName!=Microsoft::React::Test::WebSocketIntegrationTest::ConnectClose)&
(FullyQualifiedName!=Microsoft::React::Test::WebSocketIntegrationTest::ConnectNoClose)&
(FullyQualifiedName!=Microsoft::React::Test::WebSocketIntegrationTest::SendReceiveClose)&
(FullyQualifiedName!=Microsoft::React::Test::WebSocketIntegrationTest::SendConsecutive)&
(FullyQualifiedName!=Microsoft::React::Test::WebSocketIntegrationTest::SendReceiveLargeMessage)&
(FullyQualifiedName!=Microsoft::React::Test::WebSocketIntegrationTest::SendReceiveSsl)&
(FullyQualifiedName!=Microsoft::React::Test::HttpOriginPolicyIntegrationTest)&
(FullyQualifiedName!=RNTesterIntegrationTests::Dummy)&
(FullyQualifiedName!=RNTesterIntegrationTests::Fetch)&
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "Refactor WebSocket resource class",
"packageName": "@office-iss/react-native-win32",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "Implement WinRTWebSocketResource2 stubs",
"packageName": "react-native-windows",
"email": "[email protected]",
"dependentChangeType": "patch"
}
4 changes: 2 additions & 2 deletions packages/@office-iss/react-native-win32/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
"@types/prop-types": "15.7.1",
"@types/react": "^19.0.0",
"eslint": "^8.19.0",
"flow-bin": "^0.257.1",
"flow-bin": "^0.258.1",
"jscodeshift": "^0.14.0",
"just-scripts": "^1.3.3",
"prettier": "2.8.8",
Expand Down Expand Up @@ -113,4 +113,4 @@
"engines": {
"node": ">= 18"
}
}
}
10 changes: 5 additions & 5 deletions vnext/Desktop.ABITests/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"type": "Direct",
"requested": "[1.0.2792.45, )",
"resolved": "1.0.2792.45",
"contentHash": "f5sc/vcAoTCTEW7Nqzp4galAuTRguZViw8ksn+Nx2uskEBPm0/ubzy6gVjvXS/P96jLS89C8T9I0hPc417xpNg=="
"contentHash": "KOlLJSq70OySfU8mdhWdh9iOyApazWsIb6CmSz+YTJ5MmwLcsCLMW0qemORo7Si3A7VhLDIH3jwpMhPxodfkuA=="
},
"Microsoft.Windows.CppWinRT": {
"type": "Direct",
Expand Down Expand Up @@ -128,7 +128,7 @@
"type": "Direct",
"requested": "[1.0.2792.45, )",
"resolved": "1.0.2792.45",
"contentHash": "f5sc/vcAoTCTEW7Nqzp4galAuTRguZViw8ksn+Nx2uskEBPm0/ubzy6gVjvXS/P96jLS89C8T9I0hPc417xpNg=="
"contentHash": "KOlLJSq70OySfU8mdhWdh9iOyApazWsIb6CmSz+YTJ5MmwLcsCLMW0qemORo7Si3A7VhLDIH3jwpMhPxodfkuA=="
},
"Microsoft.WindowsAppSDK": {
"type": "Transitive",
Expand All @@ -145,7 +145,7 @@
"type": "Direct",
"requested": "[1.0.2792.45, )",
"resolved": "1.0.2792.45",
"contentHash": "f5sc/vcAoTCTEW7Nqzp4galAuTRguZViw8ksn+Nx2uskEBPm0/ubzy6gVjvXS/P96jLS89C8T9I0hPc417xpNg=="
"contentHash": "KOlLJSq70OySfU8mdhWdh9iOyApazWsIb6CmSz+YTJ5MmwLcsCLMW0qemORo7Si3A7VhLDIH3jwpMhPxodfkuA=="
},
"Microsoft.WindowsAppSDK": {
"type": "Transitive",
Expand All @@ -162,7 +162,7 @@
"type": "Direct",
"requested": "[1.0.2792.45, )",
"resolved": "1.0.2792.45",
"contentHash": "f5sc/vcAoTCTEW7Nqzp4galAuTRguZViw8ksn+Nx2uskEBPm0/ubzy6gVjvXS/P96jLS89C8T9I0hPc417xpNg=="
"contentHash": "KOlLJSq70OySfU8mdhWdh9iOyApazWsIb6CmSz+YTJ5MmwLcsCLMW0qemORo7Si3A7VhLDIH3jwpMhPxodfkuA=="
},
"Microsoft.WindowsAppSDK": {
"type": "Transitive",
Expand All @@ -179,7 +179,7 @@
"type": "Direct",
"requested": "[1.0.2792.45, )",
"resolved": "1.0.2792.45",
"contentHash": "f5sc/vcAoTCTEW7Nqzp4galAuTRguZViw8ksn+Nx2uskEBPm0/ubzy6gVjvXS/P96jLS89C8T9I0hPc417xpNg=="
"contentHash": "KOlLJSq70OySfU8mdhWdh9iOyApazWsIb6CmSz+YTJ5MmwLcsCLMW0qemORo7Si3A7VhLDIH3jwpMhPxodfkuA=="
},
"Microsoft.WindowsAppSDK": {
"type": "Transitive",
Expand Down
2 changes: 1 addition & 1 deletion vnext/Desktop.DLL/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"Microsoft.Web.WebView2": {
"type": "Transitive",
"resolved": "1.0.2792.45",
"contentHash": "f5sc/vcAoTCTEW7Nqzp4galAuTRguZViw8ksn+Nx2uskEBPm0/ubzy6gVjvXS/P96jLS89C8T9I0hPc417xpNg=="
"contentHash": "KOlLJSq70OySfU8mdhWdh9iOyApazWsIb6CmSz+YTJ5MmwLcsCLMW0qemORo7Si3A7VhLDIH3jwpMhPxodfkuA=="
},
"Microsoft.Windows.SDK.BuildTools": {
"type": "Transitive",
Expand Down
12 changes: 12 additions & 0 deletions vnext/Desktop.IntegrationTests/RNTesterIntegrationTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ TEST_MODULE_INITIALIZE(InitModule) {
using Microsoft::React::SetRuntimeOptionBool;

SetRuntimeOptionBool("WebSocket.AcceptSelfSigned", true);
SetRuntimeOptionBool("WebSocket.ResourceV2", true); // Use WinRTWebSocketResource2

// WebSocketJSExecutor can't register native log hooks.
SetRuntimeOptionBool("RNTester.UseWebDebugger", false);
Expand Down Expand Up @@ -207,6 +208,17 @@ TEST_CLASS (RNTesterIntegrationTests) {
Assert::AreEqual(TestStatus::Passed, result.Status, result.Message.c_str());
}

///
// This test currently fails (skipped in CI).
// Sending multiple messages in sequence and immediately closing does not comply with the behavior described in
// https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/close
BEGIN_TEST_METHOD_ATTRIBUTE(WebSocketMultipleSend)
END_TEST_METHOD_ATTRIBUTE()
TEST_METHOD(WebSocketMultipleSend) {
auto result = m_runner.RunTest("IntegrationTests/WebSocketMultipleSendTest", "WebSocketMultipleSendTest");
Assert::AreEqual(TestStatus::Passed, result.Status, result.Message.c_str());
}

BEGIN_TEST_METHOD_ATTRIBUTE(Blob)
END_TEST_METHOD_ATTRIBUTE()
TEST_METHOD(Blob) {
Expand Down
Loading

0 comments on commit ca717fc

Please sign in to comment.