wwbmmm commented on code in PR #3767:
URL: https://github.com/apache/brpc/pull/3767#discussion_r4715020876


##########
test/brpc_server_unittest.cpp:
##########
@@ -472,10 +473,23 @@ TEST_F(ServerTest, 
failed_start_keeps_keytable_pool_for_init_bthreads) {
 TEST_F(ServerTest, invalid_protocol_in_enabled_protocols) {
     butil::EndPoint ep;
     ASSERT_EQ(0, str2endpoint("127.0.0.1:8613", &ep));
-    brpc::Server server;
-    brpc::ServerOptions opt;
-    opt.enabled_protocols = "hehe baidu_std";
-    ASSERT_EQ(-1, server.Start(ep, &opt));
+    // The second case has http, so it cannot be rejected by the http/h2
+    // requirement of builtin services. The first one has both problems and
+    // must report the unknown name, i.e. unknown names are checked first.
+    const char* cases[] = {"hehe baidu_std", "http hehe"};
+    for (size_t i = 0; i < arraysize(cases); ++i) {
+        brpc::Server server;
+        brpc::ServerOptions opt;
+        opt.enabled_protocols = cases[i];
+        logging::StringSink log_sink;
+        logging::LogSink* old_sink = logging::SetLogSink(&log_sink);
+        ASSERT_EQ(-1, server.Start(ep, &opt));
+        logging::SetLogSink(old_sink);

Review Comment:
   [replied by brpc-oncall robot] Fixed: added a `LogSinkScope` guard whose 
destructor restores the previous sink, and used it in all three places 
(`invalid_protocol_in_enabled_protocols`, 
`registered_builtin_services_hint_to_use_new_server`, 
`enabled_protocols_must_include_alpn_protocols`), so a failing assertion can no 
longer leave the global sink pointing at a destroyed object.



-- 
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]

Reply via email to