+55
-2
lines changedFilter options
+55
-2
lines changed Original file line number Diff line number Diff line change
@@ -125,8 +125,8 @@ func (s *arduinoCoreServerImpl) Monitor(stream rpc.ArduinoCoreService_MonitorSer
125
125
if err != nil {
126
126
return err
127
127
}
128
-
defer release()
129
128
monitor, boardSettings, err := findMonitorAndSettingsForProtocolAndBoard(pme, openReq.GetPort().GetProtocol(), openReq.GetFqbn())
129
+
release()
130
130
if err != nil {
131
131
return err
132
132
}
Original file line number Diff line number Diff line change
@@ -35,7 +35,6 @@ import (
35
35
)
36
36
37
37
var (
38
-
tr = i18n.Tr
39
38
daemonize bool
40
39
debug bool
41
40
debugFile string
Original file line number Diff line number Diff line change
@@ -20,6 +20,7 @@ import (
20
20
"errors"
21
21
"fmt"
22
22
"io"
23
+
"sync"
23
24
"testing"
24
25
"time"
25
26
@@ -76,3 +77,56 @@ func TestArduinoCliDaemonCompileWithLotOfOutput(t *testing.T) {
76
77
testCompile()
77
78
testCompile()
78
79
}
80
+
81
+
func TestInitAndMonitorConcurrency(t *testing.T) {
82
+
// See: https://github.com/arduino/arduino-cli/issues/2719
83
+
84
+
env, cli := integrationtest.CreateEnvForDaemon(t)
85
+
defer env.CleanUp()
86
+
87
+
_, _, err := cli.Run("core", "install", "arduino:avr")
88
+
require.NoError(t, err)
89
+
90
+
grpcInst := cli.Create()
91
+
require.NoError(t, grpcInst.Init("", "", func(ir *commands.InitResponse) {
92
+
fmt.Printf("INIT> %v\n", ir.GetMessage())
93
+
}))
94
+
95
+
cli.InstallMockedSerialMonitor(t)
96
+
97
+
// Open the serial monitor for 5 seconds
98
+
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
99
+
defer cancel()
100
+
mon, err := grpcInst.Monitor(ctx, &commands.Port{
101
+
Address: "/dev/test",
102
+
Protocol: "serial",
103
+
})
104
+
require.NoError(t, err)
105
+
var monitorCompleted sync.WaitGroup
106
+
monitorCompleted.Add(1)
107
+
go func() {
108
+
for {
109
+
msg, err := mon.Recv()
110
+
if err != nil {
111
+
break
112
+
}
113
+
fmt.Println("MON> ", msg)
114
+
}
115
+
fmt.Println("MON CLOSED")
116
+
monitorCompleted.Done()
117
+
}()
118
+
119
+
// Check that Init completes without blocking when the monitor is open
120
+
start := time.Now()
121
+
require.NoError(t, grpcInst.Init("", "", func(ir *commands.InitResponse) {
122
+
fmt.Printf("INIT> %v\n", ir.GetMessage())
123
+
}))
124
+
require.LessOrEqual(t, time.Since(start), 4*time.Second)
125
+
cancel()
126
+
monitorCompleted.Wait()
127
+
128
+
// Allow some time for the mocked-monitor process to terminate (otherwise the
129
+
// test will fail on Windows when the cleanup function tries to remove the
130
+
// executable).
131
+
time.Sleep(2 * time.Second)
132
+
}
You can’t perform that action at this time.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4