mirror of https://github.com/go-redis/redis.git
Fix race in tests.
This commit is contained in:
parent
673e999431
commit
4edc7a059c
|
@ -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()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue