Commit 37eedf5c authored by Alexander Morozov's avatar Alexander Morozov

Fix race in test

Signed-off-by: default avatarAlexander Morozov <lk4d4@docker.com>
parent dc4a5ae1
...@@ -3,6 +3,7 @@ package markdown ...@@ -3,6 +3,7 @@ package markdown
import ( import (
"fmt" "fmt"
"strings" "strings"
"sync"
"testing" "testing"
"time" "time"
) )
...@@ -23,12 +24,18 @@ func TestWatcher(t *testing.T) { ...@@ -23,12 +24,18 @@ func TestWatcher(t *testing.T) {
} }
out = "" out = ""
i = 0 i = 0
var mu sync.Mutex
stopChan = TickerFunc(interval, func() { stopChan = TickerFunc(interval, func() {
i++ i++
mu.Lock()
out += fmt.Sprint(i) out += fmt.Sprint(i)
mu.Unlock()
}) })
time.Sleep(interval * 10) time.Sleep(interval * 10)
if !strings.HasPrefix(out, expected) || out == expected { mu.Lock()
res := out
mu.Unlock()
if !strings.HasPrefix(res, expected) || res == expected {
t.Fatalf("expected (%v) must be a proper prefix of out(%v).", expected, out) t.Fatalf("expected (%v) must be a proper prefix of out(%v).", expected, out)
} }
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment