Laravel 5.1:PDOException:已超出'max_user_connections'资源

时间:2015-12-08 17:49:45

标签: php mysql laravel testing laravel-5.1

我在Laravel 5.1中对登台服务器上的MySQL数据库运行功能测试,并收到以下错误:

  

PDOException:SQLSTATE [HY000] [1226]用户“用户名”已超出“max_user_connections”资源(当前值:20)

TestCase类看起来像:

<?php

use Illuminate\Support\Facades\Artisan;
use Illuminate\Foundation\Testing\DatabaseTransactions;

class TestCase extends Illuminate\Foundation\Testing\TestCase
{

    /**
     * Rollback and execute migrations for each test.
     */
    use DatabaseTransactions;

    /**
     * The base URL to use while testing the application.
     *
     * @var string
     */
    protected $baseUrl = 'http://localhost';

    /**
     * Is this the first test.
     *
     * @var bool
     */
    protected static $isInitialTest = true;

    /**
     * Creates the application.
     *
     * @return \Illuminate\Foundation\Application
     */
    public function createApplication()
    {
        $app = require __DIR__.'/../bootstrap/app.php';

        $app->make(Illuminate\Contracts\Console\Kernel::class)->bootstrap();

        return $app;
    }

    /**
     * If this is the first test of the actual test suite:
     * Delete all test table records and run migrations.
     *
     * @return void
     */
    public function setUp()
    {
        parent::setUp();

        if(self::$isInitialTest){

            self::$isInitialTest = false;

            Artisan::call('migrate');
        }
    }

}

失败的测试(在很多其他测试成功运行之后)看起来像

use Illuminate\Foundation\Testing\WithoutMiddleware;

class AreasTest extends TestCase
{
    /**
     * Add a new area to a tenant.
     */
    public function testAddArea()
    {
        $tenant = factory('XXX\Tenant', 'xxx')->create();

        $this->visit("admin/tenants/{$tenant->id}")
            ->click('…')
            ->click('N…')
            ->type('…', 'name')
            ->press('…')
            ->see('…');
    }
…
}

我正在运行这样的测试 vendor/phpunit/phpunit/phpunit --bootstrap ./bootstrap/autoload.php ./tests/

除了提升max_user_connections之外还有什么可以控制并行数据库连接打开的数量吗?如果可能的话,我不想放慢测试速度:)

在我的本地开发计算机max_user_connections上设置为0,因此没有限制且没有错误。

0 个答案:

没有答案