DataBiosphere / azul

Metadata indexer and query service used for AnVIL, HCA, LungMAP, and CGP
Apache License 2.0
5 stars 2 forks source link

PortalRegistrationIntegrationTest.tearDown doesn't handle partial setUp #3482

Open hannes-ucsc opened 2 years ago

hannes-ucsc commented 2 years ago

Just got this during make integration_test

======================================================================
ERROR: test_concurrent_portal_db_crud (integration_test.PortalRegistrationIntegrationTest)
Use multithreading to simulate multiple users simultaneously modifying
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/hannes/workspace/hca/azul/test/azul_test_case.py", line 142, in wrapped
    return method(*args, **kwargs)
  File "/home/hannes/workspace/hca/azul/test/integration_test.py", line 925, in setUp
    self.old_db = self.portal_service.read()
  File "/home/hannes/workspace/hca/azul/src/azul/portal_service.py", line 110, in read
    return self._crud(lambda db: db)
  File "/home/hannes/workspace/hca/azul/src/azul/portal_service.py", line 164, in _crud
    version = self.version_service.get(self._db_url)
  File "/home/hannes/workspace/hca/azul/src/azul/version_service.py", line 25, in get
    response = self.client.get_item(TableName=config.dynamo_object_version_table_name,
  File "/home/hannes/workspace/hca/azul/.venv/lib/python3.8/site-packages/botocore/client.py", line 357, in _api_call
    return self._make_api_call(operation_name, kwargs)
  File "/home/hannes/workspace/hca/azul/.venv/lib/python3.8/site-packages/botocore/client.py", line 676, in _make_api_call
    raise error_class(parsed_response, operation_name)
botocore.exceptions.ClientError: An error occurred (ExpiredTokenException) when calling the GetItem operation: The security token included in the request is expired

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/hannes/workspace/hca/azul/test/azul_test_case.py", line 144, in wrapped
    self.tearDown()
  File "/home/hannes/workspace/hca/azul/test/integration_test.py", line 979, in tearDown
    self.portal_service.overwrite(self.old_db)
AttributeError: 'PortalRegistrationIntegrationTest' object has no attribute 'old_db'

Expiring credentials caused setUp to fail. That's unavoidable but ideally tearDown should handle a failure during setUp. Also, super calls are missing in both methods.

jessebrennan commented 2 years ago

AlwaysTearDownTestCase could probably handle this, but also I recently learned about https://docs.python.org/3.5/library/unittest.html#unittest.TestCase.addCleanup which is a built in way to accomplish the same thing.