mirror of
https://github.com/mongodb/mongo.git
synced 2024-11-21 20:49:10 +01:00
SERVER-69408 Add randomized testing for the mixed-type timeseries bug
This commit is contained in:
parent
ec53785014
commit
dfe2ef0eb6
@ -1,2 +1,3 @@
|
|||||||
src/mongo/gotools/*
|
src/mongo/gotools/*
|
||||||
*.tpl.js
|
*.tpl.js
|
||||||
|
jstests/third_party/**/*.js
|
||||||
|
79
jstests/noPassthroughWithMongod/randomized_mixed_type_bug.js
Normal file
79
jstests/noPassthroughWithMongod/randomized_mixed_type_bug.js
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
/**
|
||||||
|
* Tests that randomly generated documents can be queried from timeseries collections in the same
|
||||||
|
* manner as a tradional collection.
|
||||||
|
*/
|
||||||
|
(function() {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
load('jstests/third_party/fast_check/fc-3.1.0.js'); // For fast-check (fc).
|
||||||
|
|
||||||
|
const scalars = [fc.string(), fc.double(), fc.boolean(), fc.date(), fc.constant(null)];
|
||||||
|
const pathComponents = fc.constant("a", "b");
|
||||||
|
// Define our grammar for documents.
|
||||||
|
let documentModel = fc.letrec(
|
||||||
|
tie => ({
|
||||||
|
// Our Terminals.
|
||||||
|
scalar: fc.oneof(...scalars),
|
||||||
|
value: fc.oneof(
|
||||||
|
{maxDepth: 3},
|
||||||
|
// It may be surprising that we don't have to reweight this. Oneof handles ensuring the
|
||||||
|
// termination happens (on sequential runs it weights the first option heavier). The
|
||||||
|
// maxDepth parameter also ensures that termination happens by the time the depth is
|
||||||
|
// reached.
|
||||||
|
// Moreover fast-check prefers simpler object to more complex objects on some runs so we
|
||||||
|
// needn't upweight scalars in order to ensure that scalar cases occur more frequently.
|
||||||
|
// For more information about the biases fast-check applies see:
|
||||||
|
// https://github.com/dubzzz/fast-check/blob/main/packages/fast-check/documentation/HowItWorks.md#bias
|
||||||
|
tie('scalar'),
|
||||||
|
tie('object'),
|
||||||
|
fc.array(tie('value'))),
|
||||||
|
object: fc.object({key: pathComponents, maxDepth: 0, maxKeys: 2, values: [tie('value')]}),
|
||||||
|
}));
|
||||||
|
|
||||||
|
// Define our test arbitraries
|
||||||
|
const onePath = fc.array(pathComponents, {minLength: 1, maxLength: 2});
|
||||||
|
const oneComparator = fc.oneof(fc.constant("$lte"), fc.constant("$gte"));
|
||||||
|
const atLeastThreeDocs = fc.array(documentModel.object, {minLength: 3});
|
||||||
|
|
||||||
|
// Our test case
|
||||||
|
let testMixedTypeQuerying = () => {
|
||||||
|
// Assert that query results for ts pushdowns are the same as query results for non-ts
|
||||||
|
// collections.
|
||||||
|
fc.assert(fc.property(
|
||||||
|
// The arbitrary.
|
||||||
|
fc.tuple(atLeastThreeDocs, documentModel.scalar, onePath, oneComparator),
|
||||||
|
// The scenario to test.
|
||||||
|
([docs, val, pathArray, compare]) => {
|
||||||
|
db.test.drop();
|
||||||
|
db.control.drop();
|
||||||
|
db.createCollection("test", {timeseries: {timeField: "t"}});
|
||||||
|
|
||||||
|
// Insert documents
|
||||||
|
docs.forEach(doc => {
|
||||||
|
let date = new ISODate();
|
||||||
|
db.test.insert(Object.assign({t: date}, doc));
|
||||||
|
db.control.insert(Object.assign({t: date}, doc));
|
||||||
|
});
|
||||||
|
|
||||||
|
// Construct the path to query on.
|
||||||
|
let path = pathArray.join('.');
|
||||||
|
|
||||||
|
// Query on pathArray w/ {[compare]: val} on test and control.
|
||||||
|
// Compare the results.
|
||||||
|
try {
|
||||||
|
assert.docEq(
|
||||||
|
// Is timeseries.
|
||||||
|
db.test.find({[path]: {[compare]: val}}, {_id: 0}).toArray(),
|
||||||
|
// Isn't timeseries.
|
||||||
|
db.control.find({[path]: {[compare]: val}}, {_id: 0}).toArray());
|
||||||
|
return true;
|
||||||
|
} catch (e) {
|
||||||
|
printjson(
|
||||||
|
{info: "test failed", error: e, scenario: [docs, val, pathArray, compare]});
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
}; // testMixedTypeQuerying
|
||||||
|
|
||||||
|
testMixedTypeQuerying();
|
||||||
|
})();
|
21
jstests/third_party/fast_check/LICENSE
vendored
Normal file
21
jstests/third_party/fast_check/LICENSE
vendored
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2017 Nicolas DUBIEN
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
2
jstests/third_party/fast_check/README.md
vendored
Normal file
2
jstests/third_party/fast_check/README.md
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
This directory contains [fast-check](https://github.com/dubzzz/fast-check) version 3.1.0.
|
||||||
|
It is provided under the LICENSE provided in the file [LICENSE](LICENSE).
|
10062
jstests/third_party/fast_check/fc-3.1.0.js
vendored
Normal file
10062
jstests/third_party/fast_check/fc-3.1.0.js
vendored
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user