martinzink commented on code in PR #1457:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1457#discussion_r1085095534
##########
libminifi/test/Utils.h:
##########
@@ -183,33 +188,54 @@ bool sendMessagesViaSSL(const
std::vector<std::string_view>& contents,
asio::error_code err;
socket.lowest_layer().connect(remote_endpoint, err);
if (err) {
- return false;
+ return err;
}
socket.handshake(asio::ssl::stream_base::client, err);
if (err) {
- return false;
+ return err;
}
for (auto& content : contents) {
std::string tcp_message(content);
tcp_message += '\n';
asio::write(socket, asio::buffer(tcp_message, tcp_message.size()), err);
if (err) {
- return false;
+ return err;
}
}
- return true;
+ return std::error_code();
}
#ifdef WIN32
inline std::error_code hide_file(const std::filesystem::path& file_name) {
- const bool success = SetFileAttributesA(file_name.string().c_str(),
FILE_ATTRIBUTE_HIDDEN);
- if (!success) {
- // note: All possible documented error codes from GetLastError are in
[0;15999] at the time of writing.
- // The below casting is safe in [0;std::numeric_limits<int>::max()], int
max is guaranteed to be at least 32767
- return { static_cast<int>(GetLastError()), std::system_category() };
- }
- return {};
+ const bool success = SetFileAttributesA(file_name.string().c_str(),
FILE_ATTRIBUTE_HIDDEN);
+ if (!success) {
+ // note: All possible documented error codes from GetLastError are in
[0;15999] at the time of writing.
+ // The below casting is safe in [0;std::numeric_limits<int>::max()], int
max is guaranteed to be at least 32767
+ return { static_cast<int>(GetLastError()), std::system_category() };
}
+ return {};
+}
#endif /* WIN32 */
+template<typename T>
+concept NetworkingProcessor = std::derived_from<T, minifi::core::Processor>
+ && requires(T x) {
+ {T::Port} -> std::convertible_to<core::Property>;
+ {x.getPort()} -> std::convertible_to<uint16_t>;
+ }; // NOLINT(readability/braces)
+
+template<NetworkingProcessor T>
+uint16_t scheduleProcessorOnRandomPort(const std::shared_ptr<TestPlan>&
test_plan, const std::shared_ptr<T>& processor) {
+ REQUIRE(processor->setProperty(T::Port, "0"));
+ test_plan->scheduleProcessor(processor);
+ uint16_t port = processor->getPort();
+ auto deadline = std::chrono::steady_clock::now() + 200ms;
+ while (port == 0 && deadline > std::chrono::steady_clock::now()) {
+ std::this_thread::sleep_for(20ms);
+ port = processor->getPort();
+ }
+ REQUIRE(port != 0);
+ return port;
Review Comment:
good idea, included this aswell in
https://github.com/apache/nifi-minifi-cpp/pull/1457/commits/f37cffb3fe783683d38646b198dfc38f7a439ce4#diff-eb32155f3c36cff6b7fb634b81ae2288627fae11502496cee252b9493e45bb4aR232-R233
--
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]