From 89c737a819ec5e27408ec8efd644fcbe643b44c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Mon, 10 Feb 2020 23:13:26 +0100 Subject: [PATCH] Test memory cache with committed transaction as current The tests did not correspond to a proper use case because the transaction committed was not the current transaction. So this could lead to wrong cache being reset and wrong cache being tested. issue8502 review289171002 --- trytond/tests/test_cache.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/trytond/tests/test_cache.py b/trytond/tests/test_cache.py index 0064e25468..85c017e6e2 100644 --- a/trytond/tests/test_cache.py +++ b/trytond/tests/test_cache.py @@ -93,16 +93,15 @@ class MemoryCacheTestCase(unittest.TestCase): cache.set('foo', 'baz') self.assertEqual(cache.get('foo'), 'baz') - Transaction().set_current_transaction(transaction1) - self.addCleanup(transaction1.stop) - self.assertEqual(cache.get('foo'), 'bar') + with Transaction().set_current_transaction(transaction1): + self.assertEqual(cache.get('foo'), 'bar') transaction2.commit() for n in range(10): - if cache.get('foo') is None: + if cache.get('foo') == 'baz': break self.wait_cache_sync() - self.assertEqual(cache.get('foo'), None) + self.assertEqual(cache.get('foo'), 'baz') def test_memory_cache_nested_transactions(self): "Test MemoryCache with nested transactions"