Skip to content

Add missing features in unified test format #820

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Aug 4, 2021
2 changes: 2 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ Additional environment variables:
* `MONGOC_TEST_MONITORING_VERBOSE`: set to `on` for verbose output from
Application Performance Monitoring tests.
* `MONGOC_TEST_COMPRESSORS=snappy,zlib`: wire protocol compressors to use
* `MONGOC_TEST_IS_SERVERLESS` (bool): defaults to `false`. Used to indicate
that tests are run against a serverless cluster.

If you start `mongod` with SSL, set these variables to configure how
`test-libmongoc` connects to it:
Expand Down
6 changes: 6 additions & 0 deletions src/libmongoc/tests/test-libmongoc.c
Original file line number Diff line number Diff line change
Expand Up @@ -2633,6 +2633,12 @@ test_framework_resolve_path (const char *path, char *resolved)
}
}

bool
test_framework_is_serverless (void)
{
return test_framework_getenv_bool ("MONGOC_TEST_IS_SERVERLESS");
}

int
test_framework_skip_if_time_sensitive (void)
{
Expand Down
3 changes: 3 additions & 0 deletions src/libmongoc/tests/test-libmongoc.h
Original file line number Diff line number Diff line change
Expand Up @@ -256,4 +256,7 @@ test_framework_skip_if_no_getlasterror (void);
int
test_framework_skip_if_no_exhaust_cursors (void);

bool
test_framework_is_serverless (void);

#endif
49 changes: 49 additions & 0 deletions src/libmongoc/tests/unified/entity-map.c
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ entity_client_new (entity_map_t *em, bson_t *bson, bson_error_t *error)
bson_t *uri_options = NULL;
bool *use_multiple_mongoses = NULL;
bson_t *observe_events = NULL;
bson_t *store_events_as_entities = NULL;
bson_t *server_api = NULL;
bool can_reduce_heartbeat = false;
mongoc_server_api_t *api = NULL;
Expand All @@ -274,6 +275,8 @@ entity_client_new (entity_map_t *em, bson_t *bson, bson_error_t *error)
bson_parser_doc_optional (parser, "serverApi", &server_api);
bson_parser_bool_optional (
parser, "observeSensitiveCommands", &entity->observe_sensitive_commands);
bson_parser_array_optional (
parser, "storeEventsAsEntities", &store_events_as_entities);

if (!bson_parser_parse (parser, bson, error)) {
goto done;
Expand Down Expand Up @@ -370,6 +373,12 @@ entity_client_new (entity_map_t *em, bson_t *bson, bson_error_t *error)
}
mongoc_client_set_apm_callbacks (client, callbacks, entity);

if (store_events_as_entities) {
/* TODO: CDRIVER-3867 Comprehensive Atlas Testing */
test_set_error (error, "storeEventsAsEntities is not supported");
goto done;
}

ret = true;
done:
mongoc_uri_destroy (uri);
Expand All @@ -379,6 +388,7 @@ entity_client_new (entity_map_t *em, bson_t *bson, bson_error_t *error)
bson_destroy (uri_options);
bson_free (use_multiple_mongoses);
bson_destroy (observe_events);
bson_destroy (store_events_as_entities);
bson_destroy (server_api);
if (!ret) {
entity_destroy (entity);
Expand Down Expand Up @@ -875,6 +885,10 @@ entity_destroy (entity_t *entity)
mongoc_gridfs_bucket_t *bucket = entity->value;

mongoc_gridfs_bucket_destroy (bucket);
} else if (0 == strcmp ("cursor", entity->type)) {
mongoc_cursor_t *cursor = entity->value;

mongoc_cursor_destroy (cursor);
} else {
test_error ("Attempting to destroy unrecognized entity type: %s, id: %s",
entity->type,
Expand Down Expand Up @@ -910,6 +924,20 @@ entity_map_get (entity_map_t *entity_map, const char *id, bson_error_t *error)
return NULL;
}

bool
entity_map_delete (entity_map_t *em, const char *id, bson_error_t *error)
{
entity_t *entity = entity_map_get (em, id, error);
if (!entity) {
return false;
}

LL_DELETE (em->entities, entity);
entity_destroy (entity);

return true;
}

static entity_t *
_entity_map_get_by_type (entity_map_t *entity_map,
const char *id,
Expand Down Expand Up @@ -984,6 +1012,18 @@ entity_map_get_changestream (entity_map_t *entity_map,
return (mongoc_change_stream_t *) entity->value;
}

mongoc_cursor_t *
entity_map_get_cursor (entity_map_t *entity_map,
const char *id,
bson_error_t *error)
{
entity_t *entity = _entity_map_get_by_type (entity_map, id, "cursor", error);
if (!entity) {
return NULL;
}
return (mongoc_cursor_t *) entity->value;
}

bson_val_t *
entity_map_get_bson (entity_map_t *entity_map,
const char *id,
Expand Down Expand Up @@ -1079,6 +1119,15 @@ entity_map_add_changestream (entity_map_t *em,
em, id, "changestream", (void *) changestream, error);
}

bool
entity_map_add_cursor (entity_map_t *em,
const char *id,
mongoc_cursor_t *cursor,
bson_error_t *error)
{
return _entity_map_add (em, id, "cursor", (void *) cursor, error);
}

bool
entity_map_add_bson (entity_map_t *em,
const char *id,
Expand Down
17 changes: 17 additions & 0 deletions src/libmongoc/tests/unified/entity-map.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ entity_map_add_changestream (entity_map_t *em,
mongoc_change_stream_t *changestream,
bson_error_t *error);

/* Steals ownership of cursor. */
bool
entity_map_add_cursor (entity_map_t *em,
const char *id,
mongoc_cursor_t *cursor,
bson_error_t *error);

/* Copies val */
bool
entity_map_add_bson (entity_map_t *em,
Expand All @@ -82,6 +89,11 @@ entity_map_add_bson (entity_map_t *em,
entity_t *
entity_map_get (entity_map_t *em, const char *id, bson_error_t *error);

/* Removes an entity from the entity map. Returns false and sets @error if @id
* does not map to an entry. */
bool
entity_map_delete (entity_map_t *em, const char *id, bson_error_t *error);

mongoc_client_t *
entity_map_get_client (entity_map_t *entity_map,
const char *id,
Expand All @@ -102,6 +114,11 @@ entity_map_get_changestream (entity_map_t *entity_map,
const char *id,
bson_error_t *error);

mongoc_cursor_t *
entity_map_get_cursor (entity_map_t *entity_map,
const char *id,
bson_error_t *error);

mongoc_client_session_t *
entity_map_get_session (entity_map_t *entity_map,
const char *id,
Expand Down
Loading