[GODRIVER-2785] Remove private method from Session interface Created: 29/Mar/23  Updated: 20/Oct/23  Resolved: 18/Apr/23

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

Type: Improvement Priority: Major - P3
Reporter: Nick Poindexter Assignee: Preston Vasquez
Resolution: Won't Do Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
Documentation Changes Summary:

1. What would you like to communicate to the user about this feature?
2. Would you like the user to see examples of the syntax and/or executable code and its output?
3. Which versions of the driver/connector does this apply to?


 Description   

The mongo Session interface has a private method "session" which prevents external vendors from being able to mock the interface for small unit tests.



 Comments   
Comment by Preston Vasquez [ 18/Apr/23 ]

Thank you for the context. The Go Driver team has decided not to unseal the session interface for the reasons described in my previous comment. Session will likely be converted to a struct in our Go 2.0 efforts, see GODRIVER-2800.

Comment by Nick Poindexter [ 14/Apr/23 ]

My use case was ensuring that errors thrown by the mongo Session in transactions bubbled up correctly. We on atlas app services wrap the Session interface to make it thread safe since current implementation is not thread safe.

For my tests, I just create the expected results from the 3rd party vendor (aka go driver/mongo) and ensure our code handles the results appropriately.

type mockSession struct {
	mockID  bson.Raw
	mockErr error
}
 
func (m mockSession) ID() bson.Raw {
	return m.mockID
}
 
func (m mockSession) StartTransaction(_ ...*options.TransactionOptions) error {
	return m.mockErr
}

Comment by Preston Vasquez [ 14/Apr/23 ]

nick.poindexter@mongodb.com The team that implemented sessions in the Go Driver decided to seal this interface specifically to prevent external vendors from mocking. The idea at the time was that (1) users should not mock things they don't own, and (2) it would be incredibly difficult to write a mock for this interface correctly.

The current Go Driver team have additional concerns:

  • If unsealing causes unforeseen bugs, re-sealing the interface would break backwards compatibility
  • Modifications or extensions made by other packages could potentially cause the MongoDB driver to behave unexpectedly or even result in data loss
  • It could be difficult to maintain consistency with behavior of sessions, as other packages modify or extend the interface

( * )There is also an existing 2.0 proposal to either convert the session interface to a struct, or wrap the interface in a struct wherever a session is returned to a user. See GODRIVER-2800.

Given the above, unsealing is unlikely to occur in a 1.0 version. However, in triage it was the opinion of the team that knowing your precise use case could help us evaluate the efficacy of ( * ) and troubleshoot a solution for 1.0. For example, if you are trying to write unit tests to ensure that a transaction's commit is executed only once.

Comment by Nick Poindexter [ 14/Apr/23 ]

preston.vasquez@mongodb.com I'm not sure what I could add to the description. Is there something that is unclear?

Comment by PM Bot [ 14/Apr/23 ]

Hey nick.poindexter@mongodb.com, We need additional details to investigate the problem. If this is still an issue for you, please provide the requested information.

Comment by Preston Vasquez [ 06/Apr/23 ]

nick.poindexter@mongodb.com Thank you for the ticket. Can you share more information on what you're trying to accomplish?

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