Skip to content

Commit 0805656

Browse files
authored
CDRIVER-3897 add tests for time-series collections (#799)
1 parent ad75396 commit 0805656

File tree

3 files changed

+260
-1
lines changed

3 files changed

+260
-1
lines changed

src/libmongoc/doc/mongoc_database_create_collection.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ This function creates a :symbol:`mongoc_collection_t` from the given :symbol:`mo
2929

3030
If no write concern is provided in ``opts``, the database's write concern is used.
3131

32+
For a list of all options, see `the MongoDB Manual entry on the create command <https://docs.mongodb.org/manual/reference/command/create/>`_.
33+
3234
Errors
3335
------
3436

Lines changed: 255 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,255 @@
1+
{
2+
"description": "timeseries-collection",
3+
"schemaVersion": "1.0",
4+
"runOnRequirements": [
5+
{
6+
"minServerVersion": "5.0"
7+
}
8+
],
9+
"createEntities": [
10+
{
11+
"client": {
12+
"id": "client0",
13+
"observeEvents": [
14+
"commandStartedEvent"
15+
]
16+
}
17+
},
18+
{
19+
"database": {
20+
"id": "database0",
21+
"client": "client0",
22+
"databaseName": "ts-tests"
23+
}
24+
},
25+
{
26+
"collection": {
27+
"id": "collection0",
28+
"database": "database0",
29+
"collectionName": "test"
30+
}
31+
}
32+
],
33+
"initialData": [
34+
{
35+
"collectionName": "test",
36+
"databaseName": "ts-tests",
37+
"documents": []
38+
}
39+
],
40+
"tests": [
41+
{
42+
"description": "createCollection with all options",
43+
"operations": [
44+
{
45+
"name": "dropCollection",
46+
"object": "database0",
47+
"arguments": {
48+
"collection": "test"
49+
}
50+
},
51+
{
52+
"name": "createCollection",
53+
"object": "database0",
54+
"arguments": {
55+
"collection": "test",
56+
"expireAfterSeconds": 604800,
57+
"timeseries": {
58+
"timeField": "time",
59+
"metaField": "meta",
60+
"granularity": "minutes"
61+
}
62+
}
63+
},
64+
{
65+
"name": "assertCollectionExists",
66+
"object": "testRunner",
67+
"arguments": {
68+
"databaseName": "ts-tests",
69+
"collectionName": "test"
70+
}
71+
}
72+
],
73+
"expectEvents": [
74+
{
75+
"client": "client0",
76+
"events": [
77+
{
78+
"commandStartedEvent": {
79+
"command": {
80+
"drop": "test"
81+
},
82+
"databaseName": "ts-tests"
83+
}
84+
},
85+
{
86+
"commandStartedEvent": {
87+
"command": {
88+
"create": "test",
89+
"expireAfterSeconds": 604800,
90+
"timeseries": {
91+
"timeField": "time",
92+
"metaField": "meta",
93+
"granularity": "minutes"
94+
}
95+
},
96+
"databaseName": "ts-tests"
97+
}
98+
}
99+
]
100+
}
101+
]
102+
},
103+
{
104+
"description": "insertMany with duplicate ids",
105+
"operations": [
106+
{
107+
"name": "dropCollection",
108+
"object": "database0",
109+
"arguments": {
110+
"collection": "test"
111+
}
112+
},
113+
{
114+
"name": "createCollection",
115+
"object": "database0",
116+
"arguments": {
117+
"collection": "test",
118+
"expireAfterSeconds": 604800,
119+
"timeseries": {
120+
"timeField": "time",
121+
"metaField": "meta",
122+
"granularity": "minutes"
123+
}
124+
}
125+
},
126+
{
127+
"name": "assertCollectionExists",
128+
"object": "testRunner",
129+
"arguments": {
130+
"databaseName": "ts-tests",
131+
"collectionName": "test"
132+
}
133+
},
134+
{
135+
"name": "insertMany",
136+
"object": "collection0",
137+
"arguments": {
138+
"documents": [
139+
{
140+
"_id": 1,
141+
"time": {
142+
"$date": {
143+
"$numberLong": "1552949630482"
144+
}
145+
}
146+
},
147+
{
148+
"_id": 1,
149+
"time": {
150+
"$date": {
151+
"$numberLong": "1552949630483"
152+
}
153+
}
154+
}
155+
]
156+
}
157+
},
158+
{
159+
"name": "find",
160+
"object": "collection0",
161+
"arguments": {
162+
"filter": {},
163+
"sort": {
164+
"time": 1
165+
}
166+
},
167+
"expectResult": [
168+
{
169+
"_id": 1,
170+
"time": {
171+
"$date": {
172+
"$numberLong": "1552949630482"
173+
}
174+
}
175+
},
176+
{
177+
"_id": 1,
178+
"time": {
179+
"$date": {
180+
"$numberLong": "1552949630483"
181+
}
182+
}
183+
}
184+
]
185+
}
186+
],
187+
"expectEvents": [
188+
{
189+
"client": "client0",
190+
"events": [
191+
{
192+
"commandStartedEvent": {
193+
"command": {
194+
"drop": "test"
195+
},
196+
"databaseName": "ts-tests"
197+
}
198+
},
199+
{
200+
"commandStartedEvent": {
201+
"command": {
202+
"create": "test",
203+
"expireAfterSeconds": 604800,
204+
"timeseries": {
205+
"timeField": "time",
206+
"metaField": "meta",
207+
"granularity": "minutes"
208+
}
209+
},
210+
"databaseName": "ts-tests"
211+
}
212+
},
213+
{
214+
"commandStartedEvent": {
215+
"command": {
216+
"insert": "test",
217+
"documents": [
218+
{
219+
"_id": 1,
220+
"time": {
221+
"$date": {
222+
"$numberLong": "1552949630482"
223+
}
224+
}
225+
},
226+
{
227+
"_id": 1,
228+
"time": {
229+
"$date": {
230+
"$numberLong": "1552949630483"
231+
}
232+
}
233+
}
234+
]
235+
}
236+
}
237+
},
238+
{
239+
"commandStartedEvent": {
240+
"command": {
241+
"find": "test",
242+
"filter": {},
243+
"sort": {
244+
"time": 1
245+
}
246+
},
247+
"databaseName": "ts-tests"
248+
}
249+
}
250+
]
251+
}
252+
]
253+
}
254+
]
255+
}

src/libmongoc/tests/unified/runner.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1153,7 +1153,7 @@ test_check_outcome_collection (test_t *test,
11531153
expected_sorted = bson_copy_and_sort (&expected);
11541154

11551155

1156-
if (!bson_equal (&actual, &expected)) {
1156+
if (!bson_equal (actual_sorted, expected_sorted)) {
11571157
test_set_error (error,
11581158
"expected %s, but got %s",
11591159
tmp_json (expected_sorted),
@@ -1493,4 +1493,6 @@ test_install_unified (TestSuite *suite)
14931493
run_unified_tests (suite, JSON_DIR "/crud/unified");
14941494

14951495
run_unified_tests (suite, JSON_DIR "/transactions/unified");
1496+
1497+
run_unified_tests (suite, JSON_DIR "/collection-management");
14961498
}

0 commit comments

Comments
 (0)