Skip to content

Commit ca717fc

Browse files
authored
Refactor WebSocket resource class (#14377)
* 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).
1 parent 4640656 commit ca717fc

27 files changed

+1240
-222
lines changed

.ado/jobs/desktop.yml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,18 +75,34 @@ jobs:
7575
#12714 - Disable for first deployment of test website.
7676
# RNTesterIntegrationTests::WebSocket
7777
# RNTesterIntegrationTests::WebSocketBlob
78+
# RNTesterIntegrationTests::WebSocketMultipleSend
7879
#14217 - Reneable RNTesterIntegrationTests
7980
# RNTesterIntegrationTests::Dummy
8081
# RNTesterIntegrationTests::Fetch
8182
# RNTesterIntegrationTests::XHRSample
8283
# RNTesterIntegrationTests::Blob
8384
# RNTesterIntegrationTests::Logging
85+
# - CI agents show the following server-side errors (local runs succeed):
86+
# - [0x801901f4] Internal server error (500).
87+
# - [0x800710dd] The operation identifier is not valid.
88+
# WebSocketIntegrationTest::ConnectClose)&
89+
# WebSocketIntegrationTest::ConnectNoClose)&
90+
# WebSocketIntegrationTest::SendReceiveClose)&
91+
# WebSocketIntegrationTest::SendConsecutive)&
92+
# WebSocketIntegrationTest::SendReceiveLargeMessage)&
93+
# WebSocketIntegrationTest::SendReceiveSsl)&
8494
- name: Desktop.IntegrationTests.Filter
8595
value: >
8696
(FullyQualifiedName!=RNTesterIntegrationTests::IntegrationTestHarness)&
8797
(FullyQualifiedName!=RNTesterIntegrationTests::WebSocket)&
8898
(FullyQualifiedName!=RNTesterIntegrationTests::WebSocketBlob)&
89-
(FullyQualifiedName!=WebSocketIntegrationTest::SendReceiveSsl)&
99+
(FullyQualifiedName!=RNTesterIntegrationTests::WebSocketMultipleSend)&
100+
(FullyQualifiedName!=Microsoft::React::Test::WebSocketIntegrationTest::ConnectClose)&
101+
(FullyQualifiedName!=Microsoft::React::Test::WebSocketIntegrationTest::ConnectNoClose)&
102+
(FullyQualifiedName!=Microsoft::React::Test::WebSocketIntegrationTest::SendReceiveClose)&
103+
(FullyQualifiedName!=Microsoft::React::Test::WebSocketIntegrationTest::SendConsecutive)&
104+
(FullyQualifiedName!=Microsoft::React::Test::WebSocketIntegrationTest::SendReceiveLargeMessage)&
105+
(FullyQualifiedName!=Microsoft::React::Test::WebSocketIntegrationTest::SendReceiveSsl)&
90106
(FullyQualifiedName!=Microsoft::React::Test::HttpOriginPolicyIntegrationTest)&
91107
(FullyQualifiedName!=RNTesterIntegrationTests::Dummy)&
92108
(FullyQualifiedName!=RNTesterIntegrationTests::Fetch)&
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "prerelease",
3+
"comment": "Refactor WebSocket resource class",
4+
"packageName": "@office-iss/react-native-win32",
5+
"email": "julio.rocha@microsoft.com",
6+
"dependentChangeType": "patch"
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "prerelease",
3+
"comment": "Implement WinRTWebSocketResource2 stubs",
4+
"packageName": "react-native-windows",
5+
"email": "julio.rocha@microsoft.com",
6+
"dependentChangeType": "patch"
7+
}

packages/@office-iss/react-native-win32/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
"@types/prop-types": "15.7.1",
8585
"@types/react": "^19.0.0",
8686
"eslint": "^8.19.0",
87-
"flow-bin": "^0.257.1",
87+
"flow-bin": "^0.258.1",
8888
"jscodeshift": "^0.14.0",
8989
"just-scripts": "^1.3.3",
9090
"prettier": "2.8.8",
@@ -113,4 +113,4 @@
113113
"engines": {
114114
"node": ">= 18"
115115
}
116-
}
116+
}

