Skip to content

Commit 08f9542

Browse files
alcaeuskevinAlbs
andauthored
Add missing features in unified test format (#820)
* CDRIVER-4066 "Support" version 1.2 of unified test format Since the only tests that are using the loop operation and storeEventsAsEntities are the drivers-atlas-testing tests, we can defer implementation of those two features until the atlas testing project. * CDRIVER-4060 Implement version 1.3 of unified test format Note that implementing the serverless topology check will be done separately * CDRIVER-4064 Support serverless runOnRequirement in test runner * Avoid early exit in complex check functions Co-authored-by: Kevin Albertson <[email protected]> * Error when encountering unsupported functionality * Don't call result_check when ignoreResultAndError is used * Reference CMAP ticket * Don't require saveResultAsEntity for createFindCursor operation * Set return value after fetching data from cursor Co-authored-by: Kevin Albertson <[email protected]>
1 parent c6b1ed0 commit 08f9542

File tree

8 files changed

+252
-21
lines changed

8 files changed

+252
-21
lines changed

CONTRIBUTING.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@ Additional environment variables:
157157
* `MONGOC_TEST_MONITORING_VERBOSE`: set to `on` for verbose output from
158158
Application Performance Monitoring tests.
159159
* `MONGOC_TEST_COMPRESSORS=snappy,zlib`: wire protocol compressors to use
160+
* `MONGOC_TEST_IS_SERVERLESS` (bool): defaults to `false`. Used to indicate
161+
that tests are run against a serverless cluster.
160162

161163
If you start `mongod` with SSL, set these variables to configure how
162164
`test-libmongoc` connects to it:

src/libmongoc/tests/test-libmongoc.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2633,6 +2633,12 @@ test_framework_resolve_path (const char *path, char *resolved)
26332633
}
26342634
}
26352635

