|
3 | 3 | #include <mongoc-client-private.h> |
4 | 4 | #include <mongoc-cursor-private.h> |
5 | 5 | #include <mongoc-collection-private.h> |
6 | | -#include <mongoc-write-concern-private.h> |
7 | 6 |
|
8 | 7 | #include "TestSuite.h" |
9 | 8 |
|
|
13 | 12 | #include "mock_server/mock-server.h" |
14 | 13 |
|
15 | 14 |
|
16 | | -static void |
17 | | -test_aggregate_w_write_concern (void *context) { |
18 | | - mongoc_cursor_t *cursor; |
19 | | - mongoc_client_t *client; |
20 | | - mongoc_collection_t *collection; |
21 | | - mongoc_write_concern_t *good_wc; |
22 | | - mongoc_write_concern_t *bad_wc; |
23 | | - bson_t *pipeline; |
24 | | - char *json; |
25 | | - bool wire_version_5; |
26 | | - const bson_t *doc; |
27 | | - bson_error_t error; |
28 | | - |
29 | | - /* set up */ |
30 | | - good_wc = mongoc_write_concern_new (); |
31 | | - bad_wc = mongoc_write_concern_new (); |
32 | | - |
33 | | - client = test_framework_client_new (); |
34 | | - assert (client); |
35 | | - ASSERT (mongoc_client_set_error_api (client, 2)); |
36 | | - |
37 | | - collection = mongoc_client_get_collection (client, "test", "test"); |
38 | | - |
39 | | - /* determine server config */ |
40 | | - wire_version_5 = test_framework_max_wire_version_at_least (5); |
41 | | - |
42 | | - /* pipeline that writes to collection */ |
43 | | - json = bson_strdup_printf ("[{'$out': '%s'}]", |
44 | | - collection->collection); |
45 | | - pipeline = tmp_bson (json); |
46 | | - |
47 | | - /* collection aggregate with valid writeConcern: no error */ |
48 | | - mongoc_write_concern_set_w (good_wc, 1); |
49 | | - cursor = mongoc_collection_aggregate_with_write_concern ( |
50 | | - collection, MONGOC_QUERY_NONE, |
51 | | - pipeline, NULL, NULL, good_wc); |
52 | | - ASSERT (cursor); |
53 | | - mongoc_cursor_next (cursor, &doc); |
54 | | - |
55 | | - ASSERT_OR_PRINT (!mongoc_cursor_error (cursor, &error), error); |
56 | | - mongoc_cursor_destroy (cursor); |
57 | | - |
58 | | - /* writeConcern that will not pass mongoc_write_concern_is_valid */ |
59 | | - bad_wc->wtimeout = -10; |
60 | | - cursor = mongoc_collection_aggregate_with_write_concern ( |
61 | | - collection, MONGOC_QUERY_NONE, |
62 | | - pipeline, NULL, NULL, bad_wc); |
63 | | - ASSERT (cursor); |
64 | | - ASSERT_ERROR_CONTAINS ( |
65 | | - cursor->error, MONGOC_ERROR_COMMAND, |
66 | | - MONGOC_ERROR_COMMAND_INVALID_ARG, |
67 | | - "Invalid mongoc_write_concern_t"); |
68 | | - bad_wc->wtimeout = 0; |
69 | | - |
70 | | - /* collection aggregate with invalid writeConcern: skip mongos */ |
71 | | - if (!test_framework_is_mongos ()) { |
72 | | - mongoc_cursor_destroy (cursor); |
73 | | - |
74 | | - mongoc_write_concern_set_w (bad_wc, 99); |
75 | | - cursor = mongoc_collection_aggregate_with_write_concern ( |
76 | | - collection, MONGOC_QUERY_NONE, |
77 | | - pipeline, NULL, NULL, bad_wc); |
78 | | - ASSERT (cursor); |
79 | | - |
80 | | - mongoc_cursor_next (cursor, &doc); |
81 | | - |
82 | | - if (wire_version_5) { |
83 | | - if (test_framework_is_replset ()) { /* replica set */ |
84 | | - ASSERT_OR_PRINT (!mongoc_cursor_error (cursor, &error), error); |
85 | | - } else { /* standalone */ |
86 | | - ASSERT_CMPINT (cursor->error.domain, ==, MONGOC_ERROR_SERVER); |
87 | | - ASSERT_CMPINT (cursor->error.code, ==, 2); |
88 | | - } |
89 | | - } else { /* if server wire version <= 4, no error */ |
90 | | - ASSERT_OR_PRINT (!mongoc_cursor_error (cursor, &error), error); |
91 | | - } |
92 | | - } |
93 | | - |
94 | | - mongoc_write_concern_destroy (good_wc); |
95 | | - mongoc_write_concern_destroy (bad_wc); |
96 | | - mongoc_collection_destroy (collection); |
97 | | - mongoc_cursor_destroy (cursor); |
98 | | - mongoc_client_destroy (client); |
99 | | - bson_free (json); |
100 | | -} |
101 | | - |
102 | | - |
103 | 15 | static void |
104 | 16 | test_read_prefs_is_valid (void) { |
105 | 17 | mongoc_collection_t *collection; |
@@ -3451,10 +3363,7 @@ test_collection_install (TestSuite *suite) |
3451 | 3363 | { |
3452 | 3364 | test_aggregate_install (suite); |
3453 | 3365 |
|
3454 | | - TestSuite_AddFull (suite, "/Collection/aggregate/write_concern", |
3455 | | - test_aggregate_w_write_concern, NULL, NULL, |
3456 | | - test_framework_skip_if_max_version_version_less_than_2); |
3457 | | - TestSuite_AddLive (suite, "/Collection/read_prefs_is_valid", |
| 3366 | + TestSuite_AddLive (suite, "/Collection/read_prefs_is_valid", |
3458 | 3367 | test_read_prefs_is_valid); |
3459 | 3368 | TestSuite_AddLive (suite, "/Collection/insert_bulk", test_insert_bulk); |
3460 | 3369 | TestSuite_AddLive (suite, |
|
0 commit comments