From 2ae866b59caab55afadb1531cc49705b0053c60e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Canna=C3=B2?= Date: Sat, 21 Mar 2026 21:25:52 +0100 Subject: [PATCH] Add query_cache_unit-t to build and init Prometheus registry - tests/unit/Makefile: Register query_cache_unit-t in the build system - test_init.cpp: Create a real Prometheus registry in test_init_query_ cache() since the Query_Cache constructor registers metrics via GloVars.prometheus_registry (nullptr would crash) --- test/tap/test_helpers/test_init.cpp | 7 +++++++ test/tap/tests/unit/Makefile | 7 ++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/test/tap/test_helpers/test_init.cpp b/test/tap/test_helpers/test_init.cpp index d555ba1ca..3266df5c8 100644 --- a/test/tap/test_helpers/test_init.cpp +++ b/test/tap/test_helpers/test_init.cpp @@ -81,6 +81,13 @@ int test_init_query_cache() { return 0; } + // The Query_Cache constructor registers Prometheus metrics via + // GloVars.prometheus_registry. Provide a real registry so the + // constructor doesn't crash on nullptr dereference. + if (GloVars.prometheus_registry == nullptr) { + GloVars.prometheus_registry = std::make_shared(); + } + GloMyQC = new MySQL_Query_Cache(); GloPgQC = new PgSQL_Query_Cache(); diff --git a/test/tap/tests/unit/Makefile b/test/tap/tests/unit/Makefile index 3b52fcd12..c56e4e2b6 100644 --- a/test/tap/tests/unit/Makefile +++ b/test/tap/tests/unit/Makefile @@ -231,7 +231,7 @@ $(ODIR)/test_init.o: $(TEST_HELPERS_DIR)/test_init.cpp | $(ODIR) # Unit test targets # =========================================================================== -UNIT_TESTS := smoke_test-t +UNIT_TESTS := smoke_test-t query_cache_unit-t .PHONY: all all: $(UNIT_TESTS) @@ -250,6 +250,11 @@ smoke_test-t: smoke_test-t.cpp $(TEST_HELPERS_OBJ) $(LIBPROXYSQLAR) $(LIBPROXYSQLAR_FULL) $(STATIC_LIBS) $(MYLIBS) \ $(ALLOW_MULTI_DEF) -o $@ +query_cache_unit-t: query_cache_unit-t.cpp $(TEST_HELPERS_OBJ) $(LIBPROXYSQLAR) + $(CXX) $< $(TEST_HELPERS_OBJ) $(IDIRS) $(LDIRS) $(OPT) \ + $(LIBPROXYSQLAR_FULL) $(STATIC_LIBS) $(MYLIBS) \ + $(ALLOW_MULTI_DEF) -o $@ + # =========================================================================== # Clean