Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow safe concurrent access to (mock.Mock).Calls #1128

Open
brackendawson opened this issue Nov 29, 2021 · 1 comment
Open

Allow safe concurrent access to (mock.Mock).Calls #1128

brackendawson opened this issue Nov 29, 2021 · 1 comment
Labels
concurrency pkg-mock Any issues related to Mock

Comments

@brackendawson
Copy link
Collaborator

brackendawson commented Nov 29, 2021

Like #965, I bumped into a need to safely access (mock.Mock).Calls today, but I wanted the calls rather than the length.

I think either a method to copy the Calls and return them:

// GetCalls returns a copy of the current Calls array.
func (m *Mock) GetCalls() []*Call

Or a high order method to safely access the Calls slice:

func (m *Mock) CallsFn(f ([]*Call)) {
    m.mutex.Lock()
    defer m.mutex.Unlock()
    f(m.Calls)
}
@brackendawson
Copy link
Collaborator Author

Related to #944

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
concurrency pkg-mock Any issues related to Mock
Projects
None yet
Development

No branches or pull requests

2 participants