ollie(test): fix data race in test (#1034)

This commit is contained in:
Thomas Kohler 2023-11-11 19:55:47 +01:00 committed by GitHub
parent 04fa579371
commit 88a0c7af2b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 5 deletions

View File

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