Skip to content

Commit 7a9eeeb

Browse files
autarchclaude
andcommitted
Add a new sharded test type for sharded cluster integration tests
This adds anew `TOOLS_TESTING_SHARDED_INTEGRATION` test type, wires it up in the build script via -topology=sharded, adds a "create sharded cluster" Evergreen function (mirroring "create repl_set" but using ShardingTest), and adds integration-X.Y-sharded tasks for all server versions that have cluster tasks (4.4 through latest). Co-Authored-By: Claude Code <noreply@anthropic.com>
1 parent 22b912b commit 7a9eeeb

6 files changed

Lines changed: 1049 additions & 1 deletion

File tree

.ai-plans/2026-03-13/js-to-go-test-migration/plan.md

Lines changed: 866 additions & 0 deletions
Large diffs are not rendered by default.

build.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ func init() {
6666
Description("runs all integration tests").
6767
OptionalArgs("pkgs", "ssl", "auth", "kerberos", "topology", "race").
6868
Do(buildscript.TestIntegration)
69+
taskRegistry.Declare("test:sharded-integration").
70+
Description("runs tests requiring a sharded cluster topology").
71+
OptionalArgs("pkgs", "ssl", "race").
72+
Do(buildscript.TestShardedIntegration)
6973
taskRegistry.Declare("test:kerberos").
7074
Description("runs all kerberos tests").
7175
OptionalArgs("race").

buildscript/build.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,13 @@ func TestIntegration(ctx *task.Context) error {
121121
return runTests(ctx, selectedPkgs(ctx), testtype.IntegrationTestType)
122122
}
123123

124+
// TestShardedIntegration runs tests that require a sharded cluster (mongos) topology.
125+
// It sets only ShardedIntegrationTestType, intentionally not setting IntegrationTestType,
126+
// so regular integration tests (which expect a standalone mongod) are not run against mongos.
127+
func TestShardedIntegration(ctx *task.Context) error {
128+
return runTests(ctx, selectedPkgs(ctx), testtype.ShardedIntegrationTestType)
129+
}
130+
124131
// TestAWSAuth is an Executor that runs all AWS auth tests for the provided packages.
125132
func TestAWSAuth(ctx *task.Context) error {
126133
return runTests(ctx, selectedPkgs(ctx), testtype.AWSAuthTestType)
@@ -190,6 +197,9 @@ func runTests(ctx *task.Context, pkgs []string, testType string) error {
190197
if ctx.Get("topology") == "replSet" {
191198
env = append(env, testtype.ReplSetTestType+"=true")
192199
}
200+
if ctx.Get("topology") == "sharded" {
201+
env = append(env, testtype.ShardedIntegrationTestType+"=true")
202+
}
193203

194204
if ctx.Get("race") == "true" {
195205
args = append(args, "-race")

common.yml

Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,33 @@ functions:
461461
fi;
462462
./bin/mongo $MONGO_ARGS --nodb --eval 'assert.soon(function(x){try{var d = new Mongo("localhost:${mongod_port}"); return true} catch(e){return false}}, "timed out connection")'
463463
464+
"create sharded cluster":
465+
- command: shell.exec
466+
params:
467+
working_dir: src/github.com/mongodb/mongo-tools
468+
background: true
469+
script: |
470+
set -x
471+
set -v
472+
set -e
473+
echo "starting sharded cluster"
474+
mkdir -p /data/db/
475+
# use jsconfig.json to set baseUrl to find libs
476+
mv test/shell_common/jsconfig.json ./
477+
if [ -n "${load_libs_version}" ]; then
478+
IMPORT_LOAD_LIBS="await import(\"../shell_common/libs/load_libs-${load_libs_version}.js\");"
479+
fi
480+
PATH=./bin:$PATH ./bin/mongo --port ${mongod_port} --nodb --eval "$IMPORT_LOAD_LIBS; var st = new ShardingTest({name: \"tools_sharded_cluster\", shards: 1, mongos: [{port: ${mongod_port}}], other: {rsOptions: {}, configOptions: {}}}); while(true){sleep(1000);}"
481+
482+
- command: shell.exec
483+
params:
484+
working_dir: src/github.com/mongodb/mongo-tools
485+
script: |
486+
set -x
487+
set -v
488+
set -e
489+
./bin/mongo --port ${mongod_port} --nodb --eval 'assert.soon(function(x){try{var d = new Mongo("localhost:${mongod_port}"); return true} catch(e){return false}}, "timed out connection")'
490+
464491
"add-aws-auth-variables-to-file":
465492
- command: shell.exec
466493
type: test
@@ -1523,6 +1550,140 @@ tasks:
15231550
vars:
15241551
target: test:integration -ssl=true -topology=replSet ${testArgs}
15251552

1553+
- name: integration-4.4-sharded
1554+
tags: ["4.4", "sharded"]
1555+
commands:
1556+
- func: "fetch source"
1557+
- command: expansions.update
1558+
- func: "download mongod and shell"
1559+
vars:
1560+
mongo_version: "4.4"
1561+
- func: "create sharded cluster"
1562+
- func: "run make target"
1563+
vars:
1564+
target: build
1565+
- func: "run make target"
1566+
vars:
1567+
target: test:sharded-integration ${testArgs}
1568+
1569+
- name: integration-5.0-sharded
1570+
tags: ["5.0", "sharded"]
1571+
commands:
1572+
- func: "fetch source"
1573+
- command: expansions.update
1574+
- func: "download mongod and shell"
1575+
vars:
1576+
mongo_version: "5.0"
1577+
- func: "create sharded cluster"
1578+
- func: "run make target"
1579+
vars:
1580+
target: build
1581+
- func: "run make target"
1582+
vars:
1583+
target: test:sharded-integration ${testArgs}
1584+
1585+
- name: integration-6.0-sharded
1586+
tags: ["6.0", "sharded"]
1587+
commands:
1588+
- func: "fetch source"
1589+
- command: expansions.update
1590+
- func: "download mongod and shell"
1591+
vars:
1592+
mongo_version: "6.0"
1593+
- func: "create sharded cluster"
1594+
- func: "run make target"
1595+
vars:
1596+
target: build
1597+
- func: "run make target"
1598+
vars:
1599+
target: test:sharded-integration ${testArgs}
1600+
1601+
- name: integration-7.0-sharded
1602+
tags: ["7.0", "sharded"]
1603+
commands:
1604+
- func: "fetch source"
1605+
- command: expansions.update
1606+
- func: "download mongod and shell"
1607+
vars:
1608+
mongo_version: "7.0"
1609+
- func: "create sharded cluster"
1610+
- func: "run make target"
1611+
vars:
1612+
target: build
1613+
- func: "run make target"
1614+
vars:
1615+
target: test:sharded-integration ${testArgs}
1616+
1617+
- name: integration-8.0-sharded
1618+
tags: ["8.0", "sharded"]
1619+
commands:
1620+
- func: "fetch source"
1621+
- command: expansions.update
1622+
- func: "download mongod and shell"
1623+
vars:
1624+
mongo_version: "8.0"
1625+
- func: "create sharded cluster"
1626+
- func: "run make target"
1627+
vars:
1628+
target: build
1629+
- func: "run make target"
1630+
vars:
1631+
target: test:sharded-integration ${testArgs}
1632+
1633+
- name: integration-8.1-sharded
1634+
tags: ["8.1", "sharded"]
1635+
commands:
1636+
- func: "fetch source"
1637+
- command: expansions.update
1638+
- func: "download mongod and shell"
1639+
vars:
1640+
mongo_version: "8.1.0"
1641+
- func: "create sharded cluster"
1642+
vars:
1643+
load_libs_version: "8.1"
1644+
- func: "run make target"
1645+
vars:
1646+
target: build
1647+
- func: "run make target"
1648+
vars:
1649+
target: test:sharded-integration ${testArgs}
1650+
1651+
- name: integration-8.2-sharded
1652+
tags: ["8.2", "sharded"]
1653+
commands:
1654+
- func: "fetch source"
1655+
- command: expansions.update
1656+
- func: "download mongod and shell"
1657+
vars:
1658+
mongo_version: "8.2.0"
1659+
- func: "create sharded cluster"
1660+
vars:
1661+
load_libs_version: "8.2"
1662+
- func: "run make target"
1663+
vars:
1664+
target: build
1665+
- func: "run make target"
1666+
vars:
1667+
target: test:sharded-integration ${testArgs}
1668+
1669+
- name: integration-latest-sharded
1670+
tags: ["latest", "sharded"]
1671+
commands:
1672+
- func: "fetch source"
1673+
- command: expansions.update
1674+
- func: "download mongod and shell"
1675+
vars:
1676+
mongo_version: "latest"
1677+
- func: "create sharded cluster"
1678+
vars:
1679+
load_libs_version: *max_server_version
1680+
- func: "run make target"
1681+
vars:
1682+
target: build
1683+
- func: "run make target"
1684+
vars:
1685+
target: test:sharded-integration ${testArgs}
1686+
15261687
- name: aws-auth-latest
15271688
tags: ["latest", "aws-auth"]
15281689
commands:

common/testtype/types.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ const (
1818
// First checks for a URI for a Mongod in the env variable TOOLS_TESTING_MONGOD. If it does not find it, looks on localhost:33333.
1919
IntegrationTestType = "TOOLS_TESTING_INTEGRATION"
2020

21+
// Testing the tools against a sharded cluster (mongos) topology.
22+
ShardedIntegrationTestType = "TOOLS_TESTING_SHARDED_INTEGRATION"
23+
2124
// Unit tests don't require a real mongod. They may still do file I/O.
2225
UnitTestType = "TOOLS_TESTING_UNIT"
2326

precious.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66
# for example from editors on save. Slower tidiers should only be invoked manually, either by
77
# running the relevant mage command or by explicitly running `precious` from the CLI.
88

9-
exclude = "vendor/**/*"
9+
exclude = [
10+
".ai-plans/**/*",
11+
"vendor/**/*",
12+
]
1013

1114
[commands.golangci-lint]
1215
type = "both"
@@ -96,6 +99,7 @@ invoke = "once"
9699
working-dir = "root"
97100
path-args = "file"
98101
include = [ "*.md" ]
102+
exclude = [ "docs/superpowers/**/*.md" ]
99103
cmd = [
100104
"$PRECIOUS_ROOT/node_modules/.bin/prettier",
101105
"--print-width", "100",

0 commit comments

Comments
 (0)