@@ -1060,11 +1060,24 @@ def test_sha256_gil(self):
10601060
10611061 @threading_helper .reap_threads
10621062 @threading_helper .requires_working_threading ()
1063- def test_threaded_hashing (self ):
1063+ def test_threaded_hashing_fast (self ):
1064+ # Same as test_threaded_hashing_slow() but only tests "fast" functions
1065+ # since otherwise test_hashlib.py becomes too slow during development.
1066+ for name in ['md5' , 'sha1' , 'sha256' , 'sha3_256' , 'blake2s' ]:
1067+ if constructor := getattr (hashlib , name , None ):
1068+ with self .subTest (name ):
1069+ self .do_test_threaded_hashing (constructor , is_shake = False )
1070+ if shake_128 := getattr (hashlib , 'shake_128' , None ):
1071+ self .do_test_threaded_hashing (shake_128 , is_shake = True )
1072+
1073+ @requires_resource ('cpu' )
1074+ @threading_helper .reap_threads
1075+ @threading_helper .requires_working_threading ()
1076+ def test_threaded_hashing_slow (self ):
10641077 for algorithm , constructors in self .constructors_to_test .items ():
10651078 is_shake = algorithm in self .shakes
10661079 for constructor in constructors :
1067- with self .subTest (constructor = constructor , is_shake = is_shake ):
1080+ with self .subTest (constructor . __name__ , is_shake = is_shake ):
10681081 self .do_test_threaded_hashing (constructor , is_shake )
10691082
10701083 def do_test_threaded_hashing (self , constructor , is_shake ):
@@ -1074,8 +1087,12 @@ def do_test_threaded_hashing(self, constructor, is_shake):
10741087 # If the internal locks are working to prevent multiple
10751088 # updates on the same object from running at once, the resulting
10761089 # hash will be the same as doing it single threaded upfront.
1090+ #
1091+ # Be careful when choosing num_threads, len(smallest_data)
1092+ # and len(data) // len(smallest_data) as the obtained chunk
1093+ # size needs to satisfy some conditions below.
10771094 num_threads = 5
1078- smallest_data = os .urandom (16 )
1095+ smallest_data = os .urandom (8 )
10791096 data = smallest_data * 200000
10801097
10811098 h1 = constructor ()
0 commit comments