From b3d68ef442bd5f99bf3d1afa29c769f2fc46c056 Mon Sep 17 00:00:00 2001 From: Jeremy Thurgood Date: Wed, 3 Dec 2014 13:44:56 +0200 Subject: [PATCH] Test for duplicate eviction scheduling. --- go/vumitools/tests/test_routing.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/go/vumitools/tests/test_routing.py b/go/vumitools/tests/test_routing.py index 033501f79..09de57e31 100644 --- a/go/vumitools/tests/test_routing.py +++ b/go/vumitools/tests/test_routing.py @@ -396,6 +396,35 @@ def test_get_routing_table_no_caching(self): self.assertEqual(cache._routing_tables, {}) self.assertEqual(cache._evictors, {}) + @inlineCallbacks + def test_schedule_duplicate_eviction(self): + """ + If we schedule an eviction that already exists, we keep the old one + instead. + """ + cache = AccountRoutingTableCache(self.clock, 5) + yield cache.get_routing_table(self.user_helper.user_api) + self.assertEqual(cache._evictors.keys(), [self.user_account_key]) + + delayed_call = cache._evictors[self.user_account_key] + self.clock.advance(1) + + # Calling schedule_eviction() doesn't replace the existing one. + cache.schedule_eviction(self.user_account_key) + self.assertNotEqual(cache._routing_tables, {}) + self.assertEqual(cache._evictors[self.user_account_key], delayed_call) + + # The existing eviction happens at the expected time. + self.clock.advance(4) + self.assertEqual(cache._routing_tables, {}) + self.assertEqual(cache._evictors, {}) + + # Advance to the time the new eviction would have been schduled to make + # sure nothing breaks. + self.clock.advance(1) + self.assertEqual(cache._routing_tables, {}) + self.assertEqual(cache._evictors, {}) + class RoutingTableDispatcherTestCase(VumiTestCase): """Base class for ``AccountRoutingTableDispatcher`` test cases"""