Skip to content

Commit c6c7615

Browse files
authored
Move to a process global for test MemoryTracker (#4739)
I've seen about three or four different test failures due to `create_test_memory_tracker` returning new instances which leads to life time issues with the memory resources. This changes to a single process singleton to avoid the issue altogether. Once we merge the current PRs that are all using `create_test_memory_tracker` I'll follow up with a PR to rename all of those instances to `get_test_memory_tracker` and remove the `create_test_memory_tracker` to prevent further use. --- TYPE: NO_HISTORY DESC: Move to a process global for test MemoryTracker
1 parent c1e3427 commit c6c7615

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

test/support/src/mem_helpers.cc

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,25 @@
3535

3636
namespace tiledb::test {
3737

38-
shared_ptr<sm::MemoryTracker> create_test_memory_tracker() {
38+
shared_ptr<sm::MemoryTracker> get_test_memory_tracker() {
3939
class MemoryTrackerCreator : public sm::MemoryTracker {
4040
public:
4141
MemoryTrackerCreator()
4242
: sm::MemoryTracker() {
4343
}
44+
45+
static shared_ptr<MemoryTracker> get_instance() {
46+
static shared_ptr<MemoryTrackerCreator> tracker{
47+
new MemoryTrackerCreator()};
48+
return tracker;
49+
}
4450
};
4551

46-
return make_shared<MemoryTrackerCreator>(HERE());
52+
return MemoryTrackerCreator::get_instance();
53+
}
54+
55+
shared_ptr<sm::MemoryTracker> create_test_memory_tracker() {
56+
return get_test_memory_tracker();
4757
}
4858

4959
} // namespace tiledb::test

test/support/src/mem_helpers.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,18 @@
3838

3939
namespace tiledb::test {
4040

41+
/**
42+
* Helper function get the test instance of a shared_ptr<MemoryTracker>
43+
*
44+
* This is the preferred function. The create_test_memory_tracker will be
45+
* replaced shortly and only serves as a proxy to this function while we
46+
* transition the first few PRs to use this new function.
47+
*
48+
* The reasoning here is that creating memory trackers has turned out to be a
49+
* bit of a footgun with lifetime issues.
50+
*/
51+
shared_ptr<sm::MemoryTracker> get_test_memory_tracker();
52+
4153
/**
4254
* Helper function to create test instances of shared_ptr<MemoryTracker>
4355
*/

0 commit comments

Comments
 (0)