[GODRIVER-2068] Replace all uses of isPoolCleared() and clearPoolChan() in tests with testPoolMonitor Created: 28/Jun/21  Updated: 04/Apr/22  Resolved: 04/Apr/22

Status: Closed
Project: Go Driver
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Improvement Priority: Unknown
Reporter: Matt Dale Assignee: Matt Dale
Resolution: Done Votes: 0
Labels: greenerbuild
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
is related to GODRIVER-2037 Don't clear the connection pool on Co... Closed

 Description   

Various mongo/integration package tests currently use a package-global event.PoolMonitor variable poolMonitor to collect connection pool events and the package-global functions isPoolCleared() and clearPoolChan() to manage the collected events. The result is that different tests and test cases can sometimes interact with each others events, causing intermittent assertion failures or timeouts on channel sends (e.g. when the poolMonitor's events channel fills up without being cleared).

To resolve the unexpected interaction between tests, replace all uses of the package-global poolMonitor with individual instances of the new testPoolMonitor. Also, replace isPoolCleared() with the condition:

poolClearedEvents := tpm.Events(func(evt *event.PoolEvent) bool {
	return evt.Type == event.PoolCleared
})
len(poolClearedEvents) > 0

 

Also consider moving testPoolMonitor into a shared test utilities package and export it. Use it for similar use cases from other tests, like topology.TestServerConnectionTimeout and topology.TestServerConnectionCancellation.



 Comments   
Comment by Githook User [ 01/Apr/22 ]

Author:

{'name': 'Matt Dale', 'email': '9760375+matthewdale@users.noreply.github.com', 'username': 'matthewdale'}

Message: GODRIVER-2068 Use monitor.TestPoolMonitor to replace most connection pool monitors in tests. (#890)
Branch: master
https://github.com/mongodb/mongo-go-driver/commit/3d60e915318c66ac5cee869dd15e2e5c56ac269f

Comment by Matt Dale [ 30/Mar/22 ]

PR: https://github.com/mongodb/mongo-go-driver/pull/890

Comment by Matt Dale [ 25/Mar/22 ]

Using a TestPoolMonitor for the TestServerConnectionTimeout/operation_context_timeout_with_unrelated_dial_errors_should_clear_the_pool test may improve reliability of that test. See failure example here

Generated at Thu Feb 08 08:37:45 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.