[
https://issues.apache.org/jira/browse/DISPATCH-2103?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17440078#comment-17440078
]
ASF GitHub Bot commented on DISPATCH-2103:
------------------------------------------
jiridanek commented on a change in pull request #1425:
URL: https://github.com/apache/qpid-dispatch/pull/1425#discussion_r744308899
##########
File path: tests/c_unittests/test_listener_startup.cpp
##########
@@ -0,0 +1,173 @@
+/*
+ * 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.
+ */
+
+#include "./qdr_doctest.hpp"
+#include "./helpers.hpp" // must come after ./qdr_doctest.hpp
+
+#include <proton/listener.h>
+
+#include <regex>
+#include <thread>
+
+extern "C" {
+qd_listener_t *qd_dispatch_configure_listener(qd_dispatch_t *qd, qd_entity_t
*entity);
+void qd_connection_manager_delete_listener(qd_dispatch_t *qd, void *impl);
+}
+
+
+/// GCC 4.8 made a questionable choice to implement std::regex_search to always
+/// return false. Meaning that tests cannot use regex on RHEL 7
+static bool regex_is_broken() {
+ return !std::regex_search("", std::regex(""));
+}
+
+void check_amqp_listener_startup_log_message(qd_server_config_t config,
std::string listen, std::string stop)
+{
+ QDR qdr{};
+ CaptureCStream css(&stderr);
+ qdr.initialize("./minimal_trace.conf");
+
+ qd_listener_t *li = qd_server_listener(qdr.qd->server);
+ li->config = config;
+
+ CHECK(qd_listener_listen(li));
+ pn_listener_close(li->pn_listener);
+ {
+ /* AMQP socket is opened (and closed) only when proactor loop runs;
meaning router has to be started */
+ auto timer = qdr.schedule_stop(0);
+ qdr.run();
+ }
+
+ qd_listener_decref(li);
+ qdr.deinitialize();
+
+ std::string logging = css.str();
+ CHECK_MESSAGE(std::regex_search(logging, std::regex(listen)),
+ listen, " not found in ", logging);
+ CHECK_MESSAGE(std::regex_search(logging, std::regex(stop)),
+ stop, " not found in ", logging);
+}
+
+void check_http_listener_startup_log_message(qd_server_config_t config,
std::string listen, std::string stop, std::string failed)
+{
+ QDR qdr{};
+ CaptureCStream css(&stderr);
+ qdr.initialize("./minimal_trace.conf");
+
+ qd_listener_t *li = qd_server_listener(qdr.qd->server);
+ li->config = config;
+
+ const bool http_supported = qd_server_http(qdr.qd->server) != nullptr;
+
+ CHECK(qd_listener_listen(li) == http_supported);
+ qdr.wait();
+ qd_lws_listener_close(li->http);
+ qd_listener_decref(li);
+ {
+ auto timer = qdr.schedule_stop(0);
+ qdr.run();
+ }
+
+ qdr.deinitialize();
+
+ std::string logging = css.str();
+ CHECK_MESSAGE((logging.find("SERVER (warning) HTTP support is not
available") == std::string::npos) == http_supported,
+ listen, " (not) found in ", logging);
+
+ CHECK_MESSAGE(std::regex_search(logging, std::regex(listen)) ==
http_supported,
+ listen, " (not) found in ", logging);
+ CHECK_MESSAGE(std::regex_search(logging, std::regex(stop)) ==
http_supported,
+ stop, " (not) found in ", logging);
+
+ CHECK_MESSAGE(std::regex_search(logging, std::regex(failed)) !=
http_supported,
+ stop, " (not) found in ", logging);
+
+}
+
+TEST_CASE("Start AMQP listener with zero port" *
doctest::skip(regex_is_broken()))
+{
+ std::thread([] {
+ qd_server_config_t config{};
+ config.port = strdup("0");
+ config.host = strdup("localhost");
+ config.host_port = strdup("localhost:0");
+
+ check_amqp_listener_startup_log_message(
+ config,
+ R"EOS(SERVER \(notice\) Listening on
(127.0.0.1)|(::1):(\d\d+))EOS",
+ R"EOS(SERVER \(trace\) Listener closed on localhost:0)EOS"
+ );
+ }).join();
+}
+
+TEST_CASE("Start AMQP listener with zero port and a name" *
doctest::skip(regex_is_broken()))
+{
+ std::thread([] {
+ qd_server_config_t config{};
+ config.name = strdup("pepa");
+ config.port = strdup("0");
+ config.host = strdup("localhost");
+ config.host_port = strdup("localhost:0");
+
+ check_amqp_listener_startup_log_message(
+ config,
+ R"EOS(SERVER \(notice\) Listening on (127.0.0.1)|(::1):(\d\d+)
\(pepa\))EOS",
+ R"EOS(SERVER \(trace\) Listener closed on localhost:0)EOS"
+ );
+ }).join();
+}
+
+TEST_CASE("Start HTTP listener with zero port" *
doctest::skip(regex_is_broken()))
+{
+ std::thread([] {
+ qd_server_config_t config{};
+ config.port = strdup("0");
+ config.host = strdup("localhost");
+ config.host_port = strdup("localhost:0");
+ config.http = true;
+
+ check_http_listener_startup_log_message(
+ config,
+ R"EOS(SERVER \(notice\) Listening for HTTP on
localhost:(\d\d+))EOS",
+ R"EOS(SERVER \(notice\) Stopped listening for HTTP on
localhost:0)EOS",
+
+ R"EOS(SERVER \(error\) No HTTP support to listen on
localhost:0)EOS"
+ );
+ }).join();
+}
+
+TEST_CASE("Start HTTP listener with zero port and a name" *
doctest::skip(regex_is_broken()))
+{
+ std::thread([] {
+ qd_server_config_t config{};
+ config.name = strdup("pepa");
+ config.port = strdup("0");
+ config.host = strdup("localhost");
+ config.host_port = strdup("localhost:0");
+ config.http = true;
+
+ check_http_listener_startup_log_message(
+ config,
+ R"EOS(SERVER \(notice\) Listening for HTTP on
localhost:(\d\d+))EOS",
Review comment:
```suggestion
R"EOS(SERVER \(notice\) Listening for HTTP on localhost:(\d\d+)
\(pepa\))EOS",
```
--
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]
> Log the actual HTTP websocket listener port when 0 was specified in config
> --------------------------------------------------------------------------
>
> Key: DISPATCH-2103
> URL: https://issues.apache.org/jira/browse/DISPATCH-2103
> Project: Qpid Dispatch
> Issue Type: New Feature
> Affects Versions: 1.15.0
> Reporter: Jiri Daněk
> Assignee: Jiri Daněk
> Priority: Major
> Fix For: 1.19.0
>
>
> {code}
> if (hl->vhost) {
> /* Store hl pointer in vhost */
> void *vp = lws_protocol_vh_priv_zalloc(hl->vhost, &protocols[0],
> sizeof(hl));
> memcpy(vp, &hl, sizeof(hl));
> qd_log(hs->log, QD_LOG_NOTICE, "Listening for HTTP on %s",
> config->host_port);
> return;
> } else {
> qd_log(hs->log, QD_LOG_NOTICE, "Error listening for HTTP on %s",
> config->host_port);
> goto error;
> }
> return;
> {code}
--
This message was sent by Atlassian Jira
(v8.20.1#820001)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]