gpio: adjust test timeouts

Signed-off-by: deadprogram <ron@hybridgroup.com>
This commit is contained in:
deadprogram 2017-04-21 11:13:56 +02:00
parent d27ad850f3
commit 84dfbc9f89
4 changed files with 45 additions and 48 deletions

View File

@ -12,7 +12,7 @@ import (
var _ gobot.Driver = (*ButtonDriver)(nil)
const BUTTON_TEST_DELAY = 150
const buttonTestDelay = 250
func initTestButtonDriver() *ButtonDriver {
return NewButtonDriver(newGpioTestAdaptor(), "1")
@ -52,7 +52,7 @@ func TestButtonDriverStart(t *testing.T) {
select {
case <-sem:
case <-time.After(BUTTON_TEST_DELAY * time.Millisecond):
case <-time.After(buttonTestDelay * time.Millisecond):
t.Errorf("Button Event \"Push\" was not published")
}
@ -68,40 +68,40 @@ func TestButtonDriverStart(t *testing.T) {
select {
case <-sem:
case <-time.After(BUTTON_TEST_DELAY * time.Millisecond):
case <-time.After(buttonTestDelay * time.Millisecond):
t.Errorf("Button Event \"Release\" was not published")
}
d.Once(Error, func(data interface{}) {
sem <- true
})
a.TestAdaptorDigitalRead(func() (val int, err error) {
err = errors.New("digital read error")
return
})
d.Once(Error, func(data interface{}) {
sem <- true
})
select {
case <-sem:
case <-time.After(BUTTON_TEST_DELAY * time.Millisecond):
case <-time.After(buttonTestDelay * time.Millisecond):
t.Errorf("Button Event \"Error\" was not published")
}
d.Once(ButtonPush, func(data interface{}) {
sem <- true
})
a.TestAdaptorDigitalRead(func() (val int, err error) {
val = 1
return
})
d.Once(ButtonPush, func(data interface{}) {
sem <- true
})
d.halt <- true
select {
case <-sem:
t.Errorf("Button Event \"Press\" should not published")
case <-time.After(BUTTON_TEST_DELAY * time.Millisecond):
case <-time.After(buttonTestDelay * time.Millisecond):
}
}

View File

@ -71,9 +71,6 @@ func TestLedDriverToggle(t *testing.T) {
}
func TestLedDriverBrightness(t *testing.T) {
// d := initTestLedDriver(&gpioTestDigitalWriter{})
// gobottest.Assert(t, d.Brightness(150), ErrPwmWriteUnsupported)
a := newGpioTestAdaptor()
d := NewLedDriver(a, "1")
a.testAdaptorPwmWrite = func() (err error) {

View File

@ -11,7 +11,7 @@ import (
var _ gobot.Driver = (*MakeyButtonDriver)(nil)
const MAKEY_TEST_DELAY = 30
const makeyTestDelay = 250
func initTestMakeyButtonDriver() *MakeyButtonDriver {
return NewMakeyButtonDriver(newGpioTestAdaptor(), "1")
@ -27,7 +27,7 @@ func TestMakeyButtonDriverHalt(t *testing.T) {
gobottest.Assert(t, d.Halt(), nil)
select {
case <-done:
case <-time.After(time.Millisecond):
case <-time.After(makeyTestDelay * time.Millisecond):
t.Errorf("MakeyButton was not halted")
}
}
@ -39,7 +39,7 @@ func TestMakeyButtonDriver(t *testing.T) {
gobottest.Assert(t, d.interval, 10*time.Millisecond)
d = NewMakeyButtonDriver(newGpioTestAdaptor(), "1", 30*time.Second)
gobottest.Assert(t, d.interval, MAKEY_TEST_DELAY*time.Second)
gobottest.Assert(t, d.interval, 30*time.Second)
}
func TestMakeyButtonDriverStart(t *testing.T) {
@ -49,51 +49,51 @@ func TestMakeyButtonDriverStart(t *testing.T) {
gobottest.Assert(t, d.Start(), nil)
a.TestAdaptorDigitalRead(func() (val int, err error) {
val = 0
return
})
d.Once(ButtonPush, func(data interface{}) {
gobottest.Assert(t, d.Active, true)
sem <- true
})
select {
case <-sem:
case <-time.After(MAKEY_TEST_DELAY * time.Millisecond):
t.Errorf("MakeyButton Event \"Push\" was not published")
}
a.TestAdaptorDigitalRead(func() (val int, err error) {
val = 1
val = 0
return
})
select {
case <-sem:
case <-time.After(makeyTestDelay * time.Millisecond):
t.Errorf("MakeyButton Event \"Push\" was not published")
}
d.Once(ButtonRelease, func(data interface{}) {
gobottest.Assert(t, d.Active, false)
sem <- true
})
select {
case <-sem:
case <-time.After(MAKEY_TEST_DELAY * time.Millisecond):
t.Errorf("MakeyButton Event \"Release\" was not published")
}
a.TestAdaptorDigitalRead(func() (val int, err error) {
err = errors.New("digital read error")
val = 1
return
})
select {
case <-sem:
case <-time.After(makeyTestDelay * time.Millisecond):
t.Errorf("MakeyButton Event \"Release\" was not published")
}
d.Once(Error, func(data interface{}) {
gobottest.Assert(t, data.(error).Error(), "digital read error")
sem <- true
})
a.TestAdaptorDigitalRead(func() (val int, err error) {
err = errors.New("digital read error")
return
})
select {
case <-sem:
case <-time.After(MAKEY_TEST_DELAY * time.Millisecond):
case <-time.After(makeyTestDelay * time.Millisecond):
t.Errorf("MakeyButton Event \"Error\" was not published")
}
@ -112,6 +112,6 @@ func TestMakeyButtonDriverStart(t *testing.T) {
select {
case <-sem:
t.Errorf("MakeyButton Event should not have been published")
case <-time.After(MAKEY_TEST_DELAY * time.Millisecond):
case <-time.After(makeyTestDelay * time.Millisecond):
}
}

View File

@ -12,7 +12,7 @@ import (
var _ gobot.Driver = (*PIRMotionDriver)(nil)
const MOTION_TEST_DELAY = 150
const motionTestDelay = 150
func initTestPIRMotionDriver() *PIRMotionDriver {
return NewPIRMotionDriver(newGpioTestAdaptor(), "1")
@ -53,7 +53,7 @@ func TestPIRMotionDriverStart(t *testing.T) {
select {
case <-sem:
case <-time.After(MOTION_TEST_DELAY * time.Millisecond):
case <-time.After(motionTestDelay * time.Millisecond):
t.Errorf("PIRMotionDriver Event \"MotionDetected\" was not published")
}
@ -69,22 +69,22 @@ func TestPIRMotionDriverStart(t *testing.T) {
select {
case <-sem:
case <-time.After(MOTION_TEST_DELAY * time.Millisecond):
case <-time.After(motionTestDelay * time.Millisecond):
t.Errorf("PIRMotionDriver Event \"MotionStopped\" was not published")
}
d.Once(Error, func(data interface{}) {
sem <- true
})
a.TestAdaptorDigitalRead(func() (val int, err error) {
err = errors.New("digital read error")
return
})
d.Once(Error, func(data interface{}) {
sem <- true
})
select {
case <-sem:
case <-time.After(MOTION_TEST_DELAY * time.Millisecond):
case <-time.After(motionTestDelay * time.Millisecond):
t.Errorf("PIRMotionDriver Event \"Error\" was not published")
}
}