Skip to content

Commit 8cd8bdc

Browse files
authored
CXX-3323 drop support for MongoDB Server 4.0 or older (#1436)
* Rename test_util::newer_than -> test_util::server_version_is_at_least
1 parent 90ff27c commit 8cd8bdc

File tree

13 files changed

+15
-139
lines changed

13 files changed

+15
-139
lines changed

examples/mongocxx/mongodb.com/transactions_examples.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -265,10 +265,6 @@ int EXAMPLES_CDECL main() {
265265
if (max_wire_version.type() != bsoncxx::type::k_int32) {
266266
throw std::logic_error{"max wire version is not int32"};
267267
}
268-
if (max_wire_version.get_int32().value < 7) {
269-
std::cerr << "Skipping: transactions example requires max wire version is >= 7" << std::endl;
270-
return EXIT_SUCCESS;
271-
}
272268
}
273269

274270
for (auto const& example : examples) {

src/mongocxx/include/mongocxx/v_noabi/mongocxx/result/bulk_write.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,6 @@ class bulk_write {
5959
///
6060
/// @return The number of documents that were modified.
6161
///
62-
/// @throws with server versions below 2.6 due to the field `nModified` not being returned.
63-
///
6462
MONGOCXX_ABI_EXPORT_CDECL(std::int32_t) modified_count() const;
6563

6664
///

src/mongocxx/lib/mongocxx/v_noabi/mongocxx/collection.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1297,12 +1297,8 @@ void collection::_drop(
12971297
scoped_bson_t opts_bson{opts_doc.view()};
12981298
auto result = libmongoc::collection_drop_with_opts(_get_impl().collection_t, opts_bson.bson(), &error);
12991299

1300-
// Throw an exception if the command failed, unless the failure was due to a non-existent
1301-
// collection. We check for this failure using 'code', but we fall back to checking 'message'
1302-
// for old server versions (3.0 and earlier) that do not send a code with the command response.
1303-
if (!result &&
1304-
!(error.code == ::MONGOC_ERROR_COLLECTION_DOES_NOT_EXIST ||
1305-
bsoncxx::v_noabi::stdx::string_view{error.message} == bsoncxx::v_noabi::stdx::string_view{"ns not found"})) {
1300+
// Throw an exception if the command failed, unless the failure was due to a non-existent collection.
1301+
if (!result && error.code != MONGOC_ERROR_COLLECTION_DOES_NOT_EXIST) {
13061302
throw_exception<operation_exception>(error);
13071303
}
13081304
}

src/mongocxx/test/spec/gridfs.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -473,12 +473,6 @@ TEST_CASE("GridFS spec automated tests", "[gridfs_spec]") {
473473

474474
client client{uri{}, test_util::add_test_server_api()};
475475

476-
// Because the GridFS spec tests use write commands that were only added to MongoDB in version
477-
// 2.6, the tests will not run against any server versions older than that.
478-
if (test_util::compare_versions(test_util::get_server_version(), "2.6") < 0) {
479-
return;
480-
}
481-
482476
auto cb = [&](std::string const& test_file) { run_gridfs_tests_in_file(test_file, &client); };
483477

484478
mongocxx::spec::run_tests_in_suite("GRIDFS_TESTS_PATH", cb);

src/mongocxx/test/spec/unified_tests/runner.cpp

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -295,20 +295,6 @@ bool compatible_with_server(bsoncxx::array::element const& requirement) {
295295
}
296296
}
297297

298-
if (auto const csfle = requirement["csfle"]) {
299-
// csfle: Optional boolean. If true, the tests MUST only run if the
300-
// driver and server support Client-Side Field Level Encryption. A
301-
// server supports CSFLE if it is version 4.2.0 or higher. If false,
302-
// tests MUST only run if CSFLE is not enabled. If this field is
303-
// omitted, there is no CSFLE requirement.
304-
std::vector<int> const requires_at_least{4, 2, 0};
305-
bool const is_csfle = csfle.get_bool().value;
306-
if (is_csfle) {
307-
if (!is_compatible_version(requires_at_least, expected)) {
308-
return false;
309-
}
310-
}
311-
}
312298
return true;
313299
}
314300

src/mongocxx/test/v_noabi/client.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -387,8 +387,6 @@ TEST_CASE("integration tests for client metadata handshake feature") {
387387

388388
found_op = true;
389389

390-
std::string server_version = test_util::get_server_version();
391-
392390
REQUIRE(op_view["clientMetadata"]);
393391
auto metadata = op_view["clientMetadata"].get_document();
394392
auto metadata_view = metadata.view();

src/mongocxx/test/v_noabi/client_helpers.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ std::int32_t compare_versions(std::string version1, std::string version2) {
231231
return 0;
232232
}
233233

234-
bool newer_than(std::string version) {
234+
bool server_version_is_at_least(std::string version) {
235235
auto server_version = get_server_version();
236236
return (compare_versions(server_version, version) >= 0);
237237
}

src/mongocxx/test/v_noabi/client_helpers.hh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ std::int32_t compare_versions(std::string version1, std::string version2);
5656
// Returns 'true' if the server version for the default client is at least 'version',
5757
// returns 'false' otherwise.
5858
//
59-
bool newer_than(std::string version);
59+
bool server_version_is_at_least(std::string version);
6060

6161
//
6262
// Converts a hexadecimal string to an string of bytes.

src/mongocxx/test/v_noabi/client_session.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -822,11 +822,6 @@ TEST_CASE("with_transaction", "[session]") {
822822
// The following three tests are prose tests from the with_transaction spec.
823823
SECTION("prose tests for with_transaction") {
824824
SECTION("callback raises a custom error") {
825-
// Multi-document transactions require server 4.2+.
826-
if (compare_versions(get_server_version(), "4.2") < 0) {
827-
SKIP("MongoDB server 4.2 or newer required");
828-
}
829-
830825
// Test an operation_exception
831826
REQUIRE_THROWS_MATCHES(
832827
session.with_transaction([](client_session*) { throw operation_exception{{}, "The meaning of life"}; }),

src/mongocxx/test/v_noabi/client_side_encryption.cpp

Lines changed: 4 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -343,11 +343,6 @@ TEST_CASE("Datakey and double encryption", "[client_side_encryption]") {
343343

344344
mongocxx::client setup_client{uri{}, test_util::add_test_server_api(client_opts)};
345345

346-
if (test_util::get_max_wire_version() < 8) {
347-
// Automatic encryption requires wire version 8.
348-
SKIP("max wire version is < 8");
349-
}
350-
351346
// 2. Drop keyvault.datakeys and db.coll
352347
_setup_drop_collections(setup_client);
353348

@@ -579,11 +574,6 @@ TEST_CASE("External key vault", "[client_side_encryption]") {
579574
test_util::add_test_server_api(),
580575
};
581576

582-
if (test_util::get_max_wire_version() < 8) {
583-
// Automatic encryption requires wire version 8.
584-
SKIP("max wire version is < 8");
585-
}
586-
587577
run_external_key_vault_test(true);
588578
run_external_key_vault_test(false);
589579
}
@@ -599,11 +589,6 @@ TEST_CASE("BSON size limits and batch splitting", "[client_side_encryption]") {
599589
test_util::add_test_server_api(),
600590
};
601591

602-
if (test_util::get_max_wire_version() < 8) {
603-
// Automatic encryption requires wire version 8.
604-
SKIP("max wire version is < 8");
605-
}
606-
607592
// Load in json schema limits/limits-schema.json and limits/limits-key.json
608593
auto limits_schema = _doc_from_file("/limits/limits-schema.json");
609594
auto limits_key = _doc_from_file("/limits/limits-key.json");
@@ -757,11 +742,6 @@ TEST_CASE("Views are prohibited", "[client_side_encryption]") {
757742
test_util::add_test_server_api(),
758743
};
759744

760-
if (test_util::get_max_wire_version() < 8) {
761-
// Automatic encryption requires wire version 8.
762-
SKIP("max wire version is < 8");
763-
}
764-
765745
// Using client, drop and create a view named db.view with an empty pipeline.
766746
// E.g. using the command { "create": "view", "viewOn": "coll" }.
767747
auto db = client["db"];
@@ -1096,11 +1076,6 @@ TEST_CASE("Corpus", "[client_side_encryption]") {
10961076
uri{},
10971077
test_util::add_test_server_api(),
10981078
};
1099-
1100-
if (test_util::get_max_wire_version() < 8) {
1101-
// Automatic encryption requires wire version 8.
1102-
SKIP("max wire version is < 8");
1103-
}
11041079
_run_corpus_test(true);
11051080
_run_corpus_test(false);
11061081
}
@@ -1217,11 +1192,6 @@ TEST_CASE("Custom endpoint", "[client_side_encryption]") {
12171192
test_util::add_test_server_api(),
12181193
};
12191194

1220-
if (test_util::get_max_wire_version() < 8) {
1221-
// Automatic encryption requires wire version 8.
1222-
SKIP("max wire version is < 8");
1223-
}
1224-
12251195
// Call client_encryption.createDataKey() with "aws" as the provider and the following
12261196
// masterKey:
12271197
// {
@@ -1560,11 +1530,6 @@ TEST_CASE("Bypass spawning mongocryptd", "[client_side_encryption]") {
15601530
test_util::add_test_server_api(),
15611531
};
15621532

1563-
if (test_util::get_max_wire_version() < 8) {
1564-
// Automatic encryption requires wire version 8.
1565-
SKIP("max wire version is < 8");
1566-
}
1567-
15681533
auto shared_lib_path = getenv("CRYPT_SHARED_LIB_PATH");
15691534

15701535
auto external_schema_file = _doc_from_file("/external/external-schema.json");
@@ -1703,11 +1668,6 @@ TEST_CASE("KMS TLS expired certificate", "[client_side_encryption]") {
17031668
SKIP("KMS TLS tests disabled (BUILD-14068)");
17041669
}
17051670

1706-
if (test_util::get_max_wire_version() < 8) {
1707-
// Automatic encryption requires wire version 8.
1708-
SKIP("max wire version is < 8");
1709-
}
1710-
17111671
options::client_encryption cse_opts;
17121672
_add_cse_opts(&cse_opts, &setup_client);
17131673
client_encryption client_encryption{std::move(cse_opts)};
@@ -1759,11 +1719,6 @@ TEST_CASE("KMS TLS wrong host certificate", "[client_side_encryption]") {
17591719
SKIP("KMS TLS tests disabled (BUILD-14068)");
17601720
}
17611721

1762-
if (test_util::get_max_wire_version() < 8) {
1763-
// Automatic encryption requires wire version 8.
1764-
SKIP("max wire version is < 8");
1765-
}
1766-
17671722
options::client_encryption cse_opts;
17681723
_add_cse_opts(&cse_opts, &setup_client);
17691724
client_encryption client_encryption{std::move(cse_opts)};
@@ -1868,11 +1823,6 @@ TEST_CASE("KMS TLS Options Tests", "[client_side_encryption][!mayfail]") {
18681823
SKIP("KMS TLS tests disabled (BUILD-14068)");
18691824
}
18701825

1871-
if (test_util::get_max_wire_version() < 8) {
1872-
// Automatic encryption requires wire version 8.
1873-
SKIP("max wire version is < 8");
1874-
}
1875-
18761826
auto client_encryption_no_client_cert =
18771827
make_prose_test_11_ce(&setup_client, "127.0.0.1:9002", "127.0.0.1:9002", "127.0.0.1:5698", with_certs::ca_only);
18781828
auto client_encryption_with_tls =
@@ -2120,7 +2070,7 @@ TEST_CASE("Explicit Encryption", "[client_side_encryption]") {
21202070
test_util::add_test_server_api(),
21212071
};
21222072

2123-
if (!test_util::newer_than("7.0")) {
2073+
if (!test_util::server_version_is_at_least("7.0")) {
21242074
SKIP("MongoDB server 7.0 or newer required");
21252075
}
21262076

@@ -2420,7 +2370,7 @@ TEST_CASE("Create Encrypted Collection", "[client_side_encryption]") {
24202370

24212371
mongocxx::client conn{mongocxx::uri{}, test_util::add_test_server_api()};
24222372

2423-
if (!test_util::newer_than("7.0")) {
2373+
if (!test_util::server_version_is_at_least("7.0")) {
24242374
SKIP("Explicit Encryption tests require MongoDB server 7.0+.");
24252375
}
24262376

@@ -2550,10 +2500,6 @@ TEST_CASE("Unique Index on keyAltNames", "[client_side_encryption]") {
25502500

25512501
CLIENT_SIDE_ENCRYPTION_ENABLED_OR_SKIP();
25522502

2553-
if (!test_util::newer_than("4.2")) {
2554-
SKIP("requires MongoDB server 4.2+");
2555-
}
2556-
25572503
// 1. Create a MongoClient object (referred to as client).
25582504
mongocxx::client client{mongocxx::uri{}, test_util::add_test_server_api()};
25592505

@@ -2691,10 +2637,6 @@ TEST_CASE("Custom Key Material Test", "[client_side_encryption]") {
26912637

26922638
CLIENT_SIDE_ENCRYPTION_ENABLED_OR_SKIP();
26932639

2694-
if (!test_util::newer_than("4.2")) {
2695-
SKIP("MongoDB server 4.2 or newer required");
2696-
}
2697-
26982640
// 1. Create a MongoClient object (referred to as client).
26992641
mongocxx::client client{mongocxx::uri{}, test_util::add_test_server_api()};
27002642

@@ -3037,7 +2979,7 @@ TEST_CASE("Range Explicit Encryption", "[client_side_encryption]") {
30372979
{
30382980
auto client = mongocxx::client(mongocxx::uri(), test_util::add_test_server_api());
30392981

3040-
if (!test_util::newer_than("8.0")) {
2982+
if (!test_util::server_version_is_at_least("8.0")) {
30412983
SKIP("MongoDB server 8.0 or newer required");
30422984
}
30432985

@@ -3443,7 +3385,7 @@ TEST_CASE("Range Explicit Encryption applies defaults", "[client_side_encryption
34433385
test_util::add_test_server_api(),
34443386
};
34453387

3446-
if (!test_util::newer_than("8.0")) {
3388+
if (!test_util::server_version_is_at_least("8.0")) {
34473389
SKIP("MongoDB server 8.0 or newer required");
34483390
}
34493391

0 commit comments

Comments
 (0)