Adjust sync test intervals to be less latency sensitive

This commit is contained in:
Jakob Borg 2015-04-24 11:25:24 +09:00
parent c5027d9478
commit e158f17c2b

View File

@ -15,6 +15,12 @@ import (
"github.com/calmh/logger" "github.com/calmh/logger"
) )
const (
logThreshold = 100 * time.Millisecond
shortWait = 5 * time.Millisecond
longWait = 125 * time.Millisecond
)
func TestTypes(t *testing.T) { func TestTypes(t *testing.T) {
debug = false debug = false
@ -49,7 +55,7 @@ func TestTypes(t *testing.T) {
func TestMutex(t *testing.T) { func TestMutex(t *testing.T) {
debug = true debug = true
threshold = time.Millisecond * 5 threshold = logThreshold
msgmut := sync.Mutex{} msgmut := sync.Mutex{}
messages := make([]string, 0) messages := make([]string, 0)
@ -62,7 +68,7 @@ func TestMutex(t *testing.T) {
mut := NewMutex() mut := NewMutex()
mut.Lock() mut.Lock()
time.Sleep(2 * time.Millisecond) time.Sleep(shortWait)
mut.Unlock() mut.Unlock()
if len(messages) > 0 { if len(messages) > 0 {
@ -70,7 +76,7 @@ func TestMutex(t *testing.T) {
} }
mut.Lock() mut.Lock()
time.Sleep(6 * time.Millisecond) time.Sleep(longWait)
mut.Unlock() mut.Unlock()
if len(messages) != 1 { if len(messages) != 1 {
@ -82,7 +88,7 @@ func TestMutex(t *testing.T) {
func TestRWMutex(t *testing.T) { func TestRWMutex(t *testing.T) {
debug = true debug = true
threshold = time.Millisecond * 5 threshold = logThreshold
msgmut := sync.Mutex{} msgmut := sync.Mutex{}
messages := make([]string, 0) messages := make([]string, 0)
@ -95,7 +101,7 @@ func TestRWMutex(t *testing.T) {
mut := NewRWMutex() mut := NewRWMutex()
mut.Lock() mut.Lock()
time.Sleep(2 * time.Millisecond) time.Sleep(shortWait)
mut.Unlock() mut.Unlock()
if len(messages) > 0 { if len(messages) > 0 {
@ -103,7 +109,7 @@ func TestRWMutex(t *testing.T) {
} }
mut.Lock() mut.Lock()
time.Sleep(6 * time.Millisecond) time.Sleep(longWait)
mut.Unlock() mut.Unlock()
if len(messages) != 1 { if len(messages) != 1 {
@ -113,7 +119,7 @@ func TestRWMutex(t *testing.T) {
// Testing rlocker logging // Testing rlocker logging
mut.RLock() mut.RLock()
go func() { go func() {
time.Sleep(7 * time.Millisecond) time.Sleep(longWait)
mut.RUnlock() mut.RUnlock()
}() }()
@ -140,7 +146,7 @@ func TestRWMutex(t *testing.T) {
func TestWaitGroup(t *testing.T) { func TestWaitGroup(t *testing.T) {
debug = true debug = true
threshold = time.Millisecond * 5 threshold = logThreshold
msgmut := sync.Mutex{} msgmut := sync.Mutex{}
messages := make([]string, 0) messages := make([]string, 0)
@ -154,7 +160,7 @@ func TestWaitGroup(t *testing.T) {
wg := NewWaitGroup() wg := NewWaitGroup()
wg.Add(1) wg.Add(1)
go func() { go func() {
time.Sleep(2 * time.Millisecond) time.Sleep(shortWait)
wg.Done() wg.Done()
}() }()
wg.Wait() wg.Wait()
@ -166,7 +172,7 @@ func TestWaitGroup(t *testing.T) {
wg = NewWaitGroup() wg = NewWaitGroup()
wg.Add(1) wg.Add(1)
go func() { go func() {
time.Sleep(6 * time.Millisecond) time.Sleep(longWait)
wg.Done() wg.Done()
}() }()
wg.Wait() wg.Wait()