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


##########
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:
   This assertion can return from the test before 
`logging::SetLogSink(old_sink)` runs. The global sink then points at the 
stack-local `log_sink` after this test exits, so later logging uses a dangling 
sink. Restore the sink before asserting the result (or use an RAII guard).
   
   This issue also appears in the following locations of the same file:
   - line 810
   - line 825



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