Skip to content

DRIVERS-709: Unified Test Format #846

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 90 commits into from
Oct 10, 2020
Merged
Show file tree
Hide file tree
Changes from 83 commits
Commits
Show all changes
90 commits
Select commit Hold shift + click to select a range
90fcf6c
DRIVERS-709 wip
jmikola Jul 22, 2020
f2c6bb0
consolidate test format, simplify assert syntax, docs for matching
jmikola Aug 19, 2020
ecdf667
bulkWrite errors, schemaVersion, and configureFailPoint APM exclusion
jmikola Aug 21, 2020
c2089ca
Revise schema version and move allowMultipleMongoses to top-level
jmikola Aug 22, 2020
2782344
Define terms and start test execution steps
jmikola Aug 22, 2020
ece67f2
Readability improvements and TODO items
jmikola Aug 22, 2020
16a0bb7
Suggest YAML nodes and anchors for collection/database names
jmikola Aug 22, 2020
acde870
Fix link text and version formatting
jmikola Aug 22, 2020
5e96571
indent Server Fail Points and describe process for sharded-replicaset
jmikola Aug 22, 2020
cf3193c
Test implementation and various other clarifications
jmikola Aug 24, 2020
e6cb23e
Language edits from PR feedback
jmikola Aug 25, 2020
00986ea
Require explicit database and collection names and add extra notes
jmikola Aug 26, 2020
8bf4f0b
observeEvents and useMultipleMongoses client entity options
jmikola Aug 26, 2020
b223eeb
Example insertOne test
jmikola Aug 26, 2020
0fcd5da
special operations for sessions spec tests
jmikola Aug 26, 2020
6253755
open questions
jmikola Aug 26, 2020
07bbfb8
open question for representing options in operation.arguments
jmikola Aug 26, 2020
d80e929
Rename schema and test file to convey they are outdated
jmikola Aug 27, 2020
98f911d
clarify schema version comparisons and compatibility
jmikola Aug 27, 2020
9c1a906
lsid assertions require observed commands with lsid fields
jmikola Aug 27, 2020
51ccdbf
Rename topologies link related spec tickets
jmikola Aug 27, 2020
bc267ee
top-level description field
jmikola Aug 27, 2020
11cb308
change stream iteration, open questions, and errorCode assertion
jmikola Aug 28, 2020
ace3491
Future Work, createchangeStream operation, and review fixes
jmikola Sep 1, 2020
b37beea
Update last modified and advisors
jmikola Sep 1, 2020
b779a14
Fix typos
jmikola Sep 3, 2020
b505fdf
Changes for events, GridFS, and error assertions
jmikola Sep 3, 2020
0dd4ad9
runOnRequirements, expectedEventsForClient, refer to YAML objects
jmikola Sep 3, 2020
3b70475
Sync JSON file with YAML to add description field
jmikola Sep 8, 2020
8038b4b
Require arrays, rename "expect" prefix, clarify "sharded" requirement
jmikola Sep 8, 2020
d960cbe
Remove note about clearing state between test files
jmikola Sep 8, 2020
87dc9d7
Note that server versions are compared numerically
jmikola Sep 8, 2020
acbec78
Fix typo
jmikola Sep 8, 2020
9997cd6
Clarify type of observeEvents
jmikola Sep 9, 2020
5480885
Require BSON types be expressed as strings for $$type operator
jmikola Sep 11, 2020
96e6713
Clarify test.outcome and comparison rules
jmikola Sep 15, 2020
a44d3a2
Make formatting of "primary" RP consistent with WC and RC
jmikola Sep 15, 2020
26f7855
Add Goals, clarify schemaVersion, and Future Work entries
jmikola Sep 17, 2020
2fd02b5
Elaborate on schema version
jmikola Sep 17, 2020
81c2e74
Clarify (un)supported entity types
jmikola Sep 18, 2020
3b74482
Allow equivalent language types for BSON types in entity map
jmikola Sep 21, 2020
4b39a33
Raise errors for unsupported operations and arguments
jmikola Sep 22, 2020
ffc5773
Fix link syntax
jmikola Sep 22, 2020
30160fa
Feedback from Oleg
jmikola Sep 22, 2020
ecee77e
$$sessionLsid error handling and heartbeatFrequencyMS tweaks
jmikola Sep 23, 2020
ba6f597
Clarify BSON type support and advise against using deprecated types
jmikola Sep 23, 2020
f8bb778
Clarify server version string comparison rules
jmikola Sep 23, 2020
955d59f
Revise version docs, MUST reset state, explain SHOULD in Design Ratio…
jmikola Sep 24, 2020
ef1d60a
Improve Evaluating Matches docs
jmikola Sep 25, 2020
0912d2a
Test runners MUST raise an error for incompatible files
jmikola Sep 25, 2020
0abb9e8
Future work for operations/arguments and schema version
jmikola Sep 25, 2020
dc7383b
Prohibit $$unsetOrMatches for array elements
jmikola Sep 28, 2020
85dcf2c
Optional arrays must be non-empty, revise expectedEvent and $$matches…
jmikola Sep 29, 2020
0e00466
Update schema for current spec syntax
jmikola Sep 29, 2020
fddd2b7
Update Makefile for new schema
jmikola Sep 29, 2020
8b20517
expectedError.isError can only be true
jmikola Sep 30, 2020
731b8b8
Add invalid test files for testing the schema itself
jmikola Sep 30, 2020
2e76cb3
Prohibit additionalProperties in test objects
jmikola Sep 30, 2020
eb7fb4b
Requirements for model objects and iterables and clarify failPoint
jmikola Oct 2, 2020
92d4368
Fix RST syntax and typos
jmikola Oct 2, 2020
13eabc2
Specify descriptions for invalid schema tests
jmikola Oct 2, 2020
ae29867
Initial valid-fail and valid-pass tests
jmikola Oct 2, 2020
198aa4c
Clarify iteration rules
jmikola Oct 2, 2020
f947095
Don't mix testRunner ops with error/result expectations
jmikola Oct 3, 2020
3790681
Additional POC tests
jmikola Oct 4, 2020
e80d6c6
Clarifications for CRUD operations
jmikola Oct 4, 2020
99ea7f1
Advise using $$unsetOrMatches for InsertOneResult
jmikola Oct 4, 2020
602833d
POC for session tests
jmikola Oct 4, 2020
a42a31c
POC for transaction tests
jmikola Oct 4, 2020
c0c1c02
Fix insertOne syntax
jmikola Oct 5, 2020
5a95b6d
Use complete fullDocument assertions in change stream tests
jmikola Oct 6, 2020
c0f468e
Clarify rules for enabling event listeners
jmikola Oct 6, 2020
cd42a55
Fix event assertions for ChangeStream tests
jmikola Oct 7, 2020
a4f20d0
Fix syntax of callback argument for withTransaction tests
jmikola Oct 7, 2020
5944094
Remove stream entity and add proxy operations for GridFS
jmikola Oct 7, 2020
3dbb895
Reorganized entity operation content and advise not using watch
jmikola Oct 7, 2020
374924d
Fix retryable reads test and add additional find test
jmikola Oct 7, 2020
29b8aab
Fix retryable writes test to use correct collection object
jmikola Oct 7, 2020
4de1a93
Fix syntax errors in session tests
jmikola Oct 7, 2020
78291dd
Fix typos in transaction tests
jmikola Oct 7, 2020
f04079f
Specify useMultipleMongoses:false for failPoint tests
jmikola Oct 7, 2020
db33be3
Fix outcome assertion in session pinning test
jmikola Oct 7, 2020
2665c01
Add related issue and iterateUntilDocumentOrError clarification
jmikola Oct 8, 2020
f3df323
Rename returnDocument test and fix syntax error
jmikola Oct 8, 2020
4bfda00
Require sharded-replicaset for retryable write session test
jmikola Oct 9, 2020
0732830
Fix typo
jmikola Oct 9, 2020
40bb54e
Remove "Related Issues" section and clear "Change Log"
jmikola Oct 10, 2020
796de8c
Fix schema validation error in returnDocument-enum-invalid.yml
jmikola Oct 10, 2020
c8815ad
Generate JSON for YAML tests
jmikola Oct 10, 2020
58de923
Add schema checks to Travis CI
jmikola Oct 10, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
286 changes: 286 additions & 0 deletions source/unified-test-format/schema-1.0.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,286 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",

