mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 05:31:20 +00:00 
			
		
		
		
	gh-96710: Make the test timing more lenient for the int/str DoS regression test. (#96717)
A regression would still absolutely fail and even a flaky pass isn't harmful as it'd fail most of the time across our N system test runs. Windows has a low resolution timer and CI systems are prone to odd timing so this just gives more leeway to avoid flakiness.
This commit is contained in:
		
							parent
							
								
									88a7f661ca
								
							
						
					
					
						commit
						11e3548fd1
					
				
					 1 changed files with 8 additions and 6 deletions
				
			
		|  | @ -650,7 +650,8 @@ def test_denial_of_service_prevented_int_to_str(self): | ||||||
|         self.assertEqual(len(huge_decimal), digits) |         self.assertEqual(len(huge_decimal), digits) | ||||||
|         # Ensuring that we chose a slow enough conversion to measure. |         # Ensuring that we chose a slow enough conversion to measure. | ||||||
|         # It takes 0.1 seconds on a Zen based cloud VM in an opt build. |         # It takes 0.1 seconds on a Zen based cloud VM in an opt build. | ||||||
|         if seconds_to_convert < 0.005: |         # Some OSes have a low res 1/64s timer, skip if hard to measure. | ||||||
|  |         if seconds_to_convert < 1/64: | ||||||
|             raise unittest.SkipTest('"slow" conversion took only ' |             raise unittest.SkipTest('"slow" conversion took only ' | ||||||
|                                     f'{seconds_to_convert} seconds.') |                                     f'{seconds_to_convert} seconds.') | ||||||
| 
 | 
 | ||||||
|  | @ -662,7 +663,7 @@ def test_denial_of_service_prevented_int_to_str(self): | ||||||
|                 str(huge_int) |                 str(huge_int) | ||||||
|             seconds_to_fail_huge = get_time() - start |             seconds_to_fail_huge = get_time() - start | ||||||
|         self.assertIn('conversion', str(err.exception)) |         self.assertIn('conversion', str(err.exception)) | ||||||
|         self.assertLess(seconds_to_fail_huge, seconds_to_convert/8) |         self.assertLessEqual(seconds_to_fail_huge, seconds_to_convert/2) | ||||||
| 
 | 
 | ||||||
|         # Now we test that a conversion that would take 30x as long also fails |         # Now we test that a conversion that would take 30x as long also fails | ||||||
|         # in a similarly fast fashion. |         # in a similarly fast fashion. | ||||||
|  | @ -673,7 +674,7 @@ def test_denial_of_service_prevented_int_to_str(self): | ||||||
|             str(extra_huge_int) |             str(extra_huge_int) | ||||||
|         seconds_to_fail_extra_huge = get_time() - start |         seconds_to_fail_extra_huge = get_time() - start | ||||||
|         self.assertIn('conversion', str(err.exception)) |         self.assertIn('conversion', str(err.exception)) | ||||||
|         self.assertLess(seconds_to_fail_extra_huge, seconds_to_convert/8) |         self.assertLess(seconds_to_fail_extra_huge, seconds_to_convert/2) | ||||||
| 
 | 
 | ||||||
|     def test_denial_of_service_prevented_str_to_int(self): |     def test_denial_of_service_prevented_str_to_int(self): | ||||||
|         """Regression test: ensure we fail before performing O(N**2) work.""" |         """Regression test: ensure we fail before performing O(N**2) work.""" | ||||||
|  | @ -691,7 +692,8 @@ def test_denial_of_service_prevented_str_to_int(self): | ||||||
|         seconds_to_convert = get_time() - start |         seconds_to_convert = get_time() - start | ||||||
|         # Ensuring that we chose a slow enough conversion to measure. |         # Ensuring that we chose a slow enough conversion to measure. | ||||||
|         # It takes 0.1 seconds on a Zen based cloud VM in an opt build. |         # It takes 0.1 seconds on a Zen based cloud VM in an opt build. | ||||||
|         if seconds_to_convert < 0.005: |         # Some OSes have a low res 1/64s timer, skip if hard to measure. | ||||||
|  |         if seconds_to_convert < 1/64: | ||||||
|             raise unittest.SkipTest('"slow" conversion took only ' |             raise unittest.SkipTest('"slow" conversion took only ' | ||||||
|                                     f'{seconds_to_convert} seconds.') |                                     f'{seconds_to_convert} seconds.') | ||||||
| 
 | 
 | ||||||
|  | @ -701,7 +703,7 @@ def test_denial_of_service_prevented_str_to_int(self): | ||||||
|                 int(huge) |                 int(huge) | ||||||
|             seconds_to_fail_huge = get_time() - start |             seconds_to_fail_huge = get_time() - start | ||||||
|         self.assertIn('conversion', str(err.exception)) |         self.assertIn('conversion', str(err.exception)) | ||||||
|         self.assertLess(seconds_to_fail_huge, seconds_to_convert/8) |         self.assertLessEqual(seconds_to_fail_huge, seconds_to_convert/2) | ||||||
| 
 | 
 | ||||||
|         # Now we test that a conversion that would take 30x as long also fails |         # Now we test that a conversion that would take 30x as long also fails | ||||||
|         # in a similarly fast fashion. |         # in a similarly fast fashion. | ||||||
|  | @ -712,7 +714,7 @@ def test_denial_of_service_prevented_str_to_int(self): | ||||||
|             int(extra_huge) |             int(extra_huge) | ||||||
|         seconds_to_fail_extra_huge = get_time() - start |         seconds_to_fail_extra_huge = get_time() - start | ||||||
|         self.assertIn('conversion', str(err.exception)) |         self.assertIn('conversion', str(err.exception)) | ||||||
|         self.assertLess(seconds_to_fail_extra_huge, seconds_to_convert/8) |         self.assertLessEqual(seconds_to_fail_extra_huge, seconds_to_convert/2) | ||||||
| 
 | 
 | ||||||
|     def test_power_of_two_bases_unlimited(self): |     def test_power_of_two_bases_unlimited(self): | ||||||
|         """The limit does not apply to power of 2 bases.""" |         """The limit does not apply to power of 2 bases.""" | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Gregory P. Smith
						Gregory P. Smith