php – max连接MySql在测试期间到达

前端之家收集整理的这篇文章主要介绍了php – max连接MySql在测试期间到达前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
当我启动我的 PHPUnit测试套件时,我达到MysqL的最大连接限制(200).

热修复是将max_connection设置为500,但是我在Zend Framework 2上下文中寻找更好的解决方案.

我试图放一些tearDown方法,但没有运气似乎是无用的或不完整的解决方案.

这是一个代码示例:

  1. protected function tearDown()
  2. {
  3. // i have two entitymanager
  4. $this->getObjectManager()->get('doctrine.connection.orm_alternate')->close();
  5. $this->getObjectManager()->get('doctrine.connection.orm_default')->close();
  6. $this->application = null;
  7. gc_collect_cycles();
  8. parent::tearDown();
  9. }

我也试图使用processIsolation转为true,但一些测试是如此之长,以至于我假设我的控制台已经冻结或类似的东西….

使用doctrine2连接和Zend Framework,如何在PHPunit测试期间阻止这种“太多连接”?

到目前为止,我尝试修改了@awons的提示
$这个 – > getObjectManager() – >获得( ‘doctrine.connection.orm_alternate’) – >关闭();


$这个 – > getObjectManager() – >获得( ‘doctrine.entitymanager.orm_alternate’) – >关闭();

是的,我检查了是否拆卸.

我不明白的是:在每个测试中,我的连接的一个新实例被创建,为什么这不是一样的实例? (像单身或注册)?
但是,即使测试通过后,该实例也不会关闭.

我错了,但不知道什么.

在这样做之前,我已经解决了类似的问题:
  1. protected static $my_db_for_testing
  2.  
  3. public static function setUpBeforeClass()
  4. {
  5. //create your DB connection once,here.
  6. $self::$my_db_for_testing = new DbConnectionWhatever()
  7. }
  8.  
  9. protected function setUp()
  10. {
  11. $this->my_obj_to_test = new MyObject();
  12. $this->my_obj_to_test->setDb($this->my_db_for_testing);
  13. }
  14.  
  15.  
  16.  
  17. public function testOne()
  18. {
  19. //normal test here
  20. }
  21.  
  22. public static function tearDownAfterClass()
  23. {
  24. //close the DB connection here
  25. }

}

猜你在找的PHP相关文章