Skip to content

Commit 194e17e

Browse files
authored
Fix potential duplicate key errors in bulk_write tests (#1359)
1 parent 2233791 commit 194e17e

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/mongocxx/test/bulk_write.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ TEST_CASE("a bulk_write will setup a mongoc bulk operation", "[bulk_write]") {
3636
instance::current();
3737
mongocxx::client client{mongocxx::uri{}};
3838
mongocxx::collection coll = client["db"]["coll"];
39+
CHECK_NOTHROW(coll.drop());
3940
auto construct = libmongoc::collection_create_bulk_operation_with_opts.create_instance();
4041
bool construct_called = false;
4142
bool ordered_value = false;
@@ -75,6 +76,7 @@ TEST_CASE("destruction of a bulk_write will destroy mongoc operation", "[bulk_wr
7576
instance::current();
7677
mongocxx::client client{mongocxx::uri{}};
7778
mongocxx::collection coll = client["db"]["coll"];
79+
CHECK_NOTHROW(coll.drop());
7880
auto destruct = libmongoc::bulk_operation_destroy.create_instance();
7981
bool destruct_called = false;
8082

@@ -184,7 +186,9 @@ class delete_functor {
184186
TEST_CASE("passing write operations to append calls corresponding C function", "[bulk_write]") {
185187
instance::current();
186188
mongocxx::client client{mongocxx::uri{}};
187-
auto bw = client["db"]["coll"].create_bulk_write();
189+
mongocxx::collection coll = client["db"]["coll"];
190+
CHECK_NOTHROW(coll.drop());
191+
auto bw = coll.create_bulk_write();
188192
bsoncxx::builder::basic::document filter_builder, doc_builder, update_doc_builder, collation_builder;
189193
filter_builder.append(kvp("_id", 1));
190194
doc_builder.append(kvp("_id", 2));
@@ -358,7 +362,9 @@ TEST_CASE("passing write operations to append calls corresponding C function", "
358362
TEST_CASE("calling empty on a bulk write before and after appending", "[bulk_write]") {
359363
instance::current();
360364
mongocxx::client client{mongocxx::uri{}, test_util::add_test_server_api()};
361-
auto bw = client["db"]["coll"].create_bulk_write();
365+
mongocxx::collection coll = client["db"]["coll"];
366+
CHECK_NOTHROW(coll.drop());
367+
auto bw = coll.create_bulk_write();
362368

363369
REQUIRE(bw.empty());
364370
bw.append(model::insert_one(make_document(kvp("_id", 1))));

0 commit comments

Comments
 (0)