Commit b731a65d authored by Jeremy Hylton's avatar Jeremy Hylton

Remove uses of random from cache tests.

parent 8f44f0fa
...@@ -6,7 +6,6 @@ objects in memory under the assumption that they may be used again. ...@@ -6,7 +6,6 @@ objects in memory under the assumption that they may be used again.
""" """
from __future__ import nested_scopes from __future__ import nested_scopes
import random
import time import time
import types import types
import unittest import unittest
...@@ -34,8 +33,6 @@ class CacheTestBase(unittest.TestCase): ...@@ -34,8 +33,6 @@ class CacheTestBase(unittest.TestCase):
conn.close() conn.close()
self.db.close() self.db.close()
NUM_COLLECTIONS = 10
MAX_OBJECTS = 100
CACHE_SIZE = 20 CACHE_SIZE = 20
def noodle_new_connection(self): def noodle_new_connection(self):
...@@ -48,17 +45,16 @@ class CacheTestBase(unittest.TestCase): ...@@ -48,17 +45,16 @@ class CacheTestBase(unittest.TestCase):
def noodle_connection(self, c): def noodle_connection(self, c):
r = c.root() r = c.root()
i = random.randrange(0, self.NUM_COLLECTIONS) i = len(self.conns)
d = r.get(i) d = r.get(i)
if d is None: if d is None:
d = r[i] = PersistentMapping() d = r[i] = PersistentMapping()
get_transaction().commit() get_transaction().commit()
for i in range(random.randrange(10, 20)): for i in range(15):
j = random.randrange(0, self.MAX_OBJECTS) o = d.get(i)
o = d.get(j)
if o is None: if o is None:
o = d[j] = MinPO(j) o = d[i] = MinPO(i)
o.value += 1 o.value += 1
get_transaction().commit() get_transaction().commit()
...@@ -196,11 +192,11 @@ class LRUCacheTests(CacheTestBase): ...@@ -196,11 +192,11 @@ class LRUCacheTests(CacheTestBase):
self.noodle_new_connection() self.noodle_new_connection()
for klass, count in self.db.cacheDetail(): for klass, count in self.db.cacheDetail():
if klass.endswith('MinPO'):
self.assertEqual(count, CONNS * CACHE_SIZE)
if klass.endswith('PersistentMapping'): if klass.endswith('PersistentMapping'):
# one root per connection # one root per connection
self.assertEqual(count, CONNS) self.assertEqual(count, CONNS)
if klass.endswith('MinPO'):
self.assertEqual(count, CONNS * CACHE_SIZE)
for details in self.db.cacheExtremeDetail(): for details in self.db.cacheExtremeDetail():
# one dict per object. keys: # one dict per object. keys:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment