【问题标题】:Laravel PHPunit kill process after test execution - PosgtreSQL max_connection exeed测试执行后 Laravel PHPunit 杀死进程 - 超过 PostgreSQL 最大连接数
【发布时间】:2018-06-27 17:20:00
【问题描述】:

我在一个 Laravel 5.4 应用程序上使用 PHPUnit 做几个测试。

超过 100 个测试使用数据库查询。我使用 \Illuminate\Foundation\Testing\DatabaseMigrations 类在每次测试之前重置和迁移数据库(因此对于测试文件中的每个方法)。

但是当我运行 phpunit 命令时,它会显示一个错误,这是由于执行了 max_connection。

我无法增加服务器上的 max_connection 限制。我尝试为 phpunit 使用 --process-isolation 参数,但它增加了测试的持续时间:15 分钟而不是 2 分钟。

我花了很多时间寻找一种设置进程数量限制的方法,但除了 --process-isolation 参数之外我没有找到任何东西。

你知道为 PHPUnit 设置进程号的方法吗?或者测试后删除数据库连接的方法?

【问题讨论】:

    标签: php postgresql laravel testing phpunit


    【解决方案1】:

    我找到了解决办法。

    我将此方法添加到我的 tests/TestCase.php 文件中:

    public function tearDown() {
        \DB::connection()->setPdo(null);
    }
    

    使用此代码,请注意,因为父 tearDown() 方法不会运行。您可以添加此行来执行此操作:

    parent::tearDown();
    

    如果添加此行后问题仍然存在,则应分析父 tearDown() 代码以获取导致问题的代码。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-12-25
      • 1970-01-01
      • 1970-01-01
      • 2016-08-18
      • 1970-01-01
      • 1970-01-01
      • 2016-06-04
      相关资源
      最近更新 更多