Skip to content
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

FIX Reset time limit back to original value #11621

Merged
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
11 changes: 11 additions & 0 deletions src/Dev/SapphireTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,11 @@ abstract class SapphireTest extends TestCase implements TestOnly

protected FixtureFactory|bool $fixtureFactory;

/**
* The original value of ini 'max_execution_time' before any code or tests change it
*/
private int $origMaxExecutionTime;

/**
* @return TempDatabase
*/
Expand Down Expand Up @@ -332,6 +337,8 @@ protected function setUp(): void
Email::config()->remove('send_all_emails_from');
Email::config()->remove('cc_all_emails_to');
Email::config()->remove('bcc_all_emails_to');

$this->origMaxExecutionTime = ini_get('max_execution_time');
}

/**
Expand Down Expand Up @@ -563,6 +570,10 @@ protected function tearDown(): void

// Call state helpers
static::$state->tearDown($this);

// Reset max_execution_time in case some code or a unit test changed it,
// either via ini_set() or set_time_limit()
ini_set('max_execution_time', $this->origMaxExecutionTime);
Copy link
Member

@GuySartorelli GuySartorelli Feb 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we still need to reset set_time_limit()? This changes the max execution time setting, but does that also result in changing the actual time limit?

Copy link
Member Author

@emteknetnz emteknetnz Feb 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

set_time_limit() is an shorthand alias for ini_set('max_execution_time'). It seems slightly less confusing just not use the alias.

I've tested locally that it still fixes the issue that was seen in CI

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't find anything in the docs of set_time_limit() that supports it being an alias, but I'll accept "I've tested locally" as good enough.

}

/**
Expand Down