chenBright commented on code in PR #3691:
URL: https://github.com/apache/brpc/pull/3691#discussion_r4426071689


##########
test/brpc_channel_unittest.cpp:
##########
@@ -3977,6 +3996,31 @@ class CountingSubChannel : public brpc::Channel {
 };
 int CountingSubChannel::s_alive = 0;
 
+TEST_F(ChannelTest, selective_channel_removal_prevents_revival) {
+    brpc::SelectiveChannel channel;
+    ASSERT_EQ(0, channel.Init("rr", nullptr));
+    brpc::SelectiveChannel::ChannelHandle handle;
+    ASSERT_EQ(0, channel.AddChannel(new CountingSubChannel, &handle));
+    ASSERT_EQ(1, CountingSubChannel::s_alive);
+    brpc::SocketUniquePtr ptr;
+    ASSERT_EQ(0, brpc::Socket::Address(handle.id, &ptr));
+
+    // Keep the HC reference but disable automatic scheduling: the retained
+    // pointer below simulates the health check task resuming after removal.
+    ptr->_is_hc_related_ref_held = false;
+    EXPECT_EQ(0, ptr->SetFailed());
+    ptr->_is_hc_related_ref_held = true;
+    channel.RemoveAndDestroyChannel(handle);
+    EXPECT_FALSE(ptr->HCEnabled());
+    ptr->Revive(1);
+    EXPECT_TRUE(ptr->Failed());
+    EXPECT_EQ(1, ptr->nref());
+    // Also clean up the leaked additional reference if this test regresses.

Review Comment:
   This is a deterministic white-box test. The flag is temporarily cleared 
around the synchronous `SetFailed()` call to suppress HC scheduling while 
preserving the actual HC reference. It is restored before removal and the 
subsequent manual revival attempt.
   
   A fixture helper could improve encapsulation, but adding a public production 
hook solely for this test is unnecessary. This is an optional improvement with 
low priority



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