Skip to content

Commit

Permalink
Add small race test
Browse files Browse the repository at this point in the history
  • Loading branch information
larsve authored and aldas committed Jan 24, 2023
1 parent 4e1f750 commit 296613d
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion jwt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ package echojwt
import (
"errors"
"fmt"
"github.com/golang-jwt/jwt/v4"
"net/http"
"net/http/httptest"
"net/url"
"strings"
"sync"
"testing"

"github.com/golang-jwt/jwt/v4"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -751,3 +752,29 @@ func TestWithConfig_panic(t *testing.T) {
},
)
}

func TestToMiddlewareRace(t *testing.T) {
e := echo.New()
mw, err := Config{
ParseTokenFunc: func(c echo.Context, auth string) (interface{}, error) {
return auth, nil
},
SuccessHandler: func(c echo.Context) {
c.Set("success", "yes")
},
}.ToMiddleware()
assert.NoError(t, err)

dummyHandler := func(_ echo.Context) error { return nil }
var wg sync.WaitGroup
for i := 0; i < 10; i++ {
wg.Add(1)
go func() {
defer wg.Done()
for j := 0; j < 10; j++ {
mw(dummyHandler)(e.NewContext(httptest.NewRequest("", "/", nil), httptest.NewRecorder()))
}
}()
}
wg.Wait()
}

0 comments on commit 296613d

Please sign in to comment.