Copilot commented on code in PR #352: URL: https://github.com/apache/fluss-rust/pull/352#discussion_r2837005484
########## .github/workflows/check_license_and_formatting.yml: ########## @@ -0,0 +1,60 @@ +# 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. + +name: License and Formatting Check + +on: + push: + branches: + - main + paths-ignore: + - 'website/**' + - '**/*.md' + pull_request: + branches: + - main Review Comment: The pull_request trigger on line 27 doesn't have paths-ignore configured, unlike the push trigger. This means license and formatting checks will run on all PRs, even for changes to website or markdown files. Consider adding paths-ignore to the pull_request section for consistency with the push trigger. ```suggestion - main paths-ignore: - 'website/**' - '**/*.md' ``` ########## bindings/cpp/test/test_utils.h: ########## @@ -0,0 +1,315 @@ +/* + * 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. + */ + +#pragma once + +#include <gtest/gtest.h> + +#include <algorithm> +#include <chrono> +#include <cstdio> +#include <cstdlib> +#include <cstring> +#include <string> +#include <thread> +#include <vector> + +#ifdef _WIN32 +#include <winsock2.h> +#include <ws2tcpip.h> +#pragma comment(lib, "ws2_32.lib") +#else +#include <arpa/inet.h> +#include <netinet/in.h> +#include <sys/socket.h> +#include <unistd.h> +#endif + +#include "fluss.hpp" + +// Macro to assert Result is OK and print error message on failure +#define ASSERT_OK(result) ASSERT_TRUE((result).Ok()) << (result).error_message +#define EXPECT_OK(result) EXPECT_TRUE((result).Ok()) << (result).error_message + +namespace fluss_test { + +static constexpr const char* kFlussVersion = "0.7.0"; +static constexpr const char* kNetworkName = "fluss-cpp-test-network"; +static constexpr const char* kZookeeperName = "zookeeper-cpp-test"; +static constexpr const char* kCoordinatorName = "coordinator-server-cpp-test"; +static constexpr const char* kTabletServerName = "tablet-server-cpp-test"; +static constexpr int kCoordinatorPort = 9123; +static constexpr int kTabletServerPort = 9124; + +/// Execute a shell command and return its exit code. +inline int RunCommand(const std::string& cmd) { + return system(cmd.c_str()); +} + +/// Wait until a TCP port is accepting connections, or timeout. +inline bool WaitForPort(const std::string& host, int port, int timeout_seconds = 60) { + auto deadline = + std::chrono::steady_clock::now() + std::chrono::seconds(timeout_seconds); + + while (std::chrono::steady_clock::now() < deadline) { + int sock = socket(AF_INET, SOCK_STREAM, 0); + if (sock < 0) { + std::this_thread::sleep_for(std::chrono::milliseconds(500)); + continue; + } + + struct sockaddr_in addr {}; + addr.sin_family = AF_INET; + addr.sin_port = htons(static_cast<uint16_t>(port)); + inet_pton(AF_INET, host.c_str(), &addr.sin_addr); + + int result = connect(sock, reinterpret_cast<struct sockaddr*>(&addr), sizeof(addr)); +#ifdef _WIN32 + closesocket(sock); +#else + close(sock); +#endif + if (result == 0) { + return true; + } + + std::this_thread::sleep_for(std::chrono::milliseconds(500)); + } + return false; +} Review Comment: The Windows socket code path (lines 83-87) is not tested in CI since only Linux is used. On Windows, WSA must be initialized with WSAStartup before any socket operations, otherwise socket() and connect() will fail. Consider either: (1) adding WSAStartup/WSACleanup calls for Windows, (2) removing the Windows code if not needed, or (3) adding a comment noting this limitation. -- 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]
