Skip to content

Commit 16b7739

Browse files
committed
Replace wire version integer literals with feature macros
1 parent 6f0232b commit 16b7739

16 files changed

+181
-529
lines changed

src/libmongoc/src/mongoc/mongoc-client-private.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ BSON_BEGIN_DECLS
9696
#define WIRE_VERSION_5_0 13
9797
/* first version to support snapshot reads */
9898
#define WIRE_VERSION_SNAPSHOT_READS 13
99+
/* version corresponding to server 5.1 release */
100+
#define WIRE_VERSION_5_1 14
99101

100102
struct _mongoc_collection_t;
101103

src/libmongoc/tests/test-mongoc-change-stream.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ test_change_stream_pipeline (void)
112112
bson_t *nonempty_pipeline =
113113
tmp_bson ("{ 'pipeline' : [ { '$project' : { 'ns': false } } ] }");
114114

115-
server = mock_server_with_auto_hello (5);
115+
server = mock_server_with_auto_hello (WIRE_VERSION_MIN);
116116
mock_server_run (server);
117117

118118
client =
@@ -614,7 +614,7 @@ _test_getmore_error (const char *server_reply,
614614
mongoc_change_stream_t *stream;
615615
const bson_t *next_doc = NULL;
616616

617-
server = mock_server_with_auto_hello (5);
617+
server = mock_server_with_auto_hello (WIRE_VERSION_MIN);
618618
mock_server_run (server);
619619
client =
620620
test_framework_client_new_from_uri (mock_server_get_uri (server), NULL);
@@ -744,7 +744,7 @@ test_change_stream_resumable_error (void)
744744
": [ { '$changeStream': { 'fullDocument': 'default' } } ], "
745745
"'cursor': { } }";
746746

747-
server = mock_server_with_auto_hello (5);
747+
server = mock_server_with_auto_hello (WIRE_VERSION_MIN);
748748
mock_server_run (server);
749749

750750
uri = mongoc_uri_copy (mock_server_get_uri (server));
@@ -914,7 +914,7 @@ test_change_stream_options (void)
914914
const bson_t *next_doc = NULL;
915915
bson_error_t err;
916916

917-
server = mock_server_with_auto_hello (5);
917+
server = mock_server_with_auto_hello (WIRE_VERSION_MIN);
918918
mock_server_run (server);
919919

920920
client =
@@ -1838,7 +1838,7 @@ _test_resume (const char *opts,
18381838
char *msg;
18391839
const bson_t *doc = NULL;
18401840

1841-
server = mock_server_with_auto_hello (7);
1841+
server = mock_server_with_auto_hello (WIRE_VERSION_4_0);
18421842
mock_server_run (server);
18431843
client =
18441844
test_framework_client_new_from_uri (mock_server_get_uri (server), NULL);

src/libmongoc/tests/test-mongoc-client.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1383,7 +1383,7 @@ test_read_command_with_opts (void)
13831383
future_t *future;
13841384
request_t *request;
13851385

1386-
server = mock_mongos_new (5);
1386+
server = mock_mongos_new (WIRE_VERSION_MIN);
13871387
mock_server_run (server);
13881388
client =
13891389
test_framework_client_new_from_uri (mock_server_get_uri (server), NULL);
@@ -1510,7 +1510,7 @@ test_command_with_opts (void)
15101510
request_t *request;
15111511
bson_t opts = BSON_INITIALIZER;
15121512

1513-
server = mock_mongos_new (5);
1513+
server = mock_mongos_new (WIRE_VERSION_MIN);
15141514
mock_server_run (server);
15151515

15161516
client =
@@ -4152,7 +4152,11 @@ test_mongoc_client_resends_handshake_on_network_error (void)
41524152
server,
41534153
"{'" HANDSHAKE_CMD_LEGACY_HELLO
41544154
"': 1, 'client': {'application': {'name': 'foo'}}}");
4155-
mock_server_replies_simple (request, "{'ok': 1, 'maxWireVersion': 14 }");
4155+
mock_server_replies_simple (
4156+
request,
4157+
tmp_str ("{'ok': 1, 'minWireVersion': %d, 'maxWireVersion': %d}",
4158+
WIRE_VERSION_MIN,
4159+
WIRE_VERSION_5_1));
41564160
request_destroy (request);
41574161
request = mock_server_receives_msg (
41584162
server, MONGOC_QUERY_NONE, tmp_bson ("{'ping': 1}"));
@@ -4173,7 +4177,10 @@ test_mongoc_client_resends_handshake_on_network_error (void)
41734177
server,
41744178
"{'" HANDSHAKE_CMD_LEGACY_HELLO
41754179
"': 1, 'client': {'application': {'name': 'foo'}}}");
4176-
mock_server_replies_simple (request, "{'ok': 1, 'maxWireVersion': 14 }");
4180+
mock_server_replies_simple (
4181+
request,
4182+
tmp_str ("{'ok': 1, 'minWireVersion': %d, 'maxWireVersion': %d }",
4183+
WIRE_VERSION_5_1));
41774184
request_destroy (request);
41784185

