Skip to content

bpo-31234: Join threads in test_hashlib #3573

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 14, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions Lib/test/test_hashlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -746,28 +746,28 @@ def test_threaded_hashing(self):
hasher = hashlib.sha1()
num_threads = 5
smallest_data = b'swineflu'
data = smallest_data*200000
data = smallest_data * 200000
expected_hash = hashlib.sha1(data*num_threads).hexdigest()

def hash_in_chunks(chunk_size, event):
def hash_in_chunks(chunk_size):
index = 0
while index < len(data):
hasher.update(data[index:index+chunk_size])
hasher.update(data[index:index + chunk_size])
index += chunk_size
event.set()

events = []
threads = []
for threadnum in range(num_threads):
chunk_size = len(data) // (10**threadnum)
chunk_size = len(data) // (10 ** threadnum)
self.assertGreater(chunk_size, 0)
self.assertEqual(chunk_size % len(smallest_data), 0)
event = threading.Event()
events.append(event)
threading.Thread(target=hash_in_chunks,
args=(chunk_size, event)).start()

for event in events:
event.wait()
thread = threading.Thread(target=hash_in_chunks,
args=(chunk_size,))
threads.append(thread)

for thread in threads:
thread.start()
for thread in threads:
thread.join()

self.assertEqual(expected_hash, hasher.hexdigest())

Expand Down