/**
* Test the following scenario:
*   Goroutine 1 borrows an instance
*   Goroutine 2 starts to borrow another instance before goroutine 1 returns its instance
*   Goroutine 1 returns its instance while goroutine 2 is validating its newly created instance
* The test verifies that the instance created by Goroutine 2 is not leaked.
 */
Test the following scenario:
Goroutine 1 borrows an instance
Goroutine 2 starts to borrow another instance before goroutine 1 returns its instance
Goroutine 1 returns its instance while goroutine 2 is validating its newly created instance
The test verifies that the instance created by Goroutine 2 is not leaked.
/ ** * Test the following scenario : * Goroutine 1 borrows an instance * Goroutine 2 starts to borrow another instance before goroutine 1 returns its instance * Goroutine 1 returns its instance while goroutine 2 is validating its newly created instance * The test verifies that the instance created by Goroutine 2 is not leaked . * /
func (suit *PoolTestSuite) TestMakeConcurrentWithReturn() {
	suit.pool.Config.TestOnBorrow = true
	suit.factory.setValid(true)
	ch := waitTestGoroutine(suit.pool, 200)
	sleep(50) 
	suit.factory.setValidateLatency(400)
	instance := suit.NoErrorWithResult(suit.pool.BorrowObject())
	suit.Equal(suit.factory.makeCounter, suit.pool.GetNumIdle()+1)
	suit.NoError(suit.pool.ReturnObject(instance))
	suit.Equal(suit.factory.makeCounter, suit.pool.GetNumIdle())
	<-ch
	close(ch)
}
func ( suit * PoolTestSuite ) TestMakeConcurrentWithReturn ( ) { suit . pool . Config . TestOnBorrow = true suit . factory . setValid ( true ) ch := waitTestGoroutine ( suit . pool , 200 ) sleep ( 50 ) suit . factory . setValidateLatency ( 400 ) instance := suit . NoErrorWithResult ( suit . pool . BorrowObject ( ) ) suit . Equal ( suit . factory . makeCounter , suit . pool . GetNumIdle ( ) + 1 ) suit . NoError ( suit . pool . ReturnObject ( instance ) ) suit . Equal ( suit . factory . makeCounter , suit . pool . GetNumIdle ( ) ) <- ch close ( ch ) }
Test the following scenario:
Goroutine 1 borrows an instance
Goroutine 2 starts to borrow another instance before goroutine 1 returns its instance
Goroutine 1 returns its instance while goroutine 2 is validating its newly created instance
The test verifies that the instance created by Goroutine 2 is not leaked.
Test the following scenario : Goroutine 1 borrows an instance Goroutine 2 starts to borrow another instance before goroutine 1 returns its instance Goroutine 1 returns its instance while goroutine 2 is validating its newly created instance The test verifies that the instance created by Goroutine 2 is not leaked .
// Borrow and return an instance, with a short wait // wait for validation to succeed // Slow down validation and borrow an instance // Now make sure that we have not leaked an instance