41794186
request = mock_server_receives_msg (

src/libmongoc/tests/test-mongoc-cluster.c

Lines changed: 17 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,7 +1034,6 @@ test_error_msg_t errors[] = {
10341034
message. */
10351035
static void
10361036
_test_not_primary (bool pooled,
1037-
bool use_op_msg,
10381037
run_command_fn_t run_command,
10391038
cleanup_fn_t cleanup_fn)
10401039
{
@@ -1050,7 +1049,7 @@ _test_not_primary (bool pooled,
10501049
const mongoc_server_description_t *sd;
10511050
char *reply;
10521051

1053-
server = mock_server_with_auto_hello (use_op_msg ? 6 : 5);
1052+
server = mock_server_with_auto_hello (WIRE_VERSION_MIN);
10541053
mock_server_run (server);
10551054

10561055
if (pooled) {
@@ -1133,33 +1132,18 @@ function_command_simple_cleanup (future_t *future)
11331132

11341133

11351134
static void
1136-
test_not_primary_single_op_query (void)
1137-
{
1138-
_test_not_primary (
1139-
false, false, future_command_simple, function_command_simple_cleanup);
1140-
}
1141-
1142-
1143-
static void
1144-
test_not_primary_pooled_op_query (void)
1145-
{
1146-
_test_not_primary (
1147-
true, false, future_command_simple, function_command_simple_cleanup);
1148-
}
1149-
1150-
static void
1151-
test_not_primary_single_op_msg (void)
1135+
test_not_primary_single (void)
11521136
{
11531137
_test_not_primary (
1154-
false, true, future_command_simple, function_command_simple_cleanup);
1138+
false, future_command_simple, function_command_simple_cleanup);
11551139
}
11561140

11571141

11581142
static void
1159-
test_not_primary_pooled_op_msg (void)
1143+
test_not_primary_pooled (void)
11601144
{
11611145
_test_not_primary (
1162-
true, true, future_command_simple, function_command_simple_cleanup);
1146+
true, future_command_simple, function_command_simple_cleanup);
11631147
}
11641148

11651149

@@ -1196,33 +1180,18 @@ future_command_private_cleanup (future_t *future)
11961180

11971181

11981182
static void
1199-
test_not_primary_auth_single_op_query (void)
1183+
test_not_primary_auth_single (void)
12001184
{
12011185
_test_not_primary (
1202-
false, false, future_command_private, future_command_private_cleanup);
1186+
false, future_command_private, future_command_private_cleanup);
12031187
}
12041188

12051189

12061190
static void
1207-
test_not_primary_auth_pooled_op_query (void)
1191+
test_not_primary_auth_pooled (void)
12081192
{
12091193
_test_not_primary (
1210-
true, false, future_command_private, future_command_private_cleanup);
1211-
}
1212-
1213-
static void
1214-
test_not_primary_auth_single_op_msg (void)
1215-
{
1216-
_test_not_primary (
1217-
false, true, future_command_private, future_command_private_cleanup);
1218-
}
1219-
1220-
1221-
static void
1222-
test_not_primary_auth_pooled_op_msg (void)
1223-
{
1224-
_test_not_primary (
1225-
true, true, future_command_private, future_command_private_cleanup);
1194+
true, future_command_private, future_command_private_cleanup);
12261195
}
12271196

12281197

@@ -2033,36 +2002,20 @@ test_cluster_install (TestSuite *suite)
20332002
test_advanced_cluster_time_not_sent_to_standalone,
20342003
test_framework_skip_if_no_crypto);
20352004
TestSuite_AddMockServerTest (suite,
2036-
"/Cluster/not_primary/single/op_query",
2037-
test_not_primary_single_op_query,
2038-
test_framework_skip_if_slow);
2039-
TestSuite_AddMockServerTest (suite,
2040-
"/Cluster/not_primary/pooled/op_query",
2041-
test_not_primary_pooled_op_query,
2042-
test_framework_skip_if_slow);
2043-
TestSuite_AddMockServerTest (suite,
2044-
"/Cluster/not_primary/single/op_msg",
2045-
test_not_primary_single_op_msg,
2046-
test_framework_skip_if_slow);
2047-
TestSuite_AddMockServerTest (suite,
2048-
"/Cluster/not_primary/pooled/op_msg",
2049-
test_not_primary_pooled_op_msg,
2050-
test_framework_skip_if_slow);
2051-
TestSuite_AddMockServerTest (suite,
2052-
"/Cluster/not_primary_auth/single/op_query",
2053-
test_not_primary_auth_single_op_query,
2005+
"/Cluster/not_primary/single",
2006+
test_not_primary_single,
20542007
test_framework_skip_if_slow);
20552008
TestSuite_AddMockServerTest (suite,
2056-
"/Cluster/not_primary_auth/pooled/op_query",
2057-
test_not_primary_auth_pooled_op_query,
2009+
"/Cluster/not_primary/pooled",
2010+
test_not_primary_pooled,
20582011
test_framework_skip_if_slow);
20592012
TestSuite_AddMockServerTest (suite,
2060-
"/Cluster/not_primary_auth/single/op_msg",
2061-
test_not_primary_auth_single_op_msg,
2013+
"/Cluster/not_primary_auth/single",
2014+
test_not_primary_auth_single,
20622015
test_framework_skip_if_slow);
20632016
TestSuite_AddMockServerTest (suite,
2064-
"/Cluster/not_primary_auth/pooled/op_msg",
2065-
test_not_primary_auth_pooled_op_msg,
2017+
"/Cluster/not_primary_auth/pooled",
2018+
test_not_primary_auth_pooled,
20662019
test_framework_skip_if_slow);
20672020
TestSuite_AddMockServerTest (
20682021
suite, "/Cluster/hello_fails", test_cluster_hello_fails);

