Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion commands/service_monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ func (s *arduinoCoreServerImpl) Monitor(stream rpc.ArduinoCoreService_MonitorSer
if err != nil {
return err
}
defer release()
monitor, boardSettings, err := findMonitorAndSettingsForProtocolAndBoard(pme, openReq.GetPort().GetProtocol(), openReq.GetFqbn())
release()
if err != nil {
return err
}
Expand Down
1 change: 0 additions & 1 deletion internal/cli/daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import (
)

var (
tr = i18n.Tr
daemonize bool
debug bool
debugFile string
Expand Down
49 changes: 49 additions & 0 deletions internal/integrationtest/daemon/daemon_concurrency_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"errors"
"fmt"
"io"
"sync"
"testing"
"time"

Expand Down Expand Up @@ -76,3 +77,51 @@ func TestArduinoCliDaemonCompileWithLotOfOutput(t *testing.T) {
testCompile()
testCompile()
}

func TestInitAndMonitorConcurrency(t *testing.T) {
// See: https://github.com/arduino/arduino-cli/issues/2719

env, cli := integrationtest.CreateEnvForDaemon(t)
defer env.CleanUp()

_, _, err := cli.Run("core", "install", "arduino:avr")
require.NoError(t, err)

grpcInst := cli.Create()
require.NoError(t, grpcInst.Init("", "", func(ir *commands.InitResponse) {
fmt.Printf("INIT> %v\n", ir.GetMessage())
}))

cli.InstallMockedSerialMonitor(t)

// Open the serial monitor for 5 seconds
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
mon, err := grpcInst.Monitor(ctx, &commands.Port{
Address: "/dev/test",
Protocol: "serial",
})
require.NoError(t, err)
var monitorCompleted sync.WaitGroup
monitorCompleted.Add(1)
go func() {
for {
msg, err := mon.Recv()
if err != nil {
break
}
fmt.Println("MON> ", msg)
}
fmt.Println("MON CLOSED")
monitorCompleted.Done()
}()

// Check that Init completes without blocking when the monitor is open
start := time.Now()
require.NoError(t, grpcInst.Init("", "", func(ir *commands.InitResponse) {
fmt.Printf("INIT> %v\n", ir.GetMessage())
}))
require.LessOrEqual(t, time.Since(start), 4*time.Second)
cancel()
monitorCompleted.Wait()
}
Loading