Ensure random prefixes for partitions and directory layer subspaces when doing comparison tests

This commit is contained in:
A.J. Beamon 2018-05-22 11:52:38 -07:00
parent 997d3eae80
commit f96b95a878
1 changed files with 11 additions and 9 deletions

View File

@ -156,7 +156,7 @@ class DirectoryTest(Test):
elif root_op == 'DIRECTORY_CREATE_SUBSPACE': elif root_op == 'DIRECTORY_CREATE_SUBSPACE':
path = generate_path() path = generate_path()
instructions.push_args(generate_prefix(allow_empty=False, is_partition=True)) instructions.push_args(generate_prefix(require_unique=False, is_partition=True))
instructions.push_args(*test_util.with_length(path)) instructions.push_args(*test_util.with_length(path))
instructions.append(op) instructions.append(op)
self.dir_list.append(DirListEntry(False, True, has_known_prefix=True)) self.dir_list.append(DirListEntry(False, True, has_known_prefix=True))
@ -164,7 +164,7 @@ class DirectoryTest(Test):
elif root_op == 'DIRECTORY_CREATE_LAYER': elif root_op == 'DIRECTORY_CREATE_LAYER':
indices = [] indices = []
prefixes = [generate_prefix(allow_empty=False, is_partition=True) for i in range(2)] prefixes = [generate_prefix(require_unique=args.concurrency==1, is_partition=True) for i in range(2)]
for i in range(2): for i in range(2):
instructions.push_args(prefixes[i]) instructions.push_args(prefixes[i])
instructions.push_args(*test_util.with_length(generate_path())) instructions.push_args(*test_util.with_length(generate_path()))
@ -201,8 +201,7 @@ class DirectoryTest(Test):
layer = self.generate_layer() layer = self.generate_layer()
is_partition = layer == 'partition' is_partition = layer == 'partition'
allow_empty_prefix = random.random() < 0.8 prefix = generate_prefix(require_unique=is_partition and args.concurrency==1, is_partition=is_partition, min_length=0)
prefix = generate_prefix(allow_empty=allow_empty_prefix, is_partition=is_partition)
# Because allocated prefixes are non-deterministic, we cannot have overlapping # Because allocated prefixes are non-deterministic, we cannot have overlapping
# transactions that allocate/remove these prefixes in a comparison test # transactions that allocate/remove these prefixes in a comparison test
@ -400,11 +399,14 @@ def generate_path(min_length=0):
return path return path
def generate_prefix(allow_empty=True, is_partition=False): def generate_prefix(require_unique=False, is_partition=False, min_length=1):
if allow_empty and random.random() < 0.8: if not require_unique and min_length == 0 and random.random() < 0.8:
return None return None
elif is_partition or random.random() < 0.5: elif require_unique or is_partition or min_length > len('abcdefg') or random.random() < 0.5:
length = random.randint(0 if allow_empty else 1, 5) if require_unique:
min_length = max(min_length, 16)
length = random.randint(min_length, min_length+5)
if length == 0: if length == 0:
return '' return ''
@ -415,5 +417,5 @@ def generate_prefix(allow_empty=True, is_partition=False):
return ''.join(chr(random.randrange(ord('\x02'), ord('\x14'))) for i in range(0, length)) return ''.join(chr(random.randrange(ord('\x02'), ord('\x14'))) for i in range(0, length))
else: else:
prefix = 'abcdefg' prefix = 'abcdefg'
generated = prefix[0:random.randrange(0 if allow_empty else 1, len(prefix))] generated = prefix[0:random.randrange(min_length, len(prefix))]
return generated return generated