/**
 * Tests fix for Bug 28579, a bug in AbandonedObjectPool that causes numActive to go negative
 * in GenericObjectPool
 */
Tests fix for Bug 28579, a bug in AbandonedObjectPool that causes numActive to go negative
in GenericObjectPool
/ ** * Tests fix for Bug 28579 a bug in AbandonedObjectPool that causes numActive to go negative * in GenericObjectPool * /
func (suit *PoolAbandonedTestSuite) TestConcurrentInvalidation() {
	poolSize := 30
	suit.pool.Config.MaxTotal = poolSize
	suit.pool.Config.MaxIdle = poolSize
	suit.pool.Config.BlockWhenExhausted = false
	vec := make([]*AbandonedTestObject, poolSize)
	for i := 0; i < poolSize; i++ {
		vec[i] = suit.NoErrorWithResult(suit.pool.BorrowObject()).(*AbandonedTestObject)
	}
	for i := 0; i < len(vec); i++ {
		vec[i]._abandoned = true
	}
	concurrentBorrows := 5
	objects := make(chan *AbandonedTestObject, poolSize)
	wait := sync.WaitGroup{}
	wait.Add(concurrentBorrows)
	for i := 0; i < concurrentBorrows; i++ {
		concurrentBorrower(suit.pool, objects, &wait)
	}
	wait.Wait()
	for i := 0; i < len(objects); i++ {
		vec = append(vec, <-objects)
	}
	close(objects)
	for i := 0; i < len(vec); i++ {
		pto := vec[i]
		if pto.active {
			suit.NoError(suit.pool.ReturnObject(pto))
		}
	}
	suit.True(suit.pool.GetNumActive() == 0, "numActive should have been 0, was %v", suit.pool.GetNumActive())
}
func ( suit * PoolAbandonedTestSuite ) TestConcurrentInvalidation ( ) { poolSize := 30 suit . pool . Config . MaxTotal = poolSize suit . pool . Config . MaxIdle = poolSize suit . pool . Config . BlockWhenExhausted = false vec := make ( [ ] * AbandonedTestObject , poolSize ) for i := 0 ; i < poolSize ; i ++ { vec [ i ] = suit . NoErrorWithResult ( suit . pool . BorrowObject ( ) ) . ( * AbandonedTestObject ) } for i := 0 ; i < len ( vec ) ; i ++ { vec [ i ] . _abandoned = true } concurrentBorrows := 5 objects := make ( chan * AbandonedTestObject , poolSize ) wait := sync . WaitGroup { } wait . Add ( concurrentBorrows ) for i := 0 ; i < concurrentBorrows ; i ++ { concurrentBorrower ( suit . pool , objects , & wait ) } wait . Wait ( ) for i := 0 ; i < len ( objects ) ; i ++ { vec = append ( vec , <- objects ) } close ( objects ) for i := 0 ; i < len ( vec ) ; i ++ { pto := vec [ i ] if pto . active { suit . NoError ( suit . pool . ReturnObject ( pto ) ) } } suit . True ( suit . pool . GetNumActive ( ) == 0 , " " , suit . pool . GetNumActive ( ) ) }
Tests fix for Bug 28579, a bug in AbandonedObjectPool that causes numActive to go negative
in GenericObjectPool
Tests fix for Bug 28579 a bug in AbandonedObjectPool that causes numActive to go negative in GenericObjectPool
// Exhaust the connection pool // Abandon all borrowed objects // Try launching a bunch of borrows concurrently.  Abandoned sweep will be triggered for each. // Wait for all the goroutine to finish // Return all objects that have not been destroyed // Now, the number of active instances should be 0