diff --git a/platforms/sphero/ollie/ollie_driver_test.go b/platforms/sphero/ollie/ollie_driver_test.go index 3116d584..4da63a2e 100644 --- a/platforms/sphero/ollie/ollie_driver_test.go +++ b/platforms/sphero/ollie/ollie_driver_test.go @@ -50,7 +50,9 @@ func TestLocatorData(t *testing.T) { for _, point := range tables { // 0x0B is the locator ID - packet := []byte{0xFF, 0xFF, 0x00, 0x00, 0x0B, point.x1, point.x2, point.y1, point.y2, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} + packet := []byte{ + 0xFF, 0xFF, 0x00, 0x00, 0x0B, point.x1, point.x2, point.y1, point.y2, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + } d.GetLocatorData(func(p Point2D) { assert.Equal(t, point.y, p.Y) @@ -64,12 +66,12 @@ func TestDataStreaming(t *testing.T) { _ = d.SetDataStreamingConfig(sphero.DefaultDataStreamingConfig()) - response := false + responseChan := make(chan bool) _ = d.On("sensordata", func(data interface{}) { cont := data.(DataStreamingPacket) fmt.Printf("got streaming packet: %+v \n", cont) assert.Equal(t, int16(10), cont.RawAccX) - response = true + responseChan <- true }) // example data packet @@ -95,8 +97,9 @@ func TestDataStreaming(t *testing.T) { // send empty packet to indicate start of next message d.HandleResponses([]byte{0xFF}, nil) - time.Sleep(10 * time.Millisecond) - if response == false { + select { + case <-responseChan: + case <-time.After(10 * time.Millisecond): t.Error("no response received") } }