@@ -13,6 +13,7 @@ import (
1313 headers2 "github.com/TykTechnologies/tyk/header"
1414 "github.com/TykTechnologies/tyk/internal/cache"
1515 "github.com/TykTechnologies/tyk/internal/uuid"
16+ "github.com/TykTechnologies/tyk/rpc"
1617 "github.com/TykTechnologies/tyk/test"
1718
1819 "github.com/TykTechnologies/tyk/config"
@@ -57,7 +58,7 @@ func TestBaseMiddleware_OrgSessionExpiry(t *testing.T) {
5758 assert .Equal (t , v , got )
5859 })
5960
60- t .Run ("should return default and trigger background refresh on cache miss" , func (t * testing.T ) {
61+ t .Run ("should return default immediately on cache miss" , func (t * testing.T ) {
6162 m := & BaseMiddleware {
6263 Spec : & APISpec {
6364 GlobalConfig : config.Config {
@@ -116,10 +117,18 @@ func TestBaseMiddleware_OrgSessionExpiry(t *testing.T) {
116117 ts .Gw .ExpiryCache .Delete (noOrgSess )
117118
118119 got := m .OrgSessionExpiry (noOrgSess )
119- assert .Equal (t , DEFAULT_ORG_SESSION_EXPIRATION , got )
120+ assert .Equal (t , DEFAULT_ORG_SESSION_EXPIRATION , got , "Should return default immediately on cache miss" )
121+
122+ m .refreshOrgSessionExpiry (noOrgSess )
123+
124+ cachedVal , found := ts .Gw .ExpiryCache .Get (noOrgSess )
125+ assert .True (t , found , "Cache should be populated after background refresh" )
126+ assert .Equal (t , DEFAULT_ORG_SESSION_EXPIRATION , cachedVal .(int64 ), "Cache should contain default expiration when org not found" )
120127 })
121128
122129 t .Run ("should return default immediately in emergency mode" , func (t * testing.T ) {
130+ rpc .SetEmergencyMode (t , true )
131+ defer rpc .SetEmergencyMode (t , false )
123132
124133 m := & BaseMiddleware {
125134 Spec : & APISpec {
@@ -154,7 +163,13 @@ func TestBaseMiddleware_OrgSessionExpiry(t *testing.T) {
154163 ts .Gw .ExpiryCache .Delete (sess .OrgID )
155164
156165 got := m .OrgSessionExpiry (sess .OrgID )
157- assert .Equal (t , DEFAULT_ORG_SESSION_EXPIRATION , got )
166+ assert .Equal (t , DEFAULT_ORG_SESSION_EXPIRATION , got , "Should return default immediately on cache miss" )
167+
168+ m .refreshOrgSessionExpiry (sess .OrgID )
169+
170+ cachedVal , found := ts .Gw .ExpiryCache .Get (sess .OrgID )
171+ assert .True (t , found , "Cache should be populated after background refresh" )
172+ assert .Equal (t , DEFAULT_ORG_SESSION_EXPIRATION , cachedVal .(int64 ), "Cache should contain default expiration when EnforceOrgDataAge is disabled" )
158173 })
159174}
160175
0 commit comments