Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Nov 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions platforms/sphero/ollie/ollie_driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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")
}
}