|
14 | 14 | use SwoftTest\Db\Testing\Pool\DbPptPoolConfig;
|
15 | 15 | use SwoftTest\Db\Testing\Pool\DbSlaveEnvPoolConfig;
|
16 | 16 | use SwoftTest\Db\Testing\Pool\DbSlavePptConfig;
|
| 17 | +use SwoftTest\Db\Testing\Pool\OtherDbPool; |
17 | 18 |
|
18 | 19 | /**
|
19 | 20 | * PoolTest
|
@@ -89,4 +90,37 @@ public function testDbSlaveEnv()
|
89 | 90 | $this->assertEquals($pConfig->isUseProvider(), false);
|
90 | 91 | $this->assertEquals($pConfig->getMaxWait(), 10);
|
91 | 92 | }
|
| 93 | + |
| 94 | + public function testMaxIdleTime() |
| 95 | + { |
| 96 | + $pool = App::getPool('idle.master'); |
| 97 | + $connection = $pool->getConnection(); |
| 98 | + $this->assertTrue($connection->check()); |
| 99 | + $connection->release(true); |
| 100 | + $connection2 = $pool->getConnection(); |
| 101 | + $this->assertTrue($connection2->check()); |
| 102 | + $connection2->release(true); |
| 103 | + } |
| 104 | + |
| 105 | + public function testMaxIdleTimeByCo() |
| 106 | + { |
| 107 | + go(function () { |
| 108 | + $this->testMaxIdleTime(); |
| 109 | + |
| 110 | + $pool = App::getPool('idle.master'); |
| 111 | + $connection = $pool->getConnection(); |
| 112 | + $this->assertTrue($connection->check()); |
| 113 | + $connection->release(true); |
| 114 | + |
| 115 | + \co::sleep(2); |
| 116 | + |
| 117 | + $connection2 = $pool->getConnection(); |
| 118 | + $this->assertFalse($connection2->check()); |
| 119 | + $connection2->release(true); |
| 120 | + |
| 121 | + $connection3 = $pool->getConnection(); |
| 122 | + $this->assertTrue($connection3->check()); |
| 123 | + $connection2->release(true); |
| 124 | + }); |
| 125 | + } |
92 | 126 | }
|
0 commit comments