-
Notifications
You must be signed in to change notification settings - Fork 11.7k
[12.x] Fix WithCachedConfig to work with parallel test runs
#57785
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
Conversation
|
@cosmastech I tried this change locally in our project, and it causes errors in some tests, for example a test that renders a page containing a NoCaptcha from the https://github.com/anhskohbo/no-captcha package. Specifically on public function register()
{
$this->app->singleton('captcha', function ($app) {
return new NoCaptcha(
$app['config']['captcha.secret'],
$app['config']['captcha.sitekey'],
$app['config']['captcha.options']
);
});
}This test works fine with |
Thanks for reporting this @SanderMuller. I will mark this as draft and continue my spelunking. |
| if (! isset(self::$originalDatabaseName)) { | ||
| self::$originalDatabaseName = $database; | ||
| } else { | ||
| $database = self::$originalDatabaseName; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note: I think that this trait/approach needs refactored to work with multiple database connections. Currently, I don't believe that multiple connections are seeded/migrated. This approach is a little bit naive and assumes (like the rest of the parallel runner code) that there's but a single database to be concerned with.
|
Our application has multiple parallel connections (to make it work we used the steps in this tutorial) but after this change our test suite breaks. I think it currently doesn't work with multiple connections. |
Yes, as noted above, the ParallelTestRunner isn't designed out of the box to work with multiple connections. Strangely enough, we have (almost) this exact tutorial code in our codebase. For whatever reason, we never ran into the parallel runner problem that others reported. Can you try adding this to your extended service provider, replacing your private static array $connectionMap = [];
protected function testDatabaseOnConnection(string $connection): string
{
if (! isset(self::$connectionMap[$connection])) {
self::$connectionMap[$connection] = config("database.connections.$connection.database");
}
self::$originalDatabaseName = self::$connectionMap[$connection];
return $this->testDatabase(config("database.connections.$connection.database"));
} |
|
Thanks @cosmastech! It sadly didn't work. I don't have time to investigate further, but from a quick test I see that the underlying
I've 'solved' it for now by overwriting the protected function testDatabase($database): string
{
$token = ParallelTesting::token();
return "{$database}_test_{$token}";
} |
Glad you've got it working for the time being. 👍 |


I'll be honest, I'm not entirely sure why this has fixed the problem described here. #57663 (comment) I've stepped through this many times and I am still lost about what this change is preventing from happening. I can see it has something to do with caching the config before calling the parallel testing provider, but... yeah, I'm still a touch confused.
For whatever it's worth, I thought that I wanted to set the application to cached before booting to avoid a disk read on LoadEnvironmentVariables, however, TIL that Env keeps a static instance of the environment variables stored. Turns out that wasn't necessary.
Thanks to @santigarcor for bringing this to my attention.