Skip to content

Commit d66362c

Browse files
committed
add race condition test
1 parent c2b6fd1 commit d66362c

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

handler_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package jwt
22

33
import (
4+
"sync"
45
"testing"
56
"time"
67
)
@@ -132,3 +133,22 @@ func TestDecodeAndValidate_ExpNbf(t *testing.T) {
132133
t.Fatal("invalid token was incorrectly validated against EXP")
133134
}
134135
}
136+
137+
func TestTestEncodeAndSign_RaceCondition(t *testing.T) {
138+
alg := NewHandler[PublicClaims](NewHmacSha256([]byte(testKey)))
139+
140+
n := 100
141+
var wg sync.WaitGroup
142+
wg.Add(n)
143+
for i := 0; i < n; i++ {
144+
go func() {
145+
alg.EncodeAndSign(PublicClaims{
146+
Iss: "test",
147+
Sub: "test",
148+
})
149+
wg.Done()
150+
}()
151+
}
152+
153+
wg.Wait()
154+
}

0 commit comments

Comments
 (0)