-
Notifications
You must be signed in to change notification settings - Fork 45
Description
Describe the bug
In #907 I came across the following test failure:
self = <tests.unit.preprocessor._regrid.test_regrid.Test testMethod=test_regrid__cell_specification>
def test_regrid__cell_specification(self):
specs = ['1x1', '2x2', '3x3', '4x4', '5x5']
scheme = 'linear'
for spec in specs:
result = regrid(self.src_cube, spec, scheme)
self.assertEqual(result, self.regridded_cube)
> self._check(spec, scheme, spec=True)
tests/unit/preprocessor/_regrid/test_regrid.py:107:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
tests/unit/preprocessor/_regrid/test_regrid.py:23: in _check
self.assertEqual(_CACHE[spec], self.tgt_grid)
E AssertionError: <iris 'Cube' of unknown / (unknown) (latitude: 180; longitude: 360)> != <Mock spec='Cube' id='140424322565072'>
I could not reproduce the error on my machine, and it occasionally passed on CircleCI. I tracked it down to being related to the _CACHE:
| _CACHE = dict() |
The cache stores the results of the regridding as a simpley key, 1x1, 2x2, etc. The problem is that the key assignment is ambiguous. This means after multiple calls, there will be a name collision, so that the wrong cached value is retrieved. This may lead to data corruption, and in my case, random test failures.
For #907, I believe that the outcome of the test depends on whether the regridder goes first (pass) or last (second). I happened to catch this, because I implement additional tests which also call the regridder at some point.
I have worked around the issue the issue by clearing _CACHE in #907 , but a less naive implementation of the cache is necessary.