(self)
| 1026 | @threading_helper.reap_threads |
| 1027 | @threading_helper.requires_working_threading() |
| 1028 | def test_threaded_hashing(self): |
| 1029 | # Updating the same hash object from several threads at once |
| 1030 | # using data chunk sizes containing the same byte sequences. |
| 1031 | # |
| 1032 | # If the internal locks are working to prevent multiple |
| 1033 | # updates on the same object from running at once, the resulting |
| 1034 | # hash will be the same as doing it single threaded upfront. |
| 1035 | hasher = hashlib.sha1() |
| 1036 | num_threads = 5 |
| 1037 | smallest_data = b'swineflu' |
| 1038 | data = smallest_data * 200000 |
| 1039 | expected_hash = hashlib.sha1(data*num_threads).hexdigest() |
| 1040 | |
| 1041 | def hash_in_chunks(chunk_size): |
| 1042 | index = 0 |
| 1043 | while index < len(data): |
| 1044 | hasher.update(data[index:index + chunk_size]) |
| 1045 | index += chunk_size |
| 1046 | |
| 1047 | threads = [] |
| 1048 | for threadnum in range(num_threads): |
| 1049 | chunk_size = len(data) // (10 ** threadnum) |
| 1050 | self.assertGreater(chunk_size, 0) |
| 1051 | self.assertEqual(chunk_size % len(smallest_data), 0) |
| 1052 | thread = threading.Thread(target=hash_in_chunks, |
| 1053 | args=(chunk_size,)) |
| 1054 | threads.append(thread) |
| 1055 | |
| 1056 | for thread in threads: |
| 1057 | thread.start() |
| 1058 | for thread in threads: |
| 1059 | thread.join() |
| 1060 | |
| 1061 | self.assertEqual(expected_hash, hasher.hexdigest()) |
| 1062 | |
| 1063 | def test_get_fips_mode(self): |
| 1064 | fips_mode = self.is_fips_mode |
nothing calls this directly
no test coverage detected