Skip to content

Commit 84907a1

Browse files
committed
CDRIVER-735 only test allowDiskUse on new mongods
The "aggregate" command only accepts allowDiskUse in mongod 2.6+.
1 parent 35312fa commit 84907a1

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

tests/test-libmongoc.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -847,6 +847,24 @@ test_framework_is_mongos (void)
847847
return is_mongos;
848848
}
849849

850+
851+
bool
852+
test_framework_max_wire_version_at_least (int version)
853+
{
854+
bson_t reply;
855+
bson_iter_t iter;
856+
bool at_least;
857+
858+
call_ismaster (&reply);
859+
860+
at_least = (bson_iter_init_find (&iter, &reply, "maxWireVersion")
861+
&& bson_iter_as_int64 (&iter) >= version);
862+
863+
bson_destroy (&reply);
864+
865+
return at_least;
866+
}
867+
850868
int
851869
main (int argc,
852870
char *argv[])

tests/test-libmongoc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ mongoc_uri_t *test_framework_get_uri (void);
3737
mongoc_client_t *test_framework_client_new (void);
3838
mongoc_client_pool_t *test_framework_client_pool_new (void);
3939
bool test_framework_is_mongos (void);
40+
bool test_framework_max_wire_version_at_least (int version);
4041

4142
typedef struct _debug_stream_stats_t {
4243
int n_destroyed;

tests/test-mongoc-collection.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1227,9 +1227,14 @@ test_aggregate (void)
12271227
ASSERT (cursor);
12281228
} else {
12291229
bson_init (&opts);
1230-
BSON_APPEND_INT32 (&opts, "batchSize", 10);
1231-
BSON_APPEND_BOOL (&opts, "allowDiskUse", true);
12321230

1231+
/* servers < 2.6 error is passed allowDiskUse */
1232+
if (test_framework_max_wire_version_at_least (2)) {
1233+
BSON_APPEND_BOOL (&opts, "allowDiskUse", true);
1234+
}
1235+
1236+
/* this is ok, the driver silently omits batchSize if server < 2.6 */
1237+
BSON_APPEND_INT32 (&opts, "batchSize", 10);
12331238
cursor = mongoc_collection_aggregate(collection, MONGOC_QUERY_NONE, pipeline, &opts, NULL);
12341239
ASSERT (cursor);
12351240

0 commit comments

Comments
 (0)