https://github.com/elgohr/stop-and-go
Testing helper for concurrency
https://github.com/elgohr/stop-and-go
concurrency go golang helper testing
Last synced: 8 days ago
JSON representation
Testing helper for concurrency
- Host: GitHub
- URL: https://github.com/elgohr/stop-and-go
- Owner: elgohr
- License: mit
- Created: 2020-11-06T09:04:58.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2024-11-25T17:10:20.000Z (8 months ago)
- Last Synced: 2025-04-02T08:48:06.631Z (3 months ago)
- Topics: concurrency, go, golang, helper, testing
- Language: Go
- Homepage:
- Size: 61.5 KB
- Stars: 12
- Watchers: 1
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-go - stop-and-go - Testing helper for concurrency. (Testing / Testing Frameworks)
- awesome-go-extra - stop-and-go - 11-06T09:04:58Z|2022-06-29T16:23:11Z| (Testing / Testing Frameworks)
README
# stop-and-go
[](https://github.com/elgohr/stop-and-go/actions)
[](https://codecov.io/gh/elgohr/stop-and-go)
[](https://goreportcard.com/report/github.com/elgohr/stop-and-go)
[](https://pkg.go.dev/github.com/elgohr/stop-and-go)
[](https://opensource.org/licenses/MIT)Testing helper for concurrency
## Install
```bash
go get -u github.com/elgohr/stop-and-go
```## Usage
```go
func TestExample(t *testing.T) {
w1 := wait.NewWaiter(time.Second)
w2 := wait.NewWaiter(time.Second)
w3 := wait.NewWaiter(time.Second)ts1 := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
w2.Done()
}))
defer ts1.Close()go func() {
w3.Done()
}()go func() {
if _, err := http.Get(ts1.URL); err != nil {
t.Error(err)
}
w1.Done()
}()if err := wait.For(
constraint.NoOrder(w3),
constraint.Before(w1, w2),
); err != nil {
t.Error(err)
}
}
```