@@ -34,36 +34,39 @@ _get_test_uri (void)
34
34
static void
35
35
_setup_test_with_client (mongoc_client_t * client )
36
36
{
37
- mongoc_write_concern_t * wc ;
38
- mongoc_database_t * db ;
39
- mongoc_collection_t * coll ;
40
37
bson_error_t error ;
41
- bson_t * opts ;
42
38
43
39
ASSERT (client );
44
40
45
- wc = mongoc_write_concern_new ();
46
- mongoc_write_concern_set_wmajority (wc , -1 );
47
- opts = bson_new ();
48
- ASSERT (mongoc_write_concern_append (wc , opts ));
49
-
50
41
/* Drop the "step-down.step-down" collection and re-create it */
51
- coll = mongoc_client_get_collection (client , "step-down" , "step-down" );
52
- if (!mongoc_collection_drop (coll , & error )) {
53
- if (NULL == strstr (error .message , "ns not found" )) {
54
- ASSERT_OR_PRINT (false, error );
42
+ {
43
+ mongoc_collection_t * const coll = mongoc_client_get_collection (client , "step-down" , "step-down" );
44
+ if (!mongoc_collection_drop (coll , & error )) {
45
+ if (NULL == strstr (error .message , "ns not found" )) {
46
+ ASSERT_OR_PRINT (false, error );
47
+ }
55
48
}
49
+ mongoc_collection_destroy (coll );
56
50
}
57
51
58
- db = mongoc_client_get_database (client , "step-down" );
59
- mongoc_collection_destroy (coll );
60
- coll = mongoc_database_create_collection (db , "step-down" , opts , & error );
61
- ASSERT_OR_PRINT (coll , error );
52
+ {
53
+ mongoc_database_t * const db = mongoc_client_get_database (client , "step-down" );
62
54
63
- mongoc_collection_destroy (coll );
64
- mongoc_database_destroy (db );
65
- mongoc_write_concern_destroy (wc );
66
- bson_destroy (opts );
55
+ bson_t opts = BSON_INITIALIZER ;
56
+
57
+ {
58
+ mongoc_write_concern_t * const wc = mongoc_write_concern_new ();
59
+ mongoc_write_concern_set_wmajority (wc , -1 );
60
+ ASSERT (mongoc_write_concern_append (wc , & opts ));
61
+ mongoc_write_concern_destroy (wc );
62
+ }
63
+
64
+ mongoc_collection_t * const coll = mongoc_database_create_collection (db , "step-down" , & opts , & error );
65
+ ASSERT_OR_PRINT (coll , error );
66
+ mongoc_collection_destroy (coll );
67
+ mongoc_database_destroy (db );
68
+ bson_destroy (& opts );
69
+ }
67
70
}
68
71
69
72
static int
@@ -132,26 +135,17 @@ _run_test_single_or_pooled (_test_fn_t test, bool use_pooled)
132
135
static void
133
136
test_getmore_iteration (mongoc_client_t * client )
134
137
{
135
- mongoc_write_concern_t * wc ;
136
138
mongoc_database_t * db ;
137
139
mongoc_collection_t * coll ;
138
140
mongoc_cursor_t * cursor ;
139
141
const bson_t * doc ;
140
142
bson_error_t error ;
141
- bson_t * insert ;
142
- bson_t * opts ;
143
143
bool res ;
144
144
int conn_count ;
145
- int i ;
146
145
uint32_t primary_id ;
147
146
148
147
ASSERT (client );
149
148
150
- wc = mongoc_write_concern_new ();
151
- mongoc_write_concern_set_wmajority (wc , -1 );
152
- opts = bson_new ();
153
- ASSERT (mongoc_write_concern_append (wc , opts ));
154
-
155
149
coll = mongoc_client_get_collection (client , "step-down" , "step-down" );
156
150
157
151
db = mongoc_client_get_database (client , "admin" );
@@ -168,13 +162,26 @@ test_getmore_iteration (mongoc_client_t *client)
168
162
conn_count = _connection_count (client , primary_id );
169
163
170
164
/* Insert 5 documents */
171
- for (i = 0 ; i < 5 ; i ++ ) {
172
- insert = bson_new ();
165
+ {
166
+ bson_t opts = BSON_INITIALIZER ;
167
+
168
+ {
169
+ mongoc_write_concern_t * const wc = mongoc_write_concern_new ();
170
+ mongoc_write_concern_set_wmajority (wc , -1 );
171
+ ASSERT (mongoc_write_concern_append (wc , & opts ));
172
+ mongoc_write_concern_destroy (wc );
173
+ }
174
+
175
+ for (int i = 0 ; i < 5 ; i ++ ) {
176
+ bson_t insert = BSON_INITIALIZER ;
173
177
174
- bson_append_int32 (insert , "a" , -1 , i );
175
- ASSERT (mongoc_collection_insert_one (coll , insert , opts , NULL , NULL ));
178
+ bson_append_int32 (& insert , "a" , -1 , i );
179
+ ASSERT (mongoc_collection_insert_one (coll , & insert , & opts , NULL , NULL ));
180
+
181
+ bson_destroy (& insert );
182
+ }
176
183
177
- bson_destroy (insert );
184
+ bson_destroy (& opts );
178
185
}
179
186
180
187
/* Retrieve the first batch of 2 documents */
@@ -200,8 +207,6 @@ test_getmore_iteration (mongoc_client_t *client)
200
207
mongoc_cursor_destroy (cursor );
201
208
mongoc_collection_destroy (coll );
202
209
mongoc_database_destroy (db );
203
- mongoc_write_concern_destroy (wc );
204
- bson_destroy (opts );
205
210
}
206
211
207
212
static void
0 commit comments