realm / realm-core

Core database component for the Realm Mobile Database SDKs
https://realm.io
Apache License 2.0
1.02k stars 165 forks source link

Add back missing test for 4003 "moved permanently" websocket response from server #7613

Open sync-by-unito[bot] opened 6 months ago

sync-by-unito[bot] commented 6 months ago

The latest updates to App and the app tests in Core master has removed the old testing for both a HTTP 308 and websocket 4003 error responses and only tests the HTTP 308 response. Update this test to include both types of return values from the server.

Original test: https://github.com/realm/realm-core/blob/4d815c6e6883bfdcb67cf755d0f0f29a4b399ea7/test/object-store/sync/app.cpp#L2988-L2996

    redir_provider->websocket_connect_func = [&logger, &connect_count]() -> std::optional<SocketProviderError> {
        logger->trace("websocket connect (%1)", ++connect_count);
        if (connect_count == 1)
            return SocketProviderError(sync::HTTPStatus::PermanentRedirect);
        if (connect_count == 2)
            return SocketProviderError(sync::websocket::WebSocketError::websocket_moved_permanently);
        return std::nullopt;
    };

Updated test: https://github.com/realm/realm-core/blob/master/test/object-store/sync/app.cpp#L3462-L3470

    socket_provider->websocket_connect_func = [&]() -> std::optional<SocketProviderError> {
        // Report a 308 response the first time we try to reconnect the websocket,
        // which should result in App performing a location update.
        // The actual Location header isn't used when we get a redirect on
        // the websocket, so we don't need to supply it here
        if (connect_count++ > 0)
            return std::nullopt;
        return sync::HTTPStatus::PermanentRedirect;
    };
sync-by-unito[bot] commented 6 months ago

➤ PM Bot commented:

Jira ticket: RCORE-2095

sync-by-unito[bot] commented 5 months ago

➤ michael-wb commented:

As a result of BAAS-31713, the 4003 redirect response for a websocket is going to be updated to be a 308 response when the initial "websocket connect" HTTP request is sent to the server. This test will need to validate that operation on the client.