/*
 * Test multi-goroutineed pool access.
 * Multiple goroutines, but maxTotal only allows half the goroutines to succeed.
 *
 * This test was prompted by Continuum build failures in the Commons DBCP test case:
 * TestPerUserPoolDataSource.testMultipleGoroutines2()
 * Let's see if the suit fails on Continuum too!
 */
Test multi-goroutineed pool access.
Multiple goroutines, but maxTotal only allows half the goroutines to succeed.

This test was prompted by Continuum build failures in the Commons DBCP test case:
TestPerUserPoolDataSource.testMultipleGoroutines2()
Let's see if the suit fails on Continuum too!
/ * * Test multi - goroutineed pool access . * Multiple goroutines but maxTotal only allows half the goroutines to succeed . * * This test was prompted by Continuum build failures in the Commons DBCP test case : * TestPerUserPoolDataSource . testMultipleGoroutines2 () * Let ' s see if the suit fails on Continuum too! * /
func (suit *PoolTestSuite) TestMaxWaitMultiGoroutineed() {
	maxWait := 500          
	holdTime := 2 * maxWait 
	goroutines := 10        
	suit.pool.Config.BlockWhenExhausted = true
	suit.pool.Config.MaxWaitMillis = int64(maxWait)
	suit.pool.Config.MaxTotal = goroutines
	resultChans := make([]chan TestGoroutineResult, goroutines*2)
	origin := currentTimeMillis() - 1000
	for i := 0; i < len(resultChans); i++ {
		resultChans[i] = waitTestGoroutine(suit.pool, holdTime)
	}
	failed := 0
	results := make([]TestGoroutineResult, len(resultChans))
	for i := 0; i < len(resultChans); i++ {
		ch := resultChans[i]
		result := <-ch
		close(ch)
		results[i] = result
		if result.error != nil {
			failed++
		}
	}
	if debugTest || len(resultChans)/2 != failed {
		fmt.Println(
			"MaxWait: ", maxWait,
			" HoldTime: ", holdTime,
			" MaxTotal: ", goroutines,
			" Goroutines: ", len(resultChans),
			" Failed: ", failed)
		for _, result := range results {
			fmt.Println(
				"Preborrow: ", (result.preborrow - origin),
				" Postborrow: ", (result.postborrow - origin),
				" BorrowTime: ", (result.postborrow - result.preborrow),
				" PostReturn: ", (result.postreturn - origin),
				" Ended: ", (result.ended - origin),
				" ObjId: ", result.objectID)
		}
	}
	suit.Equal(len(resultChans)/2, failed, "Expected half the goroutines to fail")
}
func ( suit * PoolTestSuite ) TestMaxWaitMultiGoroutineed ( ) { maxWait := 500 holdTime := 2 * maxWait goroutines := 10 suit . pool . Config . BlockWhenExhausted = true suit . pool . Config . MaxWaitMillis = int64 ( maxWait ) suit . pool . Config . MaxTotal = goroutines resultChans := make ( [ ] chan TestGoroutineResult , goroutines * 2 ) origin := currentTimeMillis ( ) - 1000 for i := 0 ; i < len ( resultChans ) ; i ++ { resultChans [ i ] = waitTestGoroutine ( suit . pool , holdTime ) } failed := 0 results := make ( [ ] TestGoroutineResult , len ( resultChans ) ) for i := 0 ; i < len ( resultChans ) ; i ++ { ch := resultChans [ i ] result := <- ch close ( ch ) results [ i ] = result if result . error != nil { failed ++ } } if debugTest || len ( resultChans ) / 2 != failed { fmt . Println ( " " , maxWait , " " , holdTime , " " , goroutines , " " , len ( resultChans ) , " " , failed ) for _ , result := range results { fmt . Println ( " " , ( result . preborrow - origin ) , " " , ( result . postborrow - origin ) , " " , ( result . postborrow - result . preborrow ) , " " , ( result . postreturn - origin ) , " " , ( result . ended - origin ) , " " , result . objectID ) } } suit . Equal ( len ( resultChans ) / 2 , failed , " " ) }
Test multi-goroutineed pool access.
Test multi - goroutineed pool access .
// wait for connection // how long to hold connection // number of goroutines to grab the object initially // Create enough goroutines so half the goroutines will have to wait