2636+
bool
2637+
test_framework_is_serverless (void)
2638+
{
2639+
return test_framework_getenv_bool ("MONGOC_TEST_IS_SERVERLESS");
2640+
}
2641+
26362642
int
26372643
test_framework_skip_if_time_sensitive (void)
26382644
{

src/libmongoc/tests/test-libmongoc.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,4 +256,7 @@ test_framework_skip_if_no_getlasterror (void);
256256
int
257257
test_framework_skip_if_no_exhaust_cursors (void);
258258

259+
bool
260+
test_framework_is_serverless (void);
261+
259262
#endif

src/libmongoc/tests/unified/entity-map.c

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ entity_client_new (entity_map_t *em, bson_t *bson, bson_error_t *error)
257257
bson_t *uri_options = NULL;
258258
bool *use_multiple_mongoses = NULL;
259259
bson_t *observe_events = NULL;
260+
bson_t *store_events_as_entities = NULL;
260261
bson_t *server_api = NULL;
261262
bool can_reduce_heartbeat = false;
262263
mongoc_server_api_t *api = NULL;
@@ -274,6 +275,8 @@ entity_client_new (entity_map_t *em, bson_t *bson, bson_error_t *error)
274275
bson_parser_doc_optional (parser, "serverApi", &server_api);
275276
bson_parser_bool_optional (
276277
parser, "observeSensitiveCommands", &entity->observe_sensitive_commands);
278+
bson_parser_array_optional (
279+
parser, "storeEventsAsEntities", &store_events_as_entities);
277280

278281
if (!bson_parser_parse (parser, bson, error)) {
279282
goto done;
@@ -370,6 +373,12 @@ entity_client_new (entity_map_t *em, bson_t *bson, bson_error_t *error)
370373
}
371374
mongoc_client_set_apm_callbacks (client, callbacks, entity);
372375

376+
if (store_events_as_entities) {
377+
/* TODO: CDRIVER-3867 Comprehensive Atlas Testing */
378+
test_set_error (error, "storeEventsAsEntities is not supported");
379+
goto done;
380+
}
381+
373382
ret = true;
374383
done:
375384
mongoc_uri_destroy (uri);
@@ -379,6 +388,7 @@ entity_client_new (entity_map_t *em, bson_t *bson, bson_error_t *error)
379388
bson_destroy (uri_options);
380389
bson_free (use_multiple_mongoses);
381390
bson_destroy (observe_events);
391+
bson_destroy (store_events_as_entities);
382392
bson_destroy (server_api);
383393
if (!ret) {
384394
entity_destroy (entity);
@@ -875,6 +885,10 @@ entity_destroy (entity_t *entity)
875885
mongoc_gridfs_bucket_t *bucket = entity->value;
876886

877887
mongoc_gridfs_bucket_destroy (bucket);
888+
} else if (0 == strcmp ("cursor", entity->type)) {
889+
mongoc_cursor_t *cursor = entity->value;
890+
891+
mongoc_cursor_destroy (cursor);
878892
} else {
879893
test_error ("Attempting to destroy unrecognized entity type: %s, id: %s",
880894
entity->type,
@@ -910,6 +924,20 @@ entity_map_get (entity_map_t *entity_map, const char *id, bson_error_t *error)
910924
return NULL;
911925
}
912926

927+
bool
928+
entity_map_delete (entity_map_t *em, const char *id, bson_error_t *error)
929+
{
930+
entity_t *entity = entity_map_get (em, id, error);
931+
if (!entity) {
932+
return false;
933+
}
934+
935+
LL_DELETE (em->entities, entity);
936+
entity_destroy (entity);
937+
938+
return true;
939+
}
940+
913941
static entity_t *
914942
_entity_map_get_by_type (entity_map_t *entity_map,
915943
const char *id,
@@ -984,6 +1012,18 @@ entity_map_get_changestream (entity_map_t *entity_map,
9841012
return (mongoc_change_stream_t *) entity->value;
9851013
}
9861014

1015+
mongoc_cursor_t *
1016+
entity_map_get_cursor (entity_map_t *entity_map,
1017+
const char *id,
1018+
bson_error_t *error)
1019+
{
1020+
entity_t *entity = _entity_map_get_by_type (entity_map, id, "cursor", error);
1021+
if (!entity) {
1022+
return NULL;
1023+
}
1024+
return (mongoc_cursor_t *) entity->value;
1025+
}
1026+
9871027
bson_val_t *
9881028
entity_map_get_bson (entity_map_t *entity_map,
9891029
const char *id,
@@ -1079,6 +1119,15 @@ entity_map_add_changestream (entity_map_t *em,
10791119
em, id, "changestream", (void *) changestream, error);
10801120
}
10811121

1122+
bool
1123+
entity_map_add_cursor (entity_map_t *em,
1124+
const char *id,
1125+
mongoc_cursor_t *cursor,
1126+
bson_error_t *error)
1127+
{
1128+
return _entity_map_add (em, id, "cursor", (void *) cursor, error);
1129+
}
1130+
10821131
bool
10831132
entity_map_add_bson (entity_map_t *em,
10841133
const char *id,

src/libmongoc/tests/unified/entity-map.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,13 @@ entity_map_add_changestream (entity_map_t *em,
7171
mongoc_change_stream_t *changestream,
7272
bson_error_t *error);
7373

74+
/* Steals ownership of cursor. */
75+
bool
76+
entity_map_add_cursor (entity_map_t *em,
77+
const char *id,
78+
mongoc_cursor_t *cursor,
79+
bson_error_t *error);
80+
7481
/* Copies val */
7582
bool
7683
entity_map_add_bson (entity_map_t *em,
@@ -82,6 +89,11 @@ entity_map_add_bson (entity_map_t *em,
8289
entity_t *
8390
entity_map_get (entity_map_t *em, const char *id, bson_error_t *error);
8491

92+
/* Removes an entity from the entity map. Returns false and sets @error if @id
93+
* does not map to an entry. */
94+
bool
95+
entity_map_delete (entity_map_t *em, const char *id, bson_error_t *error);
96+
8597
mongoc_client_t *
8698
entity_map_get_client (entity_map_t *entity_map,
8799
const char *id,
@@ -102,6 +114,11 @@ entity_map_get_changestream (entity_map_t *entity_map,
102114
const char *id,
103115
bson_error_t *error);
104116

117+
mongoc_cursor_t *
118+
entity_map_get_cursor (entity_map_t *entity_map,
119+
const char *id,
120+
bson_error_t *error);
121+
105122
mongoc_client_session_t *
106123
entity_map_get_session (entity_map_t *entity_map,
107124
const char *id,

0 commit comments

Comments
 (0)