|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Class Google\Site_Kit\Tests\Core\Email_Reporting\Max_Execution_LimiterTest |
| 4 | + * |
| 5 | + * @package Google\Site_Kit\Tests\Core\Email_Reporting |
| 6 | + */ |
| 7 | + |
| 8 | +namespace Google\Site_Kit\Tests\Core\Email_Reporting; |
| 9 | + |
| 10 | +use Google\Site_Kit\Core\Email_Reporting\Max_Execution_Limiter; |
| 11 | +use Google\Site_Kit\Tests\TestCase; |
| 12 | + |
| 13 | +class Max_Execution_LimiterTest extends TestCase { |
| 14 | + |
| 15 | + public function test_it_caches_passed_limits_and_fallbacks() { |
| 16 | + $limiter = new Max_Execution_Limiter( 45 ); |
| 17 | + $this->assertSame( 45, $this->force_get_property( $limiter, 'max_execution_time' ), 'Passed max execution limit should be cached.' ); |
| 18 | + |
| 19 | + $limiter = new Max_Execution_Limiter( 0 ); |
| 20 | + $this->assertSame( 30, $this->force_get_property( $limiter, 'max_execution_time' ), 'Zero execution limits should fall back to default.' ); |
| 21 | + |
| 22 | + $limiter = new Max_Execution_Limiter( null ); |
| 23 | + $this->assertSame( 30, $this->force_get_property( $limiter, 'max_execution_time' ), 'Null execution limits should fall back to default.' ); |
| 24 | + } |
| 25 | + |
| 26 | + public function test_should_abort_respects_runtime_and_initiator_windows() { |
| 27 | + $limiter = new Max_Execution_Limiter( 3600 ); |
| 28 | + $this->assertFalse( $limiter->should_abort( time() ), 'Limiter should allow execution while within both windows.' ); |
| 29 | + |
| 30 | + $this->force_set_property( $limiter, 'max_execution_time', 5 ); |
| 31 | + $this->assertTrue( $limiter->should_abort( time() ), 'Limiter should abort when runtime budget is exhausted.' ); |
| 32 | + |
| 33 | + $this->force_set_property( $limiter, 'max_execution_time', 3600 ); |
| 34 | + $this->assertTrue( $limiter->should_abort( time() - DAY_IN_SECONDS - 1 ), 'Limiter should abort when initiator window exceeds 24h.' ); |
| 35 | + } |
| 36 | +} |
0 commit comments