empiredan commented on code in PR #1583: URL: https://github.com/apache/incubator-pegasus/pull/1583#discussion_r1335367313
########## src/http/test/http_client_test.cpp: ########## @@ -0,0 +1,122 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +// IWYU pragma: no_include <gtest/gtest-message.h> +// IWYU pragma: no_include <gtest/gtest-param-test.h> +// IWYU pragma: no_include <gtest/gtest-test-part.h> +#include <gtest/gtest.h> +#include <iostream> +#include <string> +#include <vector> + +#include "http/http_client.h" +#include "http/http_method.h" +#include "utils/error_code.h" +#include "utils/errors.h" +#include "utils/fmt_logging.h" + +namespace dsn { + +TEST(HttpClientTest, Connect) +{ + http_client client; + ASSERT_TRUE(client.init()); + + // No one has listened on port 20000, thus this would lead to "Connection refused". + ASSERT_TRUE(client.set_url("http://127.0.0.1:20000/test/get")); + + const auto &err = client.do_method(); + ASSERT_EQ(dsn::ERR_CURL_FAILED, err.code()); + + // Would print something like "Failed to connect to 127.0.0.1 port 20000: Connection refused". + std::cout << "failed to connect: " << err.description() << std::endl; Review Comment: OK, I've added check for the prefixes of descriptions, since the postfixes differ in various systems, such as: ``` [ RUN ] HttpClientTest.Connect failed to connect: ERR_CURL_FAILED: failed to perform http request(method=GET, url=http://127.0.0.1:20000/test/get): desc="Couldn't connect to server", msg="Failed to connect to 127.0.0.1 port 20000 after 0 ms: Connection refused" /__w/incubator-pegasus/incubator-pegasus/src/http/test/http_client_test.cpp:50: Failure Expected: expected_description Which is: "ERR_CURL_FAILED: failed to perform http request(method=GET, url=http://127.0.0.1:20000/test/get): desc=\"Couldn't connect to server\", msg=\"Failed to connect to 127.0.0.1 port 20000: Connection refused\"" To be equal to: err.description() Which is: "ERR_CURL_FAILED: failed to perform http request(method=GET, url=http://127.0.0.1:20000/test/get): desc=\"Couldn't connect to server\", msg=\"Failed to connect to 127.0.0.1 port 20000 after 0 ms: Connection refused\"" [ FAILED ] HttpClientTest.Connect (147 ms) ``` ``` [ RUN ] HttpClientTest.Callback failed for callback: ERR_CURL_WRITE_ERROR: failed to perform http request(method=GET, url=http://127.0.0.1:20001/test/get): code=23, desc="Failed writing received data to disk/application", msg="Failure writing output to destination" /__w/incubator-pegasus/incubator-pegasus/src/http/test/http_client_test.cpp:[82](https://github.com/apache/incubator-pegasus/actions/runs/6275190095/job/17045034248?pr=1583#step:7:83): Failure Expected: expected_description Which is: "ERR_CURL_WRITE_ERROR: failed to perform http request(method=GET, url=http://127.0.0.1:20001/test/get): code=23, desc=\"Failed writing received data to disk/application\", msg=\"Failed writing body (18446744073709551615 != 24)\"" To be equal to: actual_description Which is: "ERR_CURL_WRITE_ERROR: failed to perform http request(method=GET, url=http://127.0.0.1:20001/test/get): code=23, desc=\"Failed writing received data to disk/application\", msg=\"Failure writing output to destination\"" [ FAILED ] HttpClientTest.Callback (2 ms) ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
