1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
/**
* Tests that time-series inserts respect {ordered: true}.
*/
(function() {
'use strict';
load('jstests/core/timeseries/libs/timeseries.js');
load('jstests/libs/fail_point_util.js');
const conn = MongoRunner.runMongod();
if (!TimeseriesTest.timeseriesCollectionsEnabled(conn)) {
jsTestLog('Skipping test because the time-series collection feature flag is disabled');
MongoRunner.stopMongod(conn);
return;
}
const testDB = conn.getDB(jsTestName());
const coll = testDB.getCollection('t');
const bucketsColl = testDB.getCollection('system.buckets.' + coll.getName());
const timeFieldName = 'time';
const metaFieldName = 'meta';
coll.drop();
assert.commandWorked(testDB.createCollection(
coll.getName(), {timeseries: {timeField: timeFieldName, metaField: metaFieldName}}));
assert.contains(bucketsColl.getName(), testDB.getCollectionNames());
const fp = configureFailPoint(conn, 'failTimeseriesInsert', {metadata: 'fail'});
const docs = [
{_id: 0, [timeFieldName]: ISODate()},
{_id: 1, [timeFieldName]: ISODate(), [metaFieldName]: 'fail'},
{_id: 2, [timeFieldName]: ISODate()}
];
const res = assert.commandFailed(coll.insert(docs, {ordered: true}));
jsTestLog('Checking insert result: ' + tojson(res));
assert.eq(res.nInserted, 1);
assert.eq(res.getWriteErrors().length, 1);
assert.eq(res.getWriteErrors()[0].index, 1);
assert.docEq(res.getWriteErrors()[0].getOperation(), docs[1]);
assert.docEq(coll.find().toArray(), [docs[0]]);
MongoRunner.stopMongod(conn);
})();
|