Skip to content

Commit f8d80ef

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 eceded6 commit f8d80ef

6 files changed

Lines changed: 1070 additions & 0 deletions

File tree

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: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,45 @@ 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+
MONGO_ARGS="${mongo_args}"
475+
NODE_OPTIONS=""
476+
mkdir -p /data/db/
477+
if [ "${USE_TLS}" = "true" ]; then
478+
NODE_OPTIONS="${replsettest_tls_config}"
479+
MONGO_ARGS="${mongo_args_tls}"
480+
elif [ "${USE_SSL}" = "true" ]; then
481+
NODE_OPTIONS="${replsettest_ssl_config}"
482+
fi
483+
# use jsconfig.json to set baseUrl to find libs
484+
mv test/shell_common/jsconfig.json ./
485+
if [ -n "${load_libs_version}" ]; then
486+
IMPORT_LOAD_LIBS="await import(\"../shell_common/libs/load_libs-${load_libs_version}.js\");"
487+
fi
488+
PATH=./bin:$PATH ./bin/mongo $MONGO_ARGS --nodb --eval "$IMPORT_LOAD_LIBS; var st = new ShardingTest({name: \"tools_sharded_cluster\", shards: 1, mongos: [{port: ${mongod_port}, $NODE_OPTIONS}], other: {rsOptions: {$NODE_OPTIONS}, configOptions: {$NODE_OPTIONS}}}); while(true){sleep(1000);}"
489+
490+
- command: shell.exec
491+
params:
492+
working_dir: src/github.com/mongodb/mongo-tools
493+
script: |
494+
set -x
495+
set -v
496+
set -e
497+
MONGO_ARGS="${mongo_args}"
498+
if [ "${USE_TLS}" = "true" ]; then
499+
MONGO_ARGS="${mongo_args_tls}"
500+
fi
501+
./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")'
502+
464503
"add-aws-auth-variables-to-file":
465504
- command: shell.exec
466505
type: test
@@ -1523,6 +1562,153 @@ tasks:
15231562
vars:
15241563
target: test:integration -ssl=true -topology=replSet ${testArgs}
15251564

1565+
- name: integration-4.4-sharded
1566+
tags: ["4.4", "sharded"]
1567+
commands:
1568+
- func: "fetch source"
1569+
- command: expansions.update
1570+
- func: "download mongod and shell"
1571+
vars:
1572+
mongo_version: "4.4"
1573+
- func: "create sharded cluster"
1574+
vars:
1575+
USE_TLS: "true"
1576+
- func: "run make target"
1577+
vars:
1578+
target: build
1579+
- func: "run make target"
1580+
vars:
1581+
target: test:sharded-integration -ssl=true ${testArgs}
1582+
1583+
- name: integration-5.0-sharded
1584+
tags: ["5.0", "sharded"]
1585+
commands:
1586+
- func: "fetch source"
1587+
- command: expansions.update
1588+
- func: "download mongod and shell"
1589+
vars:
1590+
mongo_version: "5.0"
1591+
- func: "create sharded cluster"
1592+
vars:
1593+
USE_TLS: "true"
1594+
- func: "run make target"
1595+
vars:
1596+
target: build
1597+
- func: "run make target"
1598+
vars:
1599+
target: test:sharded-integration -ssl=true ${testArgs}
1600+
1601+
- name: integration-6.0-sharded
1602+
tags: ["6.0", "sharded"]
1603+
commands:
1604+
- func: "fetch source"
1605+
- command: expansions.update
1606+
- func: "download mongod and shell"
1607+
vars:
1608+
mongo_version: "6.0"
1609+
- func: "create sharded cluster"
1610+
vars:
1611+
USE_TLS: "true"
1612+
- func: "run make target"
1613+
vars:
1614+
target: build
1615+
- func: "run make target"
1616+
vars:
1617+
target: test:sharded-integration -ssl=true ${testArgs}
1618+
1619+
- name: integration-7.0-sharded
1620+
tags: ["7.0", "sharded"]
1621+
commands:
1622+
- func: "fetch source"
1623+
- command: expansions.update
1624+
- func: "download mongod and shell"
1625+
vars:
1626+
mongo_version: "7.0"
1627+
- func: "create sharded cluster"
1628+
vars:
1629+
USE_TLS: "true"
1630+
- func: "run make target"
1631+
vars:
1632+
target: build
1633+
- func: "run make target"
1634+
vars:
1635+
target: test:sharded-integration -ssl=true ${testArgs}
1636+
1637+
- name: integration-8.0-sharded
1638+
tags: ["8.0", "sharded"]
1639+
commands:
1640+
- func: "fetch source"
1641+
- command: expansions.update
1642+
- func: "download mongod and shell"
1643+
vars:
1644+
mongo_version: "8.0"
1645+
- func: "create sharded cluster"
1646+
vars:
1647+
USE_TLS: "true"
1648+
- func: "run make target"
1649+
vars:
1650+
target: build
1651+
- func: "run make target"
1652+
vars:
1653+
target: test:sharded-integration -ssl=true ${testArgs}
1654+
1655+
- name: integration-8.1-sharded
1656+
tags: ["8.1", "sharded"]
1657+
commands:
1658+
- func: "fetch source"
1659+
- command: expansions.update
1660+
- func: "download mongod and shell"
1661+
vars:
1662+
mongo_version: "8.1.0"
1663+
- func: "create sharded cluster"
1664+
vars:
1665+
USE_TLS: "true"
1666+
load_libs_version: "8.1"
1667+
- func: "run make target"
1668+
vars:
1669+
target: build
1670+
- func: "run make target"
1671+
vars:
1672+
target: test:sharded-integration -ssl=true ${testArgs}
1673+
1674+
- name: integration-8.2-sharded
1675+
tags: ["8.2", "sharded"]
1676+
commands:
1677+
- func: "fetch source"
1678+
- command: expansions.update
1679+
- func: "download mongod and shell"
1680+
vars:
1681+
mongo_version: "8.2.0"
1682+
- func: "create sharded cluster"
1683+
vars:
1684+
USE_TLS: "true"
1685+
load_libs_version: "8.2"
1686+
- func: "run make target"
1687+
vars:
1688+
target: build
1689+
- func: "run make target"
1690+
vars:
1691+
target: test:sharded-integration -ssl=true ${testArgs}
1692+
1693+
- name: integration-latest-sharded
1694+
tags: ["latest", "sharded"]
1695+
commands:
1696+
- func: "fetch source"
1697+
- command: expansions.update
1698+
- func: "download mongod and shell"
1699+
vars:
1700+
mongo_version: "latest"
1701+
- func: "create sharded cluster"
1702+
vars:
1703+
USE_TLS: "true"
1704+
load_libs_version: *max_server_version
1705+
- func: "run make target"
1706+
vars:
1707+
target: build
1708+
- func: "run make target"
1709+
vars:
1710+
target: test:sharded-integration -ssl=true ${testArgs}
1711+
15261712
- name: aws-auth-latest
15271713
tags: ["latest", "aws-auth"]
15281714
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

0 commit comments

Comments
 (0)