File tree Expand file tree Collapse file tree 1 file changed +28
-1
lines changed Expand file tree Collapse file tree 1 file changed +28
-1
lines changed Original file line number Diff line number Diff line change @@ -6,13 +6,14 @@ package echojwt
66import (
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+ }
You can’t perform that action at this time.
0 commit comments