Skip to content

Commit 05fee44

Browse files
John Huggmeta-codesync[bot]
authored andcommitted
Fix OSS CI test and link coverage
Summary: Ensure OSS CI exercises a nonempty, backend-free Python test inventory instead of reporting a successful run with zero tests. Also repair the legacy Automake fbthrift static-link closure so external builds can link the mock server reliably. Reviewed By: anidev Differential Revision: D113608290 fbshipit-source-id: 5cd265c04f72bc37dfbc919511d2892f04d0cbf4
1 parent d6ab87f commit 05fee44

3 files changed

Lines changed: 143 additions & 35 deletions

File tree

CMake/mcrouter_test_config.py.in

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/usr/bin/env python3
2+
# Copyright (c) Meta Platforms, Inc. and affiliates.
3+
#
4+
# This source code is licensed under the MIT license found in the
5+
# LICENSE file in the root directory of this source tree.
6+
7+
8+
class ThriftTestClient:
9+
def __init__(self, addr, port) -> None:
10+
raise NotImplementedError
11+
12+
def sendVersion(self) -> str:
13+
raise NotImplementedError
14+
15+
16+
class McrouterGlobals:
17+
@staticmethod
18+
def binPath(name):
19+
bins = {
20+
"mcrouter": "@CMAKE_CURRENT_BINARY_DIR@/bin/mcrouter",
21+
}
22+
return bins[name]
23+
24+
@staticmethod
25+
def preprocessArgs(args):
26+
return args
27+
28+
@staticmethod
29+
def useThriftClient():
30+
return False
31+
32+
@staticmethod
33+
def createThriftTestClient(addr, port) -> ThriftTestClient:
34+
raise NotImplementedError

CMakeLists.txt

