code: def test_database_resource_errors(
      queue_mongo_host: str,
      host: Optional[str],
      mongoengine_alias: str,
      server_selection_timeout_ms: int,
      raises: bool,
  ) -> None:
      if not host:
          host = queue_mongo_host
      database = "datasets_server_test"
      resource = MongoResource(
          database=database,
          host=host,
          mongoengine_alias=mongoengine_alias,
          server_selection_timeout_ms=server_selection_timeout_ms,
      )
      # ^ this does not raise any issue, as it "only" registers the connection
  
      class User(Document):
          name = StringField()
          meta = {"db_alias": mongoengine_alias}
  
      if raises:
          assert not resource.is_available()
          with pytest.raises(ServerSelectionTimeoutError):
              len(User.objects())  # type: ignore
      else:
          assert resource.is_available()
          assert len(User.objects()) == 0  # type: ignore
          # clean
          User.drop_collection()  # type: ignore
  
      resource.release()
  
file_path: datasets-server/libs/libcommon/tests/test_resources.py
imports: from typing import Optional
  import pytest
  from mongoengine import Document
  from mongoengine.fields import StringField
  from pymongo.errors import ServerSelectionTimeoutError
  from libcommon.resources import CacheMongoResource, MetricsMongoResource, MongoConnectionFailure, MongoResource, QueueMongoResource
label_desc: Use image node_id 2 for calling a global function with example usage: test_database_resource_errors(queue_mongo_host, host, mongoengine_alias, server_selection_timeout_ms, raises) without return types