git » nmdb » commit e3bc360

tests/python*: Fix random operation count calculation

author Alberto Bertogli
2010-04-14 21:07:16 UTC
committer Alberto Bertogli
2010-04-14 21:10:42 UTC
parent d7d5711ad5ba7c0b72083174452d0044b6e99182

tests/python*: Fix random operation count calculation

The operation count is half of the number of keys, but in the cache-only
tests, the number of available keys to operate on can be less than that due to
cache pressure.

This can be reproduced by running the server with a small cache (e.g. -c 1)
and the tests with a large number of operations (e.g. 5000).

This patch fixes it by checking that we still have keys in the cache to
operate on.

Signed-off-by: Alberto Bertogli <albertito@blitiri.com.ar>

tests/python/random1-cache.py +1 -1
tests/python3/random1-cache.py +1 -1

diff --git a/tests/python/random1-cache.py b/tests/python/random1-cache.py
index 33ca332..0e95dc5 100755
--- a/tests/python/random1-cache.py
+++ b/tests/python/random1-cache.py
@@ -105,7 +105,7 @@ if __name__ == '__main__':
 	# operate on them a bit
 	print 'random operations'
 	operations = ('set', 'get', 'delete')
-	for i in xrange(nkeys / 2):
+	for i in xrange(min(len(lkeys), nkeys / 2)):
 		op = choice(operations)
 		k = choice(lkeys)
 		if op == 'set':
diff --git a/tests/python3/random1-cache.py b/tests/python3/random1-cache.py
index 71e8b9f..f5e4ac2 100755
--- a/tests/python3/random1-cache.py
+++ b/tests/python3/random1-cache.py
@@ -105,7 +105,7 @@ if __name__ == '__main__':
 	# operate on them a bit
 	print('random operations')
 	operations = ('set', 'get', 'delete')
-	for i in range(nkeys // 2):
+	for i in range(min(len(lkeys), nkeys // 2)):
 		op = choice(operations)
 		k = choice(lkeys)
 		if op == 'set':