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


##########
test/bvar_histogram_unittest.cpp:
##########
@@ -731,14 +732,33 @@ TEST_F(HistogramTest, window) {
 }
 
 TEST_F(HistogramTest, window_forgets_old_samples) {
+    // Own the unscheduled sampler until after h's destructor calls destroy().
+    std::unique_ptr<bvar::Histogram::sampler_type> sampler;
     bvar::Histogram h(bvar::Histogram::BucketSchema({10, 20, 30}));
+    sampler = std::make_unique<bvar::Histogram::sampler_type>(&h);
+    h._sampler = sampler.get();

Review Comment:
   The current setup already uses `std::unique_ptr` for ownership, and 
declaration order ensures destruction proceeds as window → histogram → sampler. 
The sampler remains alive through the histogram's destructor, including when an 
assertion fails.
   
   Since this setup is used by a single white-box test, I suggest keeping it 
local for now and extracting a helper if additional tests need it.



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