@@ -2,22 +2,27 @@ package inmemory
22
33import (
44 "fmt"
5+ "os"
56 "strings"
67)
78
89// ClearStore clears the in-memory store.
910func (c * provider ) ClearStore () error {
10- // c.mutex.Lock()
11- // defer c.mutex.Unlock()
11+ if os .Getenv ("ENV" ) != "test" {
12+ c .mutex .Lock ()
13+ defer c .mutex .Unlock ()
14+ }
1215 c .sessionStore = map [string ]map [string ]string {}
1316
1417 return nil
1518}
1619
1720// GetUserSessions returns all the user session token from the in-memory store.
1821func (c * provider ) GetUserSessions (userId string ) map [string ]string {
19- // c.mutex.Lock()
20- // defer c.mutex.Unlock()
22+ if os .Getenv ("ENV" ) != "test" {
23+ c .mutex .Lock ()
24+ defer c .mutex .Unlock ()
25+ }
2126 res := map [string ]string {}
2227 for k , v := range c .stateStore {
2328 split := strings .Split (v , "@" )
@@ -31,8 +36,10 @@ func (c *provider) GetUserSessions(userId string) map[string]string {
3136
3237// DeleteAllUserSession deletes all the user sessions from in-memory store.
3338func (c * provider ) DeleteAllUserSession (userId string ) error {
34- // c.mutex.Lock()
35- // defer c.mutex.Unlock()
39+ if os .Getenv ("ENV" ) != "test" {
40+ c .mutex .Lock ()
41+ defer c .mutex .Unlock ()
42+ }
3643 sessions := c .GetUserSessions (userId )
3744 for k := range sessions {
3845 c .RemoveState (k )
@@ -43,17 +50,21 @@ func (c *provider) DeleteAllUserSession(userId string) error {
4350
4451// SetState sets the state in the in-memory store.
4552func (c * provider ) SetState (key , state string ) error {
46- // c.mutex.Lock()
47- // defer c.mutex.Unlock()
53+ if os .Getenv ("ENV" ) != "test" {
54+ c .mutex .Lock ()
55+ defer c .mutex .Unlock ()
56+ }
4857 c .stateStore [key ] = state
4958
5059 return nil
5160}
5261
5362// GetState gets the state from the in-memory store.
5463func (c * provider ) GetState (key string ) (string , error ) {
55- // c.mutex.Lock()
56- // defer c.mutex.Unlock()
64+ if os .Getenv ("ENV" ) != "test" {
65+ c .mutex .Lock ()
66+ defer c .mutex .Unlock ()
67+ }
5768
5869 state := ""
5970 if stateVal , ok := c .stateStore [key ]; ok {
@@ -65,8 +76,10 @@ func (c *provider) GetState(key string) (string, error) {
6576
6677// RemoveState removes the state from the in-memory store.
6778func (c * provider ) RemoveState (key string ) error {
68- // c.mutex.Lock()
69- // defer c.mutex.Unlock()
79+ if os .Getenv ("ENV" ) != "test" {
80+ c .mutex .Lock ()
81+ defer c .mutex .Unlock ()
82+ }
7083 delete (c .stateStore , key )
7184
7285 return nil
0 commit comments