Skip to content

Commit 296613d

Browse files
larsvealdas
authored andcommitted
Add small race test
1 parent 4e1f750 commit 296613d

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

jwt_test.go

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@ package echojwt
66
import (
77
"errors"
88
"fmt"
9-
"github.com/golang-jwt/jwt/v4"
109
"net/http"
1110
"net/http/httptest"
1211
"net/url"
1312
"strings"
13+
"sync"
1414
"testing"
1515

16+
"github.com/golang-jwt/jwt/v4"
1617
"github.com/labstack/echo/v4"
1718
"github.com/labstack/echo/v4/middleware"
1819
"github.com/stretchr/testify/assert"
@@ -751,3 +752,29 @@ func TestWithConfig_panic(t *testing.T) {
751752
},
752753
)
753754
}
755+
756+
func TestToMiddlewareRace(t *testing.T) {
757+
e := echo.New()
758+
mw, err := Config{
759+
ParseTokenFunc: func(c echo.Context, auth string) (interface{}, error) {
760+
return auth, nil
761+
},
762+
SuccessHandler: func(c echo.Context) {
763+
c.Set("success", "yes")
764+
},
765+
}.ToMiddleware()
766+
assert.NoError(t, err)
767+
768+
dummyHandler := func(_ echo.Context) error { return nil }
769+
var wg sync.WaitGroup
770+
for i := 0; i < 10; i++ {
771+
wg.Add(1)
772+
go func() {
773+
defer wg.Done()
774+
for j := 0; j < 10; j++ {
775+
mw(dummyHandler)(e.NewContext(httptest.NewRequest("", "/", nil), httptest.NewRecorder()))
776+
}
777+
}()
778+
}
779+
wg.Wait()
780+
}

0 commit comments

Comments
 (0)