Skip to content

Commit 35bec19

Browse files
authored
[skip changelog] Change discoveries not starting when created (#1331)
1 parent 83d71c8 commit 35bec19

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

arduino/discovery/discovery.go

+14-6
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,6 @@ func New(id string, args ...string) (*PluggableDiscovery, error) {
8989
if err != nil {
9090
return nil, err
9191
}
92-
if err := proc.Start(); err != nil {
93-
return nil, err
94-
}
9592
messageChan := make(chan *discoveryMessage)
9693
disc := &PluggableDiscovery{
9794
id: id,
@@ -201,9 +198,20 @@ func (disc *PluggableDiscovery) sendCommand(command string) error {
201198
}
202199
}
203200

204-
// Hello sends the HELLO command to the discovery to agree on the pluggable discovery protocol. This
205-
// must be the first command to run in the communication with the discovery.
206-
func (disc *PluggableDiscovery) Hello() error {
201+
func (disc *PluggableDiscovery) runProcess() error {
202+
if err := disc.process.Start(); err != nil {
203+
return err
204+
}
205+
return nil
206+
}
207+
208+
// Run starts the discovery executable process and sends the HELLO command to the discovery to agree on the
209+
// pluggable discovery protocol. This must be the first command to run in the communication with the discovery.
210+
func (disc *PluggableDiscovery) Run() error {
211+
if err := disc.runProcess(); err != nil {
212+
return err
213+
}
214+
207215
if err := disc.sendCommand("HELLO 1 \"arduino-cli " + globals.VersionInfo.VersionString + "\"\n"); err != nil {
208216
return err
209217
}

arduino/discovery/discovery_test.go

+3
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ func TestDiscoveryStdioHandling(t *testing.T) {
3535
disc, err := New("test", "testdata/cat/cat") // copy stdin to stdout
3636
require.NoError(t, err)
3737

38+
err = disc.runProcess()
39+
require.NoError(t, err)
40+
3841
_, err = disc.outgoingCommandsPipe.Write([]byte(`{ "eventType":`)) // send partial JSON
3942
require.NoError(t, err)
4043
msg, err := disc.waitMessage(time.Millisecond * 100)

commands/bundled_tools_serial_discovery.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ func ListBoards(pm *packagemanager.PackageManager) ([]*discovery.Port, error) {
128128
}
129129
defer disc.Quit()
130130

131-
if err = disc.Hello(); err != nil {
131+
if err = disc.Run(); err != nil {
132132
return nil, fmt.Errorf("starting discovery: %v", err)
133133
}
134134

@@ -160,7 +160,7 @@ func WatchListBoards(pm *packagemanager.PackageManager) (<-chan *discovery.Event
160160
return nil, err
161161
}
162162

163-
if err = disc.Hello(); err != nil {
163+
if err = disc.Run(); err != nil {
164164
return nil, fmt.Errorf("starting discovery: %v", err)
165165
}
166166

0 commit comments

Comments
 (0)