Fix race in tests.

This commit is contained in:
Vladimir Mihailenco 2016-03-09 12:49:21 +02:00
parent 673e999431
commit 4edc7a059c
1 changed files with 7 additions and 0 deletions

View File

@ -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()
} }