Skip to content

Commit 558906f

Browse files
committed
CDRIVER-880 add test for failed agg pipeline
1 parent 14c9bdf commit 558906f

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

tests/test-mongoc-collection.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include <bcon.h>
22
#include <mongoc.h>
33
#include <mongoc-client-private.h>
4+
#include <mongoc-cursor-private.h>
45

56
#include "TestSuite.h"
67

@@ -1298,6 +1299,7 @@ test_aggregate (void)
12981299
bool r;
12991300
bson_t opts;
13001301
bson_t *pipeline;
1302+
bson_t *broken_pipeline;
13011303
bson_t *b;
13021304
bson_iter_t iter;
13031305
int i, j;
@@ -1312,6 +1314,7 @@ test_aggregate (void)
13121314
ASSERT (collection);
13131315

13141316
pipeline = BCON_NEW ("pipeline", "[", "{", "$match", "{", "hello", BCON_UTF8 ("world"), "}", "}", "]");
1317+
broken_pipeline = BCON_NEW ("pipeline", "[", "{", "$asdf", "{", "foo", BCON_UTF8 ("bar"), "}", "}", "]");
13151318
b = BCON_NEW ("hello", BCON_UTF8 ("world"));
13161319

13171320
again:
@@ -1323,6 +1326,15 @@ test_aggregate (void)
13231326
MONGOC_INSERT_NONE, b, NULL, &error), error);
13241327
}
13251328

1329+
cursor = mongoc_collection_aggregate (collection, MONGOC_QUERY_NONE, broken_pipeline, NULL, NULL);
1330+
ASSERT (cursor);
1331+
1332+
r = mongoc_cursor_next (cursor, &doc);
1333+
ASSERT (!r);
1334+
ASSERT (mongoc_cursor_error (cursor, &error));
1335+
ASSERT (cursor->failed);
1336+
ASSERT (error.code == 16436);
1337+
13261338
for (i = 0; i < 2; i++) {
13271339
if (i % 2 == 0) {
13281340
cursor = mongoc_collection_aggregate(collection, MONGOC_QUERY_NONE, pipeline, NULL, NULL);
@@ -1385,6 +1397,7 @@ test_aggregate (void)
13851397
mongoc_client_destroy(client);
13861398
bson_destroy(b);
13871399
bson_destroy(pipeline);
1400+
bson_destroy (broken_pipeline);
13881401
}
13891402

13901403

0 commit comments

Comments
 (0)