gavv / gavv/httpexpect

Make structs thread-safe

Open
#233 10 comments 0 reactions 1 assignee Assigned to @gavv View on GitHub
feature important
Dominant language
Go
Stars
2.7k
Forks
241
PR merge metrics
No merged PRs in 30d

Description

Background: https://github.com/gavv/httpexpect/discussions/229

I've pushed a few changes that make the `chain` struct thread-safe:

* 0547acd58636b8dc199f43fd7206d9bb629e7852
* a96122195174a5b9df2804e41c8abe92a90fc52b
* 90675e11729f5dfa5121bbf41a1e071dbf9e52e7

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:

- [x] Environment
- [x] Request
- [ ] Websocket

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` and `matchers` 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:

- [ ] add thread-safety section to package documentation, mention limitation placed by httpexpect, testify, and standard testing
- [ ] add note to README

In addition, we should improve our testing suite:

* [ ] add `make race` target which runs all tests under race detector
* [ ] add corresponding step to CI
* [ ] create issue for implementing stress test

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.