Skip to content

Commit 05ec494

Browse files
SimonSapinGeal
authored andcommitted
Fix running cargo test without nextest (#5266)
Reproduction: `cargo test -p apollo-federation -- -q` #5157 introduced a new kind of snapshot test for the Rust query planner. Test schemas are specified as sets of subgraph schemas, so composing them is needed. Since we don’t have composition in Rust yet, the tests rely on JS composition through Rover. To avoid a dependency on Rover on CI and for most contributors, the composed supergraph are cached in the repository. Rover use is opt-in and only required when a cached file is missing or out of date. (Composition inputs are hashed.) The file name is derived (through a macro) from the test function name. To detect name conflicts, a static `OnceLock<Mutex<HashSet<&'static str>>>` is used to ensure no name is used more than once. The static hash set relies on all snapshot tests running in the same process. This is the case with `cargo test`, but `cargo nextest run` as used on CI isolates every test in its own process. This breaks conflict detection of cache file names for composed supergraph schemas, since each test only "sees" itself in the static hash set. #5240 introduced a name conflict: composition is used in a function called twice with different arguments. Because nextest was used both locally and on CI, the conflict went undectected. As a result, running `cargo test` on dev fails because the conflict is detected. This PR fixes this case of cache file name conflict, but conflict detection is still broken with nextest. As a result it’s possible that this kind of conflict could happen again and be merged undectected. * Nextest has a notion of [test groups](https://nexte.st/book/test-groups), but they don’t appear to let multiple tests run in the same process * Instead of relying on the runtime side effect of tests, could conflict detection rely on enumerating tests at compile time? The [`linkme` crate](https://crates.io/crates/linkme) is a building block Router used to register Rust plugins. It could be used here in all composition inputs can be made const, but `std::any::type_name` used in a macro to extract the current function name is not `const fn` [yet](rust-lang/rust#63084) * Remove the cache and accept the dependency on Rover for testing. This impacts CI and all contributors. * Require every `planner!` macro invocation to specify an explicit cache file name instead of relying on the function name. Then conflict detection can use `linkme`. * Move conflict detection to a separate test that something something parses Rust source files of other tests something
1 parent 088d775 commit 05ec494

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Composed from subgraphs with hash: ca8bc5b745ab72ecb5d72159ed30d089d2084d77
2+
schema
3+
@link(url: "https://specs.apollo.dev/link/v1.0")
4+
@link(url: "https://specs.apollo.dev/join/v0.3", for: EXECUTION)
5+
{
6+
query: Query
7+
}
8+
9+
directive @join__enumValue(graph: join__Graph!) repeatable on ENUM_VALUE
10+
11+
directive @join__field(graph: join__Graph, requires: join__FieldSet, provides: join__FieldSet, type: String, external: Boolean, override: String, usedOverridden: Boolean) repeatable on FIELD_DEFINITION | INPUT_FIELD_DEFINITION
12+
13+
directive @join__graph(name: String!, url: String!) on ENUM_VALUE
14+
15+
directive @join__implements(graph: join__Graph!, interface: String!) repeatable on OBJECT | INTERFACE
16+
17+
directive @join__type(graph: join__Graph!, key: join__FieldSet, extension: Boolean! = false, resolvable: Boolean! = true, isInterfaceObject: Boolean! = false) repeatable on OBJECT | INTERFACE | UNION | ENUM | INPUT_OBJECT | SCALAR
18+
19+
directive @join__unionMember(graph: join__Graph!, member: String!) repeatable on UNION
20+
21+
directive @link(url: String, as: String, for: link__Purpose, import: [link__Import]) repeatable on SCHEMA
22+
23+
type A
24+
@join__type(graph: SUBGRAPH1)
25+
{
26+
x: Int
27+
y: Int
28+
}
29+
30+
scalar join__FieldSet
31+
32+
enum join__Graph {
33+
SUBGRAPH1 @join__graph(name: "Subgraph1", url: "none")
34+
}
35+
36+
scalar link__Import
37+
38+
enum link__Purpose {
39+
"""
40+
`SECURITY` features provide metadata necessary to securely resolve fields.
41+
"""
42+
SECURITY
43+
44+
"""
45+
`EXECUTION` features provide metadata necessary for operation execution.
46+
"""
47+
EXECUTION
48+
}
49+
50+
type Query
51+
@join__type(graph: SUBGRAPH1)
52+
{
53+
t: T
54+
}
55+
56+
type T
57+
@join__type(graph: SUBGRAPH1)
58+
{
59+
a1: A
60+
a2: A
61+
}

0 commit comments

Comments
 (0)