Skip to content

elgohr/stop-and-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

65 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

stop-and-go

Actions Status codecov Go Report Card PkgGoDev License: MIT

Testing helper for concurrency

Install

go get -u github.com/elgohr/stop-and-go

Usage

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)
	}
}

Contributors 4

  •  
  •  
  •  
  •  

Languages