Skip to content

Commit fe57b68

Browse files
Merge pull request #336 from supertokens/session-test-fix
fix: jwks test
2 parents e02a2bc + d07f0af commit fe57b68

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

recipe/session/recipeImplementation.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func getJWKSFromCacheIfPresent() *sessmodels.GetJWKSResult {
6363
// from the cores again after the entry in the cache is expired
6464
if (currentTime - jwksCache.LastFetched) < JWKCacheMaxAgeInMs {
6565
if supertokens.IsRunningInTestMode() {
66-
returnedFromCache = true
66+
returnedFromCache <- true
6767
}
6868

6969
return jwksCache
@@ -116,7 +116,7 @@ func getJWKS() (*keyfunc.JWKS, error) {
116116
jwksCache = &jwksResult
117117

118118
if supertokens.IsRunningInTestMode() {
119-
returnedFromCache = false
119+
returnedFromCache <- false
120120
}
121121

122122
return jwksResult.JWKS, nil

recipe/session/session_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1973,6 +1973,7 @@ func TestThatLockingForJWKSCacheWorksFine(t *testing.T) {
19731973
if err != nil {
19741974
t.Error(err.Error())
19751975
}
1976+
<-returnedFromCache // this value must be ignored
19761977

19771978
for _, k := range jwks.KIDs() {
19781979
keys = append(keys, k)
@@ -1989,7 +1990,7 @@ func TestThatLockingForJWKSCacheWorksFine(t *testing.T) {
19891990

19901991
for i := 0; i < threadCount; i++ {
19911992
go jwksLockTestRoutine(t, &shouldStop, i, &wg, func(_keys []string) {
1992-
if returnedFromCache == false {
1993+
if <-returnedFromCache == false {
19931994
notReturnFromCacheCount++
19941995
}
19951996

recipe/session/testingUtils.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ import (
2424

2525
// Testing constants
2626
var didGetSessionCallCore = false
27-
var returnedFromCache = false
27+
var returnedFromCache chan bool
2828
var urlsAttemptedForJWKSFetch []string
2929

3030
func resetAll() {
3131
supertokens.ResetForTest()
3232
ResetForTest()
3333
didGetSessionCallCore = false
34-
returnedFromCache = false
34+
returnedFromCache = make(chan bool, 1000)
3535
urlsAttemptedForJWKSFetch = []string{}
3636
jwksCache = nil
3737
}

0 commit comments

Comments
 (0)