If your mock an interface that matches the fmt.Stringer interface:
type Stringer interface {
String() string
}
Then your unit tests can deadlock if you provide that mock as an expected argument to a call that is not matched (i.e. fails the test).
Because, when printing the error message for the call that was not matched, it calls String() on all arguments that support it, including the mock.
But each call to a mock is protected with a mutex, and the previous call (that was not matched) has not yet exited.
Solution
The solution has two parts
During mock code generation (an existing part of this library) add a unique method on mocks (ISGOMOCK)
During test execution, whenever we are stringifying something that might be a mock, check if it is a mock (ISGOMOCK) that implements the String() method. If it is, just use the type name as the string value, instead of calling String() (which would cause the deadlock).
Fixes #116
Problem
If your mock an interface that matches the fmt.Stringer interface:
Then your unit tests can deadlock if you provide that mock as an expected argument to a call that is not matched (i.e. fails the test).
Because, when printing the error message for the call that was not matched, it calls
String()
on all arguments that support it, including the mock.But each call to a mock is protected with a mutex, and the previous call (that was not matched) has not yet exited.
Solution
The solution has two parts