diff --git a/.travis.yml b/.travis.yml index 86a5c4414..0ca059c4f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,10 +1,14 @@ language: go +sudo: true go: - 1.2 - 1.3 - 1.4 - release - tip +matrix: + allow_failures: + - go: tip before_install: - sudo add-apt-repository -y ppa:kubuntu-ppa/backports - sudo add-apt-repository -y ppa:zoogie/sdl2-snapshots diff --git a/platforms/firmata/client/client_test.go b/platforms/firmata/client/client_test.go index e2d08ff39..c1688bd5f 100644 --- a/platforms/firmata/client/client_test.go +++ b/platforms/firmata/client/client_test.go @@ -190,27 +190,29 @@ func TestProcess(t *testing.T) { func TestConnect(t *testing.T) { b := New() - testReadData = testProtocolResponse() + response := testProtocolResponse() + + go func() { + for { + testReadData = append(testReadData, response...) + <-time.After(100 * time.Millisecond) + } + }() gobot.Once(b.Event("ProtocolVersion"), func(data interface{}) { - <-time.After(1 * time.Millisecond) - testReadData = testFirmwareResponse() + response = testFirmwareResponse() }) gobot.Once(b.Event("FirmwareQuery"), func(data interface{}) { - <-time.After(1 * time.Millisecond) - testReadData = testCapabilitiesResponse() + response = testCapabilitiesResponse() }) gobot.Once(b.Event("CapabilityQuery"), func(data interface{}) { - <-time.After(1 * time.Millisecond) - testReadData = testAnalogMappingResponse() + response = testAnalogMappingResponse() }) gobot.Once(b.Event("AnalogMappingQuery"), func(data interface{}) { - - <-time.After(1 * time.Millisecond) - testReadData = testProtocolResponse() + response = testProtocolResponse() }) gobot.Assert(t, b.Connect(readWriteCloser{}), nil) diff --git a/platforms/gpio/analog_sensor_driver_test.go b/platforms/gpio/analog_sensor_driver_test.go index f4876d34e..7d4ef5a21 100644 --- a/platforms/gpio/analog_sensor_driver_test.go +++ b/platforms/gpio/analog_sensor_driver_test.go @@ -31,8 +31,13 @@ func TestAnalogSensorDriverStart(t *testing.T) { d := NewAnalogSensorDriver(newGpioTestAdaptor("adaptor"), "bot", "1") + testAdaptorAnalogRead = func() (val int, err error) { + val = 0 + return + } gobot.Assert(t, len(d.Start()), 0) + // data was received gobot.Once(d.Event(Data), func(data interface{}) { gobot.Assert(t, data.(int), 100) sem <- true @@ -45,10 +50,11 @@ func TestAnalogSensorDriverStart(t *testing.T) { select { case <-sem: - case <-time.After(15 * time.Millisecond): + case <-time.After(10 * time.Second): t.Errorf("AnalogSensor Event \"Data\" was not published") } + // read error gobot.Once(d.Event(Error), func(data interface{}) { gobot.Assert(t, data.(error).Error(), "read error") sem <- true @@ -61,10 +67,11 @@ func TestAnalogSensorDriverStart(t *testing.T) { select { case <-sem: - case <-time.After(15 * time.Millisecond): + case <-time.After(10 * time.Second): t.Errorf("AnalogSensor Event \"Error\" was not published") } + // send a halt message gobot.Once(d.Event(Data), func(data interface{}) { sem <- true }) @@ -79,7 +86,7 @@ func TestAnalogSensorDriverStart(t *testing.T) { select { case <-sem: t.Errorf("AnalogSensor Event should not published") - case <-time.After(30 * time.Millisecond): + case <-time.After(100 * time.Millisecond): } } diff --git a/platforms/i2c/wiichuck_driver_test.go b/platforms/i2c/wiichuck_driver_test.go index bcc9feec3..89ceab66e 100644 --- a/platforms/i2c/wiichuck_driver_test.go +++ b/platforms/i2c/wiichuck_driver_test.go @@ -99,21 +99,29 @@ func TestWiichuckDriverUpdate(t *testing.T) { gobot.Assert(t, data, true) chann <- true }) - <-chann - chann = make(chan bool) wii.update(decryptedValue) + select { + case <-chann: + case <-time.After(10 * time.Second): + t.Errorf("Did not recieve 'C' event") + } + gobot.On(wii.Event(Z), func(data interface{}) { gobot.Assert(t, data, true) chann <- true }) - <-chann - // - This should be done by WiichuckDriver.updateJoystick - chann = make(chan bool) wii.update(decryptedValue) + select { + case <-chann: + case <-time.After(10 * time.Second): + t.Errorf("Did not recieve 'Z' event") + } + + // - This should be done by WiichuckDriver.updateJoystick expectedData := map[string]float64{ "x": float64(0), "y": float64(0), @@ -123,7 +131,14 @@ func TestWiichuckDriverUpdate(t *testing.T) { gobot.Assert(t, data, expectedData) chann <- true }) - <-chann + + wii.update(decryptedValue) + + select { + case <-chann: + case <-time.After(10 * time.Second): + t.Errorf("Did not recieve 'Joystick' event") + } // ------ When value is encrypted wii = initTestWiichuckDriver() @@ -249,27 +264,36 @@ func TestWiichuckDriverUpdateButtons(t *testing.T) { wii.data["c"] = 0 - wii.updateButtons() - gobot.On(wii.Event(C), func(data interface{}) { gobot.Assert(t, true, data) chann <- true }) - <-chann + + wii.updateButtons() + + select { + case <-chann: + case <-time.After(10 * time.Second): + t.Errorf("Did not recieve 'C' event") + } //when data["z"] is 0 - chann = make(chan bool) wii = initTestWiichuckDriver() wii.data["z"] = 0 - wii.updateButtons() - gobot.On(wii.Event(Z), func(data interface{}) { gobot.Assert(t, true, data) chann <- true }) - <-chann + + wii.updateButtons() + + select { + case <-chann: + case <-time.After(10 * time.Second): + t.Errorf("Did not recieve 'Z' event") + } } func TestWiichuckDriverUpdateJoystick(t *testing.T) { @@ -282,8 +306,6 @@ func TestWiichuckDriverUpdateJoystick(t *testing.T) { wii.joystick["sx_origin"] = 1 wii.joystick["sy_origin"] = 5 - wii.updateJoystick() - expectedData := map[string]float64{ "x": float64(39), "y": float64(50), @@ -293,10 +315,16 @@ func TestWiichuckDriverUpdateJoystick(t *testing.T) { gobot.Assert(t, data, expectedData) chann <- true }) - <-chann + + wii.updateJoystick() + + select { + case <-chann: + case <-time.After(10 * time.Second): + t.Errorf("Did not recieve 'Joystick' event") + } //// Second pass - chann = make(chan bool) wii = initTestWiichuckDriver() wii.data["sx"] = 178 @@ -304,8 +332,6 @@ func TestWiichuckDriverUpdateJoystick(t *testing.T) { wii.joystick["sx_origin"] = 14 wii.joystick["sy_origin"] = 27 - wii.updateJoystick() - expectedData = map[string]float64{ "x": float64(164), "y": float64(7), @@ -315,5 +341,12 @@ func TestWiichuckDriverUpdateJoystick(t *testing.T) { gobot.Assert(t, data, expectedData) chann <- true }) - <-chann + + wii.updateJoystick() + + select { + case <-chann: + case <-time.After(10 * time.Second): + t.Errorf("Did not recieve 'Joystick' event") + } } diff --git a/platforms/joystick/joystick_driver_test.go b/platforms/joystick/joystick_driver_test.go index d2814ca43..3b6a1a41a 100644 --- a/platforms/joystick/joystick_driver_test.go +++ b/platforms/joystick/joystick_driver_test.go @@ -41,53 +41,65 @@ func TestJoystickDriverHandleEvent(t *testing.T) { sem := make(chan bool) d := initTestJoystickDriver() d.Start() + + // left x stick + gobot.On(d.Event("left_x"), func(data interface{}) { + gobot.Assert(t, int16(100), data.(int16)) + sem <- true + }) d.handleEvent(&sdl.JoyAxisEvent{ Which: 0, Axis: 0, Value: 100, }) - gobot.On(d.Event("left_x"), func(data interface{}) { - gobot.Assert(t, int16(100), data.(int16)) + select { + case <-sem: + case <-time.After(10 * time.Second): + t.Errorf("Button Event \"left_x\" was not published") + } + + // x button press + gobot.On(d.Event("x_press"), func(data interface{}) { sem <- true }) - <-sem d.handleEvent(&sdl.JoyButtonEvent{ Which: 0, Button: 2, State: 1, }) - gobot.On(d.Event("x_press"), func(data interface{}) { - sem <- true - }) select { case <-sem: - case <-time.After(10 * time.Millisecond): + case <-time.After(10 * time.Second): t.Errorf("Button Event \"x_press\" was not published") } + + // x button release + gobot.On(d.Event("x_release"), func(data interface{}) { + sem <- true + }) d.handleEvent(&sdl.JoyButtonEvent{ Which: 0, Button: 2, State: 0, }) - gobot.On(d.Event("x_release"), func(data interface{}) { - sem <- true - }) select { case <-sem: - case <-time.After(10 * time.Millisecond): + case <-time.After(10 * time.Second): t.Errorf("Button Event \"x_release\" was not published") } + + // down button press + gobot.On(d.Event("down"), func(data interface{}) { + sem <- true + }) d.handleEvent(&sdl.JoyHatEvent{ Which: 0, Hat: 0, Value: 4, }) - gobot.On(d.Event("down"), func(data interface{}) { - sem <- true - }) select { case <-sem: - case <-time.After(10 * time.Millisecond): + case <-time.After(10 * time.Second): t.Errorf("Hat Event \"down\" was not published") } diff --git a/platforms/spark/spark_core_adaptor_test.go b/platforms/spark/spark_core_adaptor_test.go index e0b2b5fea..b4b748d1e 100644 --- a/platforms/spark/spark_core_adaptor_test.go +++ b/platforms/spark/spark_core_adaptor_test.go @@ -6,6 +6,7 @@ import ( "net/http/httptest" "net/url" "testing" + "time" "github.com/donovanhide/eventsource" "github.com/hybridgroup/gobot" @@ -378,8 +379,7 @@ func TestSparkCoreAdaptorEventStream(t *testing.T) { stream, err := a.EventStream("devices", "") gobot.Assert(t, err, nil) - eventChan <- testEventSource{event: "event", data: "sse event"} - + // stream message gobot.Once(stream, func(data interface{}) { e := data.(Event) gobot.Assert(t, e.Name, "event") @@ -388,10 +388,15 @@ func TestSparkCoreAdaptorEventStream(t *testing.T) { sem <- true }) - <-sem + eventChan <- testEventSource{event: "event", data: "sse event"} - errorChan <- errors.New("stream error") + select { + case <-sem: + case <-time.After(1 * time.Second): + t.Errorf("Did not recieve stream") + } + // stream error gobot.Once(stream, func(data interface{}) { e := data.(Event) gobot.Assert(t, e.Name, "") @@ -400,6 +405,12 @@ func TestSparkCoreAdaptorEventStream(t *testing.T) { sem <- true }) - <-sem + errorChan <- errors.New("stream error") + + select { + case <-sem: + case <-time.After(1 * time.Second): + t.Errorf("Did not recieve stream error") + } }