@@ -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)
@@ -52,28 +54,34 @@ func TestArduinoCliDaemon(t *testing.T) {
5254 require .NoError (t , err )
5355 fmt .Printf ("Got boardlist response with %d ports\n " , len (boardListResp .GetPorts ()))
5456
57+ // When the client closes the connection we expect that the streaming from the server closes.
5558 testWatcher := func () {
5659 // Run watcher
57- watcher , err := grpcInst .BoardListWatch ()
58- require .NoError (t , err )
5960 ctx , cancel := context .WithCancel (context .Background ())
61+ watcher , err := grpcInst .BoardListWatch (ctx )
62+ require .NoError (t , err )
63+ watcherCanceldCh := make (chan struct {})
6064 go func () {
61- defer cancel ()
6265 for {
6366 msg , err := watcher .Recv ()
6467 if err == io .EOF {
6568 fmt .Println ("Watcher EOF" )
6669 return
6770 }
68- require .Empty (t , msg .Error , "Board list watcher returned an error" )
71+ if s , ok := status .FromError (err ); ok && s .Code () == codes .Canceled {
72+ fmt .Println ("Watcher canceled" )
73+ watcherCanceldCh <- struct {}{}
74+ return
75+ }
6976 require .NoError (t , err , "BoardListWatch grpc call returned an error" )
70- fmt .Printf ("WATCH> %v\n " , msg )
77+ require .Empty (t , msg .Error , "Board list watcher returned an error" )
78+ fmt .Printf ("WATCH> %v %v\n " , msg , err )
7179 }
7280 }()
7381 time .Sleep (time .Second )
74- require . NoError ( t , watcher . CloseSend () )
82+ cancel ( )
7583 select {
76- case <- ctx . Done () :
84+ case <- watcherCanceldCh :
7785 // all right!
7886 case <- time .After (time .Second ):
7987 require .Fail (t , "BoardListWatch didn't close" )
0 commit comments