src/libmongoc/tests/test-mongoc-collection-find-with-opts.c

Lines changed: 3 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@ static void
4646
_test_collection_op_query_or_find_command (
4747
test_collection_find_with_opts_t *test_data,
4848
check_request_fn_t check_request_fn,
49-
const char *reply_json,
50-
int32_t max_wire_version)
49+
const char *reply_json)
5150
{
5251
mock_server_t *server;
5352
mongoc_client_t *client;
@@ -58,7 +57,7 @@ _test_collection_op_query_or_find_command (
5857
request_t *request;
5958
const bson_t *doc;
6059

61-
server = mock_server_with_auto_hello (max_wire_version);
60+
server = mock_server_with_auto_hello (WIRE_VERSION_MIN);
6261
mock_server_run (server);
6362
client =
6463
test_framework_client_new_from_uri (mock_server_get_uri (server), NULL);
@@ -84,56 +83,6 @@ _test_collection_op_query_or_find_command (
8483
}
8584

8685

87-
static request_t *
88-
_check_op_query (mock_server_t *server,
89-
test_collection_find_with_opts_t *test_data)
90-
{
91-
mongoc_query_flags_t flags;
92-
request_t *request;
93-
const bson_t *doc;
94-
bson_iter_t iter;
95-
uint32_t len;
96-
const uint8_t *data;
97-
bson_t query;
98-
99-
/* Server Selection Spec: all queries to standalone set secondaryOk. */
100-
flags = test_data->expected_flags | MONGOC_QUERY_SECONDARY_OK;
101-
102-
request =
103-
mock_server_receives_query (server,
104-
"db.collection",
105-
flags,
106-
test_data->expected_skip,
107-
test_data->expected_n_return,
108-
test_data->expected_op_query,
109-
test_data->expected_op_query_projection);
110-
111-
ASSERT (request);
112-
113-
/* check that nothing unexpected is in $query */
114-
if (bson_empty (test_data->filter_bson)) {
115-
doc = request_get_doc (request, 0);
116-
117-
if (bson_iter_init_find (&iter, doc, "$query")) {
118-
ASSERT (BSON_ITER_HOLDS_DOCUMENT (&iter));
119-
bson_iter_document (&iter, &len, &data);
120-
bson_init_static (&query, data, (size_t) len);
121-
ASSERT (bson_empty (&query));
122-
}
123-
}
124-
125-
return request;
126-
}
127-
128-
129-
static void
130-
_test_collection_op_query (test_collection_find_with_opts_t *test_data)
131-
{
132-
_test_collection_op_query_or_find_command (
133-
test_data, _check_op_query, "{}", 3 /* wire version */);
134-
}
135-
136-
13786
static request_t *
13887
_check_find_command (mock_server_t *server,
13988
test_collection_find_with_opts_t *test_data)
@@ -160,8 +109,7 @@ _test_collection_find_command (test_collection_find_with_opts_t *test_data)
160109
" 'cursor': {"
161110
" 'id': 0,"
162111
" 'ns': 'db.collection',"
163-
" 'firstBatch': [{}]}}",
164-
4 /* max wire version */);
112+
" 'firstBatch': [{}]}}");
165113
}
166114

167115

@@ -173,7 +121,6 @@ _test_collection_find_with_opts (test_collection_find_with_opts_t *test_data)
173121
test_data->filter_bson = tmp_bson (test_data->filter);
174122
test_data->opts_bson = tmp_bson (test_data->opts);
175123

176-
_test_collection_op_query (test_data);
177124
_test_collection_find_command (test_data);
178125
}
179126

0 commit comments

Comments
 (0)