summaryrefslogtreecommitdiff
path: root/jstests/concurrency/fsm_workloads/create_timeseries_collection.js
blob: ed28e29966c25e7050a62c9729dbc2b5fe1a96dc (plain)
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
"use strict";

load("jstests/core/timeseries/libs/timeseries.js");

/**
 * Repeatedly creates a time-series collection, inserts data and drops it.
 *
 * @tags: [
 *   assumes_no_implicit_collection_creation_after_drop,
 *   does_not_support_stepdowns,
 *   requires_fcv_49,
 *   sbe_incompatible,
 * ]
 */
var $config = (function() {
    var data = {prefix: "create_timeseries_collection", supportsTimeseriesCollections: false};

    var states = (function() {
        function getCollectionName(prefix, collName, tid) {
            return prefix + "_" + collName + "_" + tid;
        }

        function init(db, collName) {
            this.num = 0;

            if (TimeseriesTest.timeseriesCollectionsEnabled(db.getMongo())) {
                this.supportsTimeseriesCollections = true;
                return;
            }

            jsTestLog("Skipping test because the time-series collection feature flag is disabled");
        }

        function create(db, collName) {
            if (!this.supportsTimeseriesCollections) {
                return;
            }

            collName = getCollectionName(this.prefix, collName, this.tid);

            const timeFieldName = "time";
            assertAlways.commandWorked(
                db.createCollection(collName, {timeseries: {timeField: timeFieldName}}));
        }

        function insert(db, collName) {
            if (!this.supportsTimeseriesCollections) {
                return;
            }

            collName = getCollectionName(this.prefix, collName, this.tid);

            const coll = db.getCollection(collName);
            assertAlways.commandWorked(coll.insert({
                _id: this.num,
                measurement: "measurement",
                time: ISODate(),
            }));
        }

        function drop(db, collName) {
            if (!this.supportsTimeseriesCollections) {
                return;
            }

            collName = getCollectionName(this.prefix, collName, this.tid);
            db.getCollection(collName).drop();
        }

        return {init: init, create: create, insert: insert, drop: drop};
    })();

    var transitions = {
        init: {create: 1},
        create: {insert: 0.8, drop: 0.2},
        insert: {insert: 0.8, drop: 0.2},
        drop: {create: 1}
    };

    return {
        threadCount: 4,
        iterations: 1000,
        data: data,
        states: states,
        transitions: transitions,
    };
})();