Validate test files against the schema they declare #1813
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
Previously we used a hard-coded schema version to validate test files, which needed updating whenever we release a new schema version. This could be replaced by using schema-latest, but this doesn't solve another problem we currently face: since we validate test files with a newer version of the schema, it could be that they use functionality that was only introduced in a later version without us ever knowing.
The solution introduced here greps a given file for its
schemaVersion
, then validates the test against that schema version. If the schema in question is not given, the file is validated againstlatest
and a warning is printed. This is necessary because there is a valid-fail test that specifies schema version0.1
, which the validator wouldn't be able to find. The logic in the file also accounts for changing thespec
set in the call toajv
according to whether the schema uses draft-2019-09 (1.24 and newer) or draft-7 (older schema versions).An unfortunate side effect of this change is that validation now takes significantly longer than before. While previously a
make
run took ~6 seconds, it now tales ~150 seconds. Parallelising this usingmake -j10
on my machine improved performance to ~56 seconds, which is still considerably slower than before. However, given the improvements provided, the fact that this is usually only run in CI, and the fact that people can runmake
on just the spec they've worked on makes me think that this delay is acceptable for the time being.Please complete the following before merging:
[ ] Update changelog.[ ] Test changes in at least one language driver.[ ] Test these changes against all server versions and topologies (including standalone, replica set, and shardedclusters).