mirror of
https://github.com/redis/go-redis.git
synced 2025-07-28 06:42:00 +03:00
Fix race in tests.
This commit is contained in:
@ -2,6 +2,7 @@ package redis
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"net"
|
"net"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -19,12 +20,18 @@ func (cn *conn) SetNetConn(netcn net.Conn) {
|
|||||||
cn.netcn = netcn
|
cn.netcn = netcn
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var timeMu sync.Mutex
|
||||||
|
|
||||||
func SetTime(tm time.Time) {
|
func SetTime(tm time.Time) {
|
||||||
|
timeMu.Lock()
|
||||||
now = func() time.Time {
|
now = func() time.Time {
|
||||||
return tm
|
return tm
|
||||||
}
|
}
|
||||||
|
timeMu.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
func RestoreTime() {
|
func RestoreTime() {
|
||||||
|
timeMu.Lock()
|
||||||
now = time.Now
|
now = time.Now
|
||||||
|
timeMu.Unlock()
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user