Skip to content

Commit

Permalink
Prevent race condition in ConnectSucceeds WS unit test (#14405)
Browse files Browse the repository at this point in the history
* Prevent race condition in ConnectSucceeds

* Change files
  • Loading branch information
JunielKatarn authored Mar 7, 2025
1 parent 782335b commit 1ebf0e8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "Prevent race condition in ConnectSucceeds",
"packageName": "react-native-windows",
"email": "[email protected]",
"dependentChangeType": "patch"
}
6 changes: 4 additions & 2 deletions vnext/Desktop.UnitTests/WinRTWebSocketResourceUnitTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,21 @@ TEST_CLASS (WinRTWebSocketResourceUnitTest) {
auto imws{winrt::make<MockMessageWebSocket>()};

// Set up mocks
auto callingQueue = Mso::DispatchQueue::MakeSerialQueue();
auto mws{imws.as<MockMessageWebSocket>()};
// TODO: Mock Control()
mws->Mocks.ConnectAsync = [](const Uri &) -> IAsyncAction { return DoNothingAsync(); };

// Test APIs
auto rc = make_shared<WinRTWebSocketResource2>(
std::move(imws), MockDataWriter{}, CertExceptions{}, Mso::DispatchQueue::MakeSerialQueue());
auto rc = make_shared<WinRTWebSocketResource2>(std::move(imws), MockDataWriter{}, CertExceptions{}, callingQueue);
rc->SetOnConnect([&connected]() { connected = true; });
rc->SetOnError([&errorMessage](Error &&error) { errorMessage = error.Message; });

rc->Connect(testUrl, {}, {});
rc->Close(CloseCode::Normal, {});

callingQueue.AwaitTermination();

Assert::AreEqual({}, errorMessage);
Assert::IsTrue(connected);
}
Expand Down

0 comments on commit 1ebf0e8

Please sign in to comment.