azavea / climate-change-api

Apache License 2.0
0 stars 0 forks source link

API cache interacts with unit test results #373

Closed rmartz closed 7 years ago

rmartz commented 7 years ago

While working with the API, I noticed something odd: My /api/scenario/ endpoint was reporting incomplete data:

[
  {
    "name": "RCP45",
    "label": null,
    "description": null
  },
  {
    "name": "RCP85",
    "label": null,
    "description": null
  }
]

Which is weird because the scenarios definitely exist:

In [2]: Scenario.objects.all().values()
Out[2]: [{'description': u'Stabilization without overshoot pathway to 4.5 W/m2 at stabilization after 2100. See https://www.skepticalscience.com/rcp.php', 'label': u'RCP 4.5', u'id': 1, 'name': u'RCP45'}, {'description': u'Rising radiative forcing pathway leading to 8.5 W/m2 in 2100. See https://www.skepticalscience.com/rcp.php', 'label': u'RCP 8.5', u'id': 2, 'name': u'RCP85'}, {'description': u'A historical dataset from NEX GDDP for 1950 to 2005 that blends reanalysis data with observations', 'label': u'Historical', u'id': 3, 'name': u'historical'}]

So I restarted the server, tried again, and all was well - I was getting back all three scenarios, with their labels and descriptions populated. Except now, I'm getting a unit test error:

FAIL: test_filtering (climate_data.tests.test_views.ScenarioViewSetTestCase)
Should allow equality filtering on name.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/opt/django/climate_change_api/climate_data/tests/test_views.py", line 145, in test_filtering
    self.assertEqual(len(response.data), 2)
AssertionError: 3 != 2

----------------------------------------------------------------------
Ran 327 tests in 23.487s

FAILED (failures=1)

It appears that the unit test and API are competing with each other for ownership of the cache.

This also definitely happens with the /api/climate-model/ endpoint, and may happen with other endpoints as well.

flibbertigibbet commented 7 years ago

Tests should be using the dummy cache, which does nothing.

Perhaps related to #311, caused by an apparent timing issue with tests being started with non-test settings. Possibly due to the use of factory_boy for mocks.