vnext/Desktop.ABITests/packages.lock.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"type": "Direct",
1313
"requested": "[1.0.2792.45, )",
1414
"resolved": "1.0.2792.45",
15-
"contentHash": "f5sc/vcAoTCTEW7Nqzp4galAuTRguZViw8ksn+Nx2uskEBPm0/ubzy6gVjvXS/P96jLS89C8T9I0hPc417xpNg=="
15+
"contentHash": "KOlLJSq70OySfU8mdhWdh9iOyApazWsIb6CmSz+YTJ5MmwLcsCLMW0qemORo7Si3A7VhLDIH3jwpMhPxodfkuA=="
1616
},
1717
"Microsoft.Windows.CppWinRT": {
1818
"type": "Direct",
@@ -128,7 +128,7 @@
128128
"type": "Direct",
129129
"requested": "[1.0.2792.45, )",
130130
"resolved": "1.0.2792.45",
131-
"contentHash": "f5sc/vcAoTCTEW7Nqzp4galAuTRguZViw8ksn+Nx2uskEBPm0/ubzy6gVjvXS/P96jLS89C8T9I0hPc417xpNg=="
131+
"contentHash": "KOlLJSq70OySfU8mdhWdh9iOyApazWsIb6CmSz+YTJ5MmwLcsCLMW0qemORo7Si3A7VhLDIH3jwpMhPxodfkuA=="
132132
},
133133
"Microsoft.WindowsAppSDK": {
134134
"type": "Transitive",
@@ -145,7 +145,7 @@
145145
"type": "Direct",
146146
"requested": "[1.0.2792.45, )",
147147
"resolved": "1.0.2792.45",
148-
"contentHash": "f5sc/vcAoTCTEW7Nqzp4galAuTRguZViw8ksn+Nx2uskEBPm0/ubzy6gVjvXS/P96jLS89C8T9I0hPc417xpNg=="
148+
"contentHash": "KOlLJSq70OySfU8mdhWdh9iOyApazWsIb6CmSz+YTJ5MmwLcsCLMW0qemORo7Si3A7VhLDIH3jwpMhPxodfkuA=="
149149
},
150150
"Microsoft.WindowsAppSDK": {
151151
"type": "Transitive",
@@ -162,7 +162,7 @@
162162
"type": "Direct",
163163
"requested": "[1.0.2792.45, )",
164164
"resolved": "1.0.2792.45",
165-
"contentHash": "f5sc/vcAoTCTEW7Nqzp4galAuTRguZViw8ksn+Nx2uskEBPm0/ubzy6gVjvXS/P96jLS89C8T9I0hPc417xpNg=="
165+
"contentHash": "KOlLJSq70OySfU8mdhWdh9iOyApazWsIb6CmSz+YTJ5MmwLcsCLMW0qemORo7Si3A7VhLDIH3jwpMhPxodfkuA=="
166166
},
167167
"Microsoft.WindowsAppSDK": {
168168
"type": "Transitive",
@@ -179,7 +179,7 @@
179179
"type": "Direct",
180180
"requested": "[1.0.2792.45, )",
181181
"resolved": "1.0.2792.45",
182-
"contentHash": "f5sc/vcAoTCTEW7Nqzp4galAuTRguZViw8ksn+Nx2uskEBPm0/ubzy6gVjvXS/P96jLS89C8T9I0hPc417xpNg=="
182+
"contentHash": "KOlLJSq70OySfU8mdhWdh9iOyApazWsIb6CmSz+YTJ5MmwLcsCLMW0qemORo7Si3A7VhLDIH3jwpMhPxodfkuA=="
183183
},
184184
"Microsoft.WindowsAppSDK": {
185185
"type": "Transitive",

vnext/Desktop.DLL/packages.lock.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
"Microsoft.Web.WebView2": {
4444
"type": "Transitive",
4545
"resolved": "1.0.2792.45",
46-
"contentHash": "f5sc/vcAoTCTEW7Nqzp4galAuTRguZViw8ksn+Nx2uskEBPm0/ubzy6gVjvXS/P96jLS89C8T9I0hPc417xpNg=="
46+
"contentHash": "KOlLJSq70OySfU8mdhWdh9iOyApazWsIb6CmSz+YTJ5MmwLcsCLMW0qemORo7Si3A7VhLDIH3jwpMhPxodfkuA=="
4747
},
4848
"Microsoft.Windows.SDK.BuildTools": {
4949
"type": "Transitive",

vnext/Desktop.IntegrationTests/RNTesterIntegrationTests.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ TEST_MODULE_INITIALIZE(InitModule) {
2525
using Microsoft::React::SetRuntimeOptionBool;
2626

2727
SetRuntimeOptionBool("WebSocket.AcceptSelfSigned", true);
28+
SetRuntimeOptionBool("WebSocket.ResourceV2", true); // Use WinRTWebSocketResource2
2829

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

211+
///
212+
// This test currently fails (skipped in CI).
213+
// Sending multiple messages in sequence and immediately closing does not comply with the behavior described in
214+
// https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/close
215+
BEGIN_TEST_METHOD_ATTRIBUTE(WebSocketMultipleSend)
216+
END_TEST_METHOD_ATTRIBUTE()
217+
TEST_METHOD(WebSocketMultipleSend) {
218+
auto result = m_runner.RunTest("IntegrationTests/WebSocketMultipleSendTest", "WebSocketMultipleSendTest");
219+
Assert::AreEqual(TestStatus::Passed, result.Status, result.Message.c_str());
220+
}
221+
210222
BEGIN_TEST_METHOD_ATTRIBUTE(Blob)
211223
END_TEST_METHOD_ATTRIBUTE()
212224
TEST_METHOD(Blob) {

0 commit comments

Comments
 (0)