"title": "Unified Test Format",
"type": "object",
"additionalProperties": false,
"required": ["description", "schemaVersion", "tests"],
"properties": {
"description": { "type": "string" },
"schemaVersion": { "$ref": "#/definitions/version" },
"runOnRequirements": {
"type": "array",
"minItems": 1,
"items": { "$ref": "#/definitions/runOnRequirement" }
},
"createEntities": {
"type": "array",
"minItems": 1,
"items": { "$ref": "#/definitions/entity" }
},
"initialData": {
"type": "array",
"minItems": 1,
"items": { "$ref": "#/definitions/collectionData" }
},
"tests": {
"type": "array",
"minItems": 1,
"items": { "$ref": "#/definitions/test" }
}
},

"definitions": {
"version": {
"type": "string",
"pattern": "^[0-9]+(\\.[0-9]+){1,2}$"
},

"runOnRequirement": {
"type": "object",
"additionalProperties": false,
"minProperties": 1,
"properties": {
"maxServerVersion": { "$ref": "#/definitions/version" },
"minServerVersion": { "$ref": "#/definitions/version" },
"topologies": {
"type": "array",
"minItems": 1,
"items": {
"type": "string",
"enum": ["single", "replicaset", "sharded", "sharded-replicaset"]
}
}
}
},

"entity": {
"type": "object",
"additionalProperties": false,
"maxProperties": 1,
"minProperties": 1,
"properties": {
"client": {
"type": "object",
"additionalProperties": false,
"required": ["id"],
"properties": {
"id": { "type": "string" },
"uriOptions": { "type": "object" },
"useMultipleMongoses": { "type": "boolean" },
"observeEvents": {
"type": "array",
"minItems": 1,
"items": {
"type": "string",
"enum": ["commandStartedEvent", "commandSucceededEvent", "commandFailedEvent"]
}
},
"ignoreCommandMonitoringEvents": {
"type": "array",
"minItems": 1,
"items": { "type": "string" }
}
}
},
"database": {
"type": "object",
"additionalProperties": false,
"required": ["id", "client", "databaseName"],
"properties": {
"id": { "type": "string" },
"client": { "type": "string" },
"databaseName": { "type": "string" },
"databaseOptions": { "$ref": "#/definitions/collectionOrDatabaseOptions" }
}
},
"collection": {
"type": "object",
"additionalProperties": false,
"required": ["id", "database", "collectionName"],
"properties": {
"id": { "type": "string" },
"database": { "type": "string" },
"collectionName": { "type": "string" },
"collectionOptions": { "$ref": "#/definitions/collectionOrDatabaseOptions" }
}
},
"session": {
"type": "object",
"additionalProperties": false,
"required": ["id", "client"],
"properties": {
"id": { "type": "string" },
"client": { "type": "string" },
"sessionOptions": { "type": "object" }
}
},
"bucket": {
"type": "object",
"additionalProperties": false,
"required": ["id", "database"],
"properties": {
"id": { "type": "string" },
"database": { "type": "string" },
"bucketOptions": { "type": "object" }
}
},
"stream": {
"type": "object",
"additionalProperties": false,
"required": ["id", "hexBytes"],
"properties": {
"id": { "type": "string" },
"hexBytes": {
"type": "string",
"pattern": "^([0-9A-Fa-f]{2})*$"
}
}
}
}
},

"collectionData": {
"type": "object",
"additionalProperties": false,
"required": ["collectionName", "databaseName", "documents"],
"properties": {
"collectionName": { "type": "string" },
"databaseName": { "type": "string" },
"documents": {
"type": "array",
"items": { "type": "object" }
}
}
},

"expectedEventsForClient": {
"type": "object",
"additionalProperties": false,
"required": ["client", "events"],
"properties": {
"client": { "type": "string" },
"events": {
"type": "array",
"items": { "$ref": "#/definitions/expectedEvent" }
}
}
},

"expectedEvent": {
"type": "object",
"additionalProperties": false,
"maxProperties": 1,
"minProperties": 1,
"properties": {
"commandStartedEvent": {
"type": "object",
"additionalProperties": false,
"properties": {
"command": { "type": "object" },
"commandName": { "type": "string" },
"databaseName": { "type": "string" }
}
},
"commandSucceededEvent": {
"type": "object",
"additionalProperties": false,
"properties": {
"reply": { "type": "object" },
"commandName": { "type": "string" }
}
},
"commandFailedEvent": {
"type": "object",
"additionalProperties": false,
"properties": {
"commandName": { "type": "string" }
}
}
}
},

"collectionOrDatabaseOptions": {
"type": "object",
"additionalProperties": false,
"properties": {
"readConcern": { "type": "object" },
"readPreference": { "type": "object" },
"writeConcern": { "type": "object" }
}
},

"operation": {
"type": "object",
"additionalProperties": false,
"required": ["name", "object"],
"properties": {
"name": { "type": "string" },
"object": { "type": "string" },
"arguments": { "type": "object" },
"expectError": { "$ref": "#/definitions/expectedError" },
"expectResult": {},
"saveResultAsEntity": { "type": "string" }
},
"allOf": [
{ "not": { "required": ["expectError", "expectResult"] } },
{ "not": { "required": ["expectError", "saveResultAsEntity"] } }
]
},

"expectedError": {
"type": "object",
"additionalProperties": false,
"minProperties": 1,
"properties": {
"isError": {
"type": "boolean",
"const": true
},
"isClientError": { "type": "boolean" },
"errorContains": { "type": "string" },
"errorCode": { "type": "integer" },
"errorCodeName": { "type": "string" },
"errorLabelsContain": {
"type": "array",
"minItems": 1,
"items": { "type": "string" }
},
"errorLabelsOmit": {
"type": "array",
"minItems": 1,
"items": { "type": "string" }
},
"expectResult": {}
}
},

"test": {
"type": "object",
"additionalProperties": false,
"required": ["description", "operations"],
"properties": {
"description": { "type": "string" },
"runOnRequirements": {
"type": "array",
"minItems": 1,
"items": { "$ref": "#/definitions/runOnRequirement" }
},
"skipReason": { "type": "string" },
"operations": {
"type": "array",
"items": { "$ref": "#/definitions/operation" }
},
"expectEvents": {
"type": "array",
"items": { "$ref": "#/definitions/expectedEventsForClient" }
},
"outcome": {
"type": "array",
"minItems": 1,
"items": { "$ref": "#/definitions/collectionData" }
}
}
}
}
}
63 changes: 63 additions & 0 deletions source/unified-test-format/schema-testing-example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{
"tests": [
{
"description": "valid because error:true and result has only expected fields",
"operations": [
{
"object": "collection",
"name": "runCommand",
"error": true,
"result": {
"errorContains": "string"
}
}
]
},
{
"description": "valid because error == false. result can be any type (non-object)",
"operations": [
{
"object": "collection",
"name": "operation",
"error": false,
"result": 1
}
]
},
{
"description": "valid because error == false. result can be any type (object)",
"operations": [
{
"object": "collection",
"name": "operation",
"error": false,
"result": {
"foo": "bar"
}
}
]
},
{
"description": "valid because error != true. result can be any type (non-object)",
"operations": [
{
"object": "collection",
"name": "operation",
"result": 1
}
]
},
{
"description": "valid because error != true. result can be any type (object)",
"operations": [
{
"object": "collection",
"name": "operation",
"result": {
"foo": "bar"
}
}
]
}
]
}
21 changes: 21 additions & 0 deletions source/unified-test-format/tests/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
SCHEMA=../schema-1.0.json

.PHONY: all invalid valid-fail valid-pass HAS_AJV

all: invalid valid-fail valid-pass

invalid: HAS_AJV
@# Redirect stdout to hide expected validation errors
@ajv test -s $(SCHEMA) -d "invalid/*.yml" --invalid > /dev/null && echo "invalid/*.yml passed test"

valid-fail: HAS_AJV
@ajv test -s $(SCHEMA) -d "valid-fail/*.yml" --valid

valid-pass: HAS_AJV
@ajv test -s $(SCHEMA) -d "valid-pass/*.yml" --valid

HAS_AJV:
@if ! command -v ajv > /dev/null; then \
echo 'Error: need "npm install -g ajv-cli"' 1>&2; \
exit 1; \
fi
Loading