Merge pull request #239 from LK4D4/race_test

Fix race in test
This commit is contained in:
Abiola Ibrahim 2015-09-11 16:58:19 +01:00
commit 26dc212f4c

View File

@ -3,6 +3,7 @@ package markdown
import (
"fmt"
"strings"
"sync"
"testing"
"time"
)
@ -23,12 +24,18 @@ func TestWatcher(t *testing.T) {
}
out = ""
i = 0
var mu sync.Mutex
stopChan = TickerFunc(interval, func() {
i++
mu.Lock()
out += fmt.Sprint(i)
mu.Unlock()
})
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)
}
}