git » nmdb » commit c8cf39b

Allow random tests to take a key prefix

author Alberto Bertogli
2008-06-04 04:36:30 UTC
committer Alberto Bertogli
2008-06-04 18:17:26 UTC
parent 9fd09c020ed5aff22f6e7c5bd9cb634b55cb8258

Allow random tests to take a key prefix

This makes running several tests in parallel, with the guarantee they will
not step on each other's keys.

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

tests/python/random1-cache.py +7 -3
tests/python/random1.py +7 -3

diff --git a/tests/python/random1-cache.py b/tests/python/random1-cache.py
index c6bf75a..33ca332 100755
--- a/tests/python/random1-cache.py
+++ b/tests/python/random1-cache.py
@@ -83,16 +83,20 @@ def getrand():
 
 
 if __name__ == '__main__':
-	if len(sys.argv) != 2:
-		print 'Use: random1-cache.py number_of_keys'
+	if len(sys.argv) < 2:
+		print 'Use: random1-cache.py number_of_keys [key_prefix]'
 		sys.exit(1)
 
 	nkeys = int(sys.argv[1])
+	if len(sys.argv) > 2:
+		key_prefix = sys.argv[2]
+	else:
+		key_prefix = ''
 
 	# fill all the keys
 	print 'populate'
 	for i in xrange(nkeys):
-		set(getrand(), getrand())
+		set(key_prefix + str(getrand()), getrand())
 
 	print 'missing', find_missing()
 
diff --git a/tests/python/random1.py b/tests/python/random1.py
index b873d46..172b4b5 100755
--- a/tests/python/random1.py
+++ b/tests/python/random1.py
@@ -102,16 +102,20 @@ def getrand():
 
 
 if __name__ == '__main__':
-	if len(sys.argv) != 2:
-		print 'Use: random1.py number_of_keys'
+	if len(sys.argv) < 2:
+		print 'Use: random1.py number_of_keys [key_prefix]'
 		sys.exit(1)
 
 	nkeys = int(sys.argv[1])
+	if len(sys.argv) > 2:
+		key_prefix = sys.argv[2]
+	else:
+		key_prefix = ''
 
 	# fill all the keys
 	print 'populate'
 	for i in xrange(nkeys):
-		set(getrand(), getrand())
+		set(key_prefix + str(getrand()), getrand())
 
 	lkeys = ldb.keys()