@@ -27,6 +27,8 @@ import (
2727 "github.com/arduino/arduino-cli/internal/integrationtest"
2828 "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
2929 "github.com/arduino/go-paths-helper"
30+ "google.golang.org/grpc/codes"
31+ "google.golang.org/grpc/status"
3032
3133 "github.com/stretchr/testify/require"
3234)
@@ -54,28 +56,34 @@ func TestArduinoCliDaemon(t *testing.T) {
5456
5557 testWatcher := func () {
5658 // Run watcher
57- watcher , err := grpcInst .BoardListWatch ()
59+ ctx , cancel := context .WithCancel (context .TODO ())
60+ watcher , err := grpcInst .BoardListWatch (ctx )
5861 require .NoError (t , err )
59- ctx , cancel := context . WithCancel ( context . Background () )
62+ watcherCanceldCh := make ( chan struct {} )
6063 go func () {
61- defer cancel ()
6264 for {
6365 msg , err := watcher .Recv ()
6466 if err == io .EOF {
6567 fmt .Println ("Watcher EOF" )
6668 return
6769 }
68- require .Empty (t , msg .Error , "Board list watcher returned an error" )
70+ if s , ok := status .FromError (err ); ok && s .Code () == codes .Canceled {
71+ fmt .Println ("Watcher canceled" )
72+ watcherCanceldCh <- struct {}{}
73+ return
74+ }
6975 require .NoError (t , err , "BoardListWatch grpc call returned an error" )
70- fmt .Printf ("WATCH> %v\n " , msg )
76+ require .Empty (t , msg .Error , "Board list watcher returned an error" )
77+ fmt .Printf ("WATCH> %v %v\n " , msg , err )
7178 }
7279 }()
7380 time .Sleep (time .Second )
74- require .NoError (t , watcher .CloseSend ())
81+ cancel ()
82+ time .Sleep (time .Second )
7583 select {
76- case <- ctx . Done () :
84+ case <- watcherCanceldCh :
7785 // all right!
78- case <- time .After (time .Second ):
86+ case <- time .After (2 * time .Second ):
7987 require .Fail (t , "BoardListWatch didn't close" )
8088 }
8189 }
0 commit comments