func TestHitLimitAndRelease(t *testing.T) {
	wait := make(chan bool)
	proceed := make(chan bool)
	finish := make(chan bool)
	handler := http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
		fmt.Println(req.Header)
		if req.Header.Get("Wait") != "" {
			proceed <- true
			<-wait
		}
		w.Write([]byte("hello"))
	})
	cl, err := New(handler, headerLimit, 1)
	require.NoError(t, err)
	srv := httptest.NewServer(cl)
	defer srv.Close()
	go func() {
		re, _, errGet := testutils.Get(srv.URL, testutils.Header("Limit", "a"), testutils.Header("wait", "yes"))
		require.NoError(t, errGet)
		assert.Equal(t, http.StatusOK, re.StatusCode)
		finish <- true
	}()
	<-proceed
	re, _, err := testutils.Get(srv.URL, testutils.Header("Limit", "a"))
	require.NoError(t, err)
	assert.Equal(t, http.StatusTooManyRequests, re.StatusCode)
	re, _, err = testutils.Get(srv.URL, testutils.Header("Limit", "b"))
	require.NoError(t, err)
	assert.Equal(t, http.StatusOK, re.StatusCode)
	close(wait)
	<-finish
	re, _, err = testutils.Get(srv.URL, testutils.Header("Limit", "a"))
	require.NoError(t, err)
	assert.Equal(t, http.StatusOK, re.StatusCode)
}
We've hit the limit and were able to proceed once the request has completed
package connlimit
import (
	"fmt"
	"net/http"
	"net/http/httptest"
	"testing"
	"github.com/stretchr/testify/assert"
	"github.com/stretchr/testify/require"
	"github.com/vulcand/oxy/testutils"
	"github.com/vulcand/oxy/utils"
)