mirror of https://github.com/mongodb/mongo
9.4 KiB
9.4 KiB
Hooks
Hooks are a mechanism to run routines around the tests, at the test content boundaries.
Supported hooks
Specify any of the following as the hooks in your Suite config:
AnalyzeShardKeysInBackground- A hook for runninganalyzeShardKeycommands while a test is running.AntithesisLogging- Prints antithesis commands before & after test run.BackgroundInitialSync- Background Initial Sync- After every test, this hook checks if a background node has finished initial sync and if so validates it, tears it down, and restarts it.
- This test accepts a parameter
nthat specifies a number of tests after which it will wait for replication to finish before validating and restarting the initial sync node. - This requires the ReplicaSetFixture to be started with
start_initial_sync_node=True. If used at the same time asCleanEveryN, thenvalue passed to this hook should be equal to thenvalue forCleanEveryN.
CheckClusterIndexConsistency- Checks that indexes are the same across chunks for the same collections.CheckMetadataConsistencyInBackground- Check the metadata consistency of a sharded cluster.CheckOrphansDeleted- Check if the range deleter failed to delete any orphan documents.CheckReplDBHashInBackground- A hook for comparing the dbhashes of all replica set members while a test is running.CheckReplDBHash- Check if the dbhashes match.CheckReplOplogs- Check thatlocal.oplog.rsmatches on the primary and secondaries.CheckReplPreImagesConsistency- Check thatconfig.system.preimagesis consistent between the primary and secondaries.CheckRoutingTableConsistency- Verifies the absence of corrupted entries in config.chunks and config.collections.CheckShardFilteringMetadata- Inspect filtering metadata on shardsCleanEveryN- Restart the fixture after it has ranntests.CleanupConcurrencyWorkloads- Drop all databases, except those that have been excluded.- For concurrency tests that run on different DBs, drop all databases except ones in
exclude_dbs. For tests that run on the same DB, drop all databases except ones inexclude_dbsand the DB used by the test/workloads. For tests that run on the same collection, drop all collections in all databases except forexclude_dbsand the collection used by the test/workloads. - On mongod-related fixtures, this will clear the dbpath
- For concurrency tests that run on different DBs, drop all databases except ones in
ClusterParameter- Sets the specified cluster server parameter.ContinuousAddRemoveShard- Continuously adds and removes shards at regular intervals. If running withconfigsvrtransitions, will transition in/out of config shard mode.ContinuousInitialSync- Periodically initial sync nodes then step them up.ContinuousStepdown- regularly connect to replica sets and send areplSetStepDowncommand.ContinuousTransition- connects to replica sets and transitions them from replica set to CSRS node in the background.DoReconfigInBackground- A hook for running a safe reconfig against a replica set while a test is running.DropSessionsCollection- A hook for dropping and recreating config.system.sessions while tests are running.DropUserCollections- Drops all user collections.EnableSpuriousWriteConflicts- Toggles write conflicts.FCVUpgradeDowngradeInBackground- A hook to run background FCV upgrade and downgrade against test servers while a test is running.FuzzRuntimeParameters- Regularly connect to nodes and sends them asetParametercommand; uses the Config Fuzzer.FuzzRuntimeStress- Test hook that periodically changes the amount of stress the system is experiencing.FuzzerRestoreSettings- Cleans up unwanted changes from fuzzer.GenerateAndCheckPerfResults- Combine JSON results from individual benchmarks and check their reported values against any thresholds set for them.- Combines test results from individual benchmark files to a single file. This is useful for generating the json file to feed into the Evergreen performance visualization plugin.
HelloDelays- Sets Hello fault injections.IntermediateInitialSync- Intermediate Initial Sync- This hook accepts a parameter
nthat specifies a number of tests after which it will start up a node to initial sync, wait for replication to finish, and then validate the data. - This requires the ReplicaSetFixture to be started with 'start_initial_sync_node=True'.
- This hook accepts a parameter
LagOplogApplicationInBackground- Toggles secondary oplog application lag.LibfuzzerHook- Merges inputs after a fuzzer run.MagicRestoreEveryN- Open a backup cursor and run magic restore process afterntests have run.- Requires the use of
MagicRestoreFixture.
- Requires the use of
PeriodicKillSecondaries- Periodically kills the secondaries in a replica set.- Also verifies that the secondaries can reach the SECONDARY state without having connectivity to the primary after an unclean shutdown.
PeriodicStackTrace- Test hook that sends the stacktracing signal to mongo processes at randomized intervals.QueryableServerHook- Starts the queryable server before each test for queryable restores. Restarts the queryable server between tests.RotateExecutionControlParams- Periodically rotates 'executionControlConcurrencyAdjustmentAlgorithm' and deprioritization server parameters to random valid values.RunChangeStreamsInBackground- Run in the background full cluster change streams while a test is running. Open and close the change stream every1..10tests (random usingconfig.RANDOM_SEED).RunDBCheckInBackground- A hook for runningdbCheckon a replica set while a test is running.- This includes dbhashes for all non-local databases and non-replicated system collections that match on the primary and secondaries.
- It also will check the performance results against any thresholds that are set for each benchmark. If no thresholds are set for a test, this hook should always pass.
RunQueryStats- Runs$queryStatsafter every test, and clears the query stats store before every test.SimulateCrash- A hook to simulate crashes.ValidateCollections- Run full validation.ValidateCollectionsInBackground- A hook to run background collection validation against test servers while a test is running.- This will run on all collections in all databases on every stand-alone node, primary replica-set node, or primary shard node.
ValidateDirectSecondaryReads- Only supported in suites that useReplicaSetFixture.- To be used with
set_read_preference_secondary.jsandimplicit_enable_profiler.jsin suites that read directly from secondaries in a replica set. Check the profiler collections of all databases at the end of the suite to verify that each secondary only ran the read commands it got directly from the shell.
- To be used with
WaitForReplication- Wait for replication to complete.
Interfaces
All hooks inherit from the buildscripts.resmokelib.testing.hooks.interface.Hook parent class and can override any subset of the following empty base methods:
before_suitebefore_testafter_testafter_suite
At least 1 base method must be overridden, otherwise the hook will not do anything at all. During test suite execution, each hook runs its custom logic in the respective scenarios. Some customizable tasks that hooks can perform include: validating data, deleting data, performing cleanup, etc.
BGHook- A hook that repeatedly callsrun_action()in a background thread for the duration of the test suite.DataConsistencyHook- A hook for running a static JavaScript file that checks data consistency of the server.- If the mongo shell process running the JavaScript file exits with a non-zero return code, then an
errors.ServerFailureexception is raised to cause resmoke.py's test execution to stop.
- If the mongo shell process running the JavaScript file exits with a non-zero return code, then an
Hook- Common interface all Hooks will inherit from.JSHook- A hook interface with a static JavaScript file to execute.PerClusterDataConsistencyHook- A hook that runs on each independent cluster of the fixture.- The independent cluster itself may be another fixture.