[autotest] Set rpm info cache expriation to 30 mins.

Set rpm info cache expriation to 30 mins.
Any changes to rpm attributes in db will eventually picked up
by rpm after 30 mins.

BUG=chromium:517233
TEST=Unittest.
DEPLOY=rpm

Change-Id: I860933cd774a005dc27daf2bbb511b2f3672e049
Reviewed-on: https://chromium-review.googlesource.com/305370
Commit-Ready: Fang Deng <fdeng@chromium.org>
Tested-by: Fang Deng <fdeng@chromium.org>
Reviewed-by: Paul Hobbs <phobbs@google.com>
diff --git a/site_utils/rpm_control_system/utils_unittest.py b/site_utils/rpm_control_system/utils_unittest.py
index 567bf81..1785140 100755
--- a/site_utils/rpm_control_system/utils_unittest.py
+++ b/site_utils/rpm_control_system/utils_unittest.py
@@ -7,6 +7,7 @@
 import mox
 import os
 import unittest
+import time
 from StringIO import StringIO
 
 import utils
@@ -84,8 +85,8 @@
         p3 = utils.PowerUnitInfo(
                 'host3', utils.PowerUnitInfo.POWERUNIT_TYPES.RPM,
                 'rpm3', 'hydra3')
-        # Initialize an LRU with size 2.
-        cache = utils.LRUCache(2)
+        # Initialize an LRU with size 2, items never expire.
+        cache = utils.LRUCache(2, expiration_secs=None)
         # Add two items, LRU should be full now
         cache['host1'] = p1
         cache['host2'] = p2
@@ -100,5 +101,50 @@
         self.assertTrue('host3' in cache)
 
 
+    def  test_LRU_cache_expires(self):
+        """Test LRUCache expires."""
+        self.mox.StubOutWithMock(time, 'time')
+        time.time().AndReturn(10)
+        time.time().AndReturn(25)
+        p1 = utils.PowerUnitInfo(
+                'host1', utils.PowerUnitInfo.POWERUNIT_TYPES.RPM,
+                'rpm1', 'hydra1')
+
+        self.mox.ReplayAll()
+        # Initialize an LRU with size 1, items exppire after 10 secs.
+        cache = utils.LRUCache(1, expiration_secs=10)
+        # Add two items, LRU should be full now
+        cache['host1'] = p1
+        check_contains_1 = 'host1' in cache
+        check_contains_2 = 'host2' in cache
+        self.mox.VerifyAll()
+        self.assertFalse(check_contains_1)
+        self.assertFalse(check_contains_2)
+
+
+    def  test_LRU_cache_full_with_expries(self):
+        """Test timestamp is removed properly when cache is full."""
+        self.mox.StubOutWithMock(time, 'time')
+        time.time().AndReturn(10)
+        time.time().AndReturn(25)
+        p1 = utils.PowerUnitInfo(
+                'host1', utils.PowerUnitInfo.POWERUNIT_TYPES.RPM,
+                'rpm1', 'hydra1')
+        p2 = utils.PowerUnitInfo(
+                'host2', utils.PowerUnitInfo.POWERUNIT_TYPES.RPM,
+                'rpm2', 'hydra2')
+        self.mox.ReplayAll()
+        # Initialize an LRU with size 1, items expire after 10 secs.
+        cache = utils.LRUCache(1, expiration_secs=10)
+        # Add two items, LRU should be full now
+        cache['host1'] = p1
+        cache['host2'] = p2
+        self.mox.VerifyAll()
+        self.assertEqual(len(cache.timestamps), 1)
+        self.assertEqual(len(cache.cache), 1)
+        self.assertTrue('host2' in cache.timestamps)
+        self.assertTrue('host2' in cache.cache)
+
+
 if __name__ == '__main__':
     unittest.main()