-
-
Notifications
You must be signed in to change notification settings - Fork 239
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
Make structs thread-safe #233
Comments
@gavv I'd like to take this up. Sounds interesting!! |
Great! |
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
I was reviewing #254 and realized that there is a problem with our approach. We acquire a lock, then perform a check, and then report failure, under the lock. A potential problem is that reporting failure means invoking AssertionHandler, Reporter, Logger, Formatter, which may be implemented by user. In other words, we invoke user code under a lock. If this user code will try to access our object, we'll get deadlock. For example, if AssertionHandler tries to get a value from env, env method will try to acquire a lock and will hang. I have an idea of quite generic approach to avoid this. We can introduce three rules:
This way, failures are guaranteed to be reported outside of the lock (because leave is called after releasing lock). Which means that associated user code is also called outside of the lock. Two simple changes are needed:
|
Is this still open? |
@sujeetsawala yes. I plan to finish it by myself, except stress test. If you would like to help with stress test, you're welcome! It can be done independently of other stuff. |
@gavv I have the following questions:-
Can you explain the objectives of our stress test? |
Background: #229
I've pushed a few changes that make the
chain
struct thread-safe:This automatically makes many structs thread-safe too: Expect, Value, Array, Object, etc. It's true for matcher structs which contains only a chain + immutable data.
The next step is to manually implement thread-safety for the following structs:
These three structs has mutable state and should be protected manually. For each of them, we should add sync.RWMutex field and protect all operations. We can remove noCopy fields from these structs.
Request struct needs special care: it contains
transforms
andmatchers
callbacks that are invoked during Expect() call. We should NOT call them under a lock because otherwise it would be easy to write code with deadlocks (if you use the same request from this callbacks).Websocket also needs some special handling. It should allow to read and write messages concurrently and to call disconnect concurrently (similarly as gorilla websocket which it uses under the hood).
After finishing this, we should update docs:
In addition, we should improve our testing suite:
make race
target which runs all tests under race detectorThe text was updated successfully, but these errors were encountered: