From 4edc7a059c71eec2003ec25559f0d2d32df99ba3 Mon Sep 17 00:00:00 2001 From: Vladimir Mihailenco Date: Wed, 9 Mar 2016 12:49:21 +0200 Subject: [PATCH] Fix race in tests. --- export_test.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/export_test.go b/export_test.go index 95715b5f..36b2c547 100644 --- a/export_test.go +++ b/export_test.go @@ -2,6 +2,7 @@ package redis import ( "net" + "sync" "time" ) @@ -19,12 +20,18 @@ func (cn *conn) SetNetConn(netcn net.Conn) { cn.netcn = netcn } +var timeMu sync.Mutex + func SetTime(tm time.Time) { + timeMu.Lock() now = func() time.Time { return tm } + timeMu.Unlock() } func RestoreTime() { + timeMu.Lock() now = time.Now + timeMu.Unlock() }