Skip to content

Commit bf242c9

Browse files
committed
MB-61170: Release all allocated resources in memcached_statistics_tests
Initialize the required services before running the tests and shut them down before terminating. Change-Id: If76f400455d817924f0e1f54d12b5281801446d8 Reviewed-on: https://review.couchbase.org/c/kv_engine/+/207214 Tested-by: Build Bot <[email protected]> Reviewed-by: Vesko Karaganev <[email protected]>
1 parent d21a8c9 commit bf242c9

File tree

4 files changed

+35
-12
lines changed

4 files changed

+35
-12
lines changed

Diff for: tests/statistics/CMakeLists.txt

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
cb_add_test_executable(memcached_statistics_test
2-
prometheus_test.cc
3-
collector_test.cc)
2+
collector_test.cc
3+
main.cc
4+
prometheus_test.cc)
45
kv_enable_pch(memcached_statistics_test)
56
cb_enable_unity_build(memcached_statistics_test)
67
target_link_libraries(memcached_statistics_test
78
PRIVATE
89
GTest::gmock
9-
GTest::gtest_main
1010
memcached_daemon
1111
memcached_logger
1212
statistics)

Diff for: tests/statistics/main.cc

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright 2024-Present Couchbase, Inc.
3+
*
4+
* Use of this software is governed by the Business Source License included
5+
* in the file licenses/BSL-Couchbase.txt. As of the Change Date specified
6+
* in that file, in accordance with the Business Source License, use of this
7+
* software will be governed by the Apache License, Version 2.0, included in
8+
* the file licenses/APL2.txt.
9+
*/
10+
11+
#include <daemon/external_auth_manager_thread.h>
12+
#include <daemon/mcaudit.h>
13+
#include <folly/portability/GTest.h>
14+
#include <logger/logger.h>
15+
16+
int main(int argc, char** argv) {
17+
::testing::InitGoogleTest(&argc, argv);
18+
19+
cb::logger::createBlackholeLogger();
20+
21+
externalAuthManager = std::make_unique<ExternalAuthManagerThread>();
22+
initialize_audit();
23+
24+
int ret = RUN_ALL_TESTS();
25+
26+
externalAuthManager->shutdown();
27+
externalAuthManager->waitForState(Couchbase::ThreadState::Zombie);
28+
externalAuthManager.reset();
29+
shutdown_audit();
30+
cb::logger::shutdown();
31+
return ret;
32+
}

Diff for: tests/statistics/prometheus_test.cc

-7
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,6 @@
3333
#include <chrono>
3434
#include <vector>
3535

36-
void PrometheusStatTest::SetUpTestSuite() {
37-
if (!externalAuthManager) {
38-
externalAuthManager = std::make_unique<ExternalAuthManagerThread>();
39-
}
40-
}
41-
4236
PrometheusStatTest::EndpointMetrics PrometheusStatTest::getMetrics() const {
4337
EndpointMetrics metrics;
4438

@@ -53,7 +47,6 @@ PrometheusStatTest::EndpointMetrics PrometheusStatTest::getMetrics() const {
5347
TEST_F(PrometheusStatTest, auditStatsNotPerBucket) {
5448
// confirm audit stats are not labelled with a bucket - they are actually
5549
// global stats.
56-
initialize_audit();
5750
auto metrics = getMetrics();
5851
using namespace cb::stats;
5952
using namespace ::testing;

Diff for: tests/statistics/prometheus_test.h

-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,5 @@ class PrometheusStatTest : public CollectorTest {
3232
StatMap metering;
3333
};
3434

35-
static void SetUpTestSuite();
36-
3735
EndpointMetrics getMetrics() const;
3836
};

0 commit comments

Comments
 (0)