Skip to content

Commit

Permalink
Dji Tello Halt does not terminate all the related goroutines and may …
Browse files Browse the repository at this point in the history
…wait forever when it is called multiple times

Add failing unit tests.
  • Loading branch information
st-user authored and deadprogram committed Sep 26, 2022
1 parent 5bbcfec commit 3c8f48a
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions platforms/dji/tello/driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/binary"
"fmt"
"io"
"sync"
"testing"
"time"

Expand All @@ -14,6 +15,15 @@ import (

var _ gobot.Driver = (*Driver)(nil)

type WriteCloserDoNothing struct{}

func (w *WriteCloserDoNothing) Write(p []byte) (n int, err error) {
return 0, nil
}
func (w *WriteCloserDoNothing) Close() error {
return nil
}

func TestTelloDriver(t *testing.T) {
d := NewDriver("8888")

Expand Down Expand Up @@ -134,3 +144,38 @@ func TestHandleResponse(t *testing.T) {
})
}
}

func TestHaltShouldTerminateAllTheRelatedGoroutines(t *testing.T) {
d := NewDriver("8888")
d.cmdConn = &WriteCloserDoNothing{}

var wg sync.WaitGroup
wg.Add(3)
go func() {
<-d.doneCh
wg.Done()
fmt.Println("Done routine 1.")
}()
go func() {
<-d.doneCh
wg.Done()
fmt.Println("Done routine 2.")
}()
go func() {
<-d.doneCh
wg.Done()
fmt.Println("Done routine 3.")
}()

d.Halt()
wg.Wait()
}

func TestHaltNotWaitForeverWhenCalledMultipleTimes(t *testing.T) {
d := NewDriver("8888")
d.cmdConn = &WriteCloserDoNothing{}

d.Halt()
d.Halt()
d.Halt()
}

0 comments on commit 3c8f48a

Please sign in to comment.