Lines changed: 85 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -573,9 +573,90 @@ install(
573573
# =============================================================================
574574
if(BUILD_TESTS)
575575
enable_testing()
576-
find_package(GTest CONFIG REQUIRED)
576+
include(FBPythonBinary)
577+
578+
set(MCROUTER_TEST_CONFIG_DIR "${CMAKE_CURRENT_BINARY_DIR}/python")
579+
file(MAKE_DIRECTORY "${MCROUTER_TEST_CONFIG_DIR}")
580+
configure_file(
581+
"${CMAKE_CURRENT_SOURCE_DIR}/CMake/mcrouter_test_config.py.in"
582+
"${MCROUTER_TEST_CONFIG_DIR}/config.py"
583+
@ONLY
584+
)
585+
586+
add_fb_python_library(
587+
mcrouter_test_config
588+
BASE_DIR "${MCROUTER_TEST_CONFIG_DIR}"
589+
NAMESPACE "mcrouter.test"
590+
SOURCES "${MCROUTER_TEST_CONFIG_DIR}/config.py"
591+
)
592+
593+
# JSON fixtures required by test_validate_config.py are referenced via
594+
# relative path "mcrouter/test/*.json" with WORKING_DIRECTORY set below.
595+
# In fbcode layout canonical JSONs live at fbcode/mcrouter/test/ (../test
596+
# from public_tld); in OSS after shipit they live at mcrouter/test/ in the
597+
# source tree. We copy them to binary dir only (no source-tree mutation)
598+
# and run tests with WORKING_DIRECTORY = binary dir so
599+
# "mcrouter/test/*.json" resolves in sandboxed/OSS executions.
600+
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/mcrouter/test")
601+
# fbcode layout: fbcode/mcrouter/test/ (../test from public_tld).
602+
set(_fbcode_test_dir "${CMAKE_CURRENT_SOURCE_DIR}/../test")
603+
# OSS layout (after shipit): fixtures vendored under mcrouter/test/.
604+
set(_oss_test_dir "${CMAKE_CURRENT_SOURCE_DIR}/mcrouter/test")
605+
if(EXISTS "${_fbcode_test_dir}/test_ascii.json"
606+
AND EXISTS "${_fbcode_test_dir}/invalid_config.json")
607+
file(
608+
COPY
609+
"${_fbcode_test_dir}/test_ascii.json"
610+
"${_fbcode_test_dir}/invalid_config.json"
611+
DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/mcrouter/test"
612+
)
613+
elseif(EXISTS "${_oss_test_dir}/test_ascii.json"
614+
AND EXISTS "${_oss_test_dir}/invalid_config.json")
615+
file(
616+
COPY
617+
"${_oss_test_dir}/test_ascii.json"
618+
"${_oss_test_dir}/invalid_config.json"
619+
DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/mcrouter/test"
620+
)
621+
else()
622+
message(WARNING
623+
"mcrouter test JSON fixtures (test_ascii.json, invalid_config.json) were "
624+
"not found under ../test or mcrouter/test. test_validate_config.py will "
625+
"fail with FileNotFoundError at runtime. Only test_validate_config.py "
626+
"depends on these fixtures; test_bad_params.py and test_linenumbers.py "
627+
"do not."
628+
)
629+
endif()
630+
631+
add_fb_python_unittest(
632+
mcrouter_oss_python_tests
633+
BASE_DIR "${CMAKE_CURRENT_SOURCE_DIR}"
634+
NAMESPACE ""
635+
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
636+
SOURCES
637+
mcrouter/test/test_bad_params.py
638+
mcrouter/test/test_linenumbers.py
639+
mcrouter/test/test_validate_config.py
640+
DEPENDS mcrouter_test_config
641+
)
577642

578-
# Add test subdirectories when ready
579-
# add_subdirectory(mcrouter/lib/test)
580-
# add_subdirectory(mcrouter/test)
643+
# Ensure mcrouter binary exists before Python tests that spawn it.
644+
# We avoid depending on the internal "${TARGET}.GEN_PY_EXE" name from
645+
# FBPythonBinary.cmake – it is an implementation detail that can change
646+
# across fbcode_builder revisions. Instead, make the
647+
# mcrouter_test_config.py_sources_built target (which add_fb_python_library
648+
# creates and which chains into the unittest exe build) depend on
649+
# mcrouter_server. That way ctest only runs after the server binary is
650+
# present. This target name is still an FBPythonBinary internal, so guard
651+
# on its existence too and fall back to a warning if the contract changes.
652+
if(TARGET mcrouter_server AND TARGET mcrouter_test_config.py_sources_built)
653+
add_dependencies(mcrouter_test_config.py_sources_built mcrouter_server)
654+
elseif(TARGET mcrouter_server)
655+
message(WARNING
656+
"Expected FBPythonBinary target mcrouter_test_config.py_sources_built "
657+
"was not found; cannot order the mcrouter_server build before the "
658+
"Python tests. Tests that spawn mcrouter may race the binary build if "
659+
"FBPythonBinary's internal target naming has changed."
660+
)
661+
endif()
581662
endif()

mcrouter/lib/network/test/Makefile.am

Lines changed: 24 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,36 @@ noinst_PROGRAMS = mock_mc_server
77
noinst_LIBRARIES = libtest_util.a
88
check_PROGRAMS = mcrouter_network_test
99

10-
mock_mc_server_SOURCES = \
11-
MockMc.cpp \
12-
MockMc.h \
13-
MockMcOnRequest.h \
14-
MockMcServer.cpp
15-
mock_mc_server_CPPFLAGS = -I$(top_srcdir)/..
16-
# Link order matters.
17-
mock_mc_server_LDADD = \
18-
$(top_builddir)/lib/libmcrouter.a \
10+
FBTHRIFT_STATIC_LIBS = \
11+
-Wl,--start-group \
1912
-lthriftcpp2 \
2013
-lserverdbginfo \
2114
-ltransport \
2215
-lthriftanyrep \
16+
-lthriftannotation \
2317
-lthrifttype \
2418
-lthrifttyperep \
25-
-lthriftprotocol \
19+
-lthrift_dynamic_value \
2620
-lrpcmetadata \
21+
-lthriftprotocol \
2722
-lthriftmetadata \
2823
-lasync \
2924
-lconcurrency \
3025
-lruntime \
3126
-lthrift-core \
3227
-lcommon \
28+
-Wl,--end-group
29+
30+
mock_mc_server_SOURCES = \
31+
MockMc.cpp \
32+
MockMc.h \
33+
MockMcOnRequest.h \
34+
MockMcServer.cpp
35+
mock_mc_server_CPPFLAGS = -I$(top_srcdir)/..
36+
# Link order matters.
37+
mock_mc_server_LDADD = \
38+
$(top_builddir)/lib/libmcrouter.a \
39+
$(FBTHRIFT_STATIC_LIBS) \
3340
-lfmt \
3441
-lfizz \
3542
-lwangle \
@@ -44,14 +51,7 @@ mock_mc_thrift_server_CPPFLAGS = -I$(top_srcdir)/..
4451
# Link order matters.
4552
mock_mc_thrift_server_LDADD = \
4653
$(top_builddir)/lib/libmcrouter.a \
47-
-lthriftcpp2 \
48-
-ltransport \
49-
-lthriftprotocol \
50-
-lrpcmetadata \
51-
-lasync \
52-
-lconcurrency \
53-
-lthrift-core \
54-
-lcommon \
54+
$(FBTHRIFT_STATIC_LIBS) \
5555
-lfmt \
5656
-lfizz \
5757
-lwangle \
@@ -66,14 +66,11 @@ mock_mc_server_dual_CPPFLAGS = -I$(top_srcdir)/..
6666
# Link order matters.
6767
mock_mc_server_dual_LDADD = \
6868
$(top_builddir)/lib/libmcrouter.a \
69-
-lthriftcpp2 \
70-
-ltransport \
71-
-lthriftprotocol \
72-
-lrpcmetadata \
73-
-lasync \
74-
-lconcurrency \
75-
-lthrift-core \
76-
-lcommon
69+
$(FBTHRIFT_STATIC_LIBS) \
70+
-lfmt \
71+
-lfizz \
72+
-lwangle \
73+
-lfolly
7774

7875
libtest_util_a_SOURCES = \
7976
ClientSocket.cpp \
@@ -110,8 +107,4 @@ mcrouter_network_test_LDADD = \
110107
$(top_builddir)/lib/libmcrouter.a \
111108
$(top_builddir)/lib/libtestmain.la \
112109
$(top_builddir)/lib/network/libtest_util.a \
113-
-lthriftcpp2 \
114-
-lthriftprotocol \
115-
-lrpcmetadata \
116-
-ltransport \
117-
-lcommon
110+
$(FBTHRIFT_STATIC_LIBS)

0 commit comments

Comments
 (0)