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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions arduino/discovery/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,29 +247,32 @@ func (disc *PluggableDiscovery) runProcess() error {
return err
}
disc.outgoingCommandsPipe = stdin
disc.process = proc

messageChan := make(chan *discoveryMessage)
disc.incomingMessagesChan = messageChan
go disc.jsonDecodeLoop(stdout, messageChan)

if err := disc.process.Start(); err != nil {
if err := proc.Start(); err != nil {
return err
}

disc.statusMutex.Lock()
defer disc.statusMutex.Unlock()
disc.process = proc
disc.state = Alive
logrus.Infof("started discovery %s process", disc.id)
return nil
}

func (disc *PluggableDiscovery) killProcess() error {
logrus.Infof("killing discovery %s process", disc.id)
if err := disc.process.Kill(); err != nil {
return err
}
if err := disc.process.Wait(); err != nil {
return err
if disc.process != nil {
if err := disc.process.Kill(); err != nil {
return err
}
if err := disc.process.Wait(); err != nil {
return err
}
}
disc.statusMutex.Lock()
defer disc.statusMutex.Unlock()
Expand Down
19 changes: 19 additions & 0 deletions test/test_board.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
# a commercial license, send an email to license@arduino.cc.
from pathlib import Path
from git import Repo
import os
import glob
import simplejson as json
import semver
import pytest
Expand Down Expand Up @@ -405,6 +407,23 @@ def test_board_list(run_command):
assert "protocol_label" in port["port"]


def test_board_list_with_invalid_discovery(run_command, data_dir):
run_command(["core", "update-index"])
result = run_command(["board", "list"])
assert result.ok

# check that the CLI do no crash if an invalid discovery is installed
# (for example if the installation fails midway).
# https://github.com/arduino/arduino-cli/issues/1669
tool_dir = os.path.join(data_dir, "packages", "builtin", "tools", "serial-discovery")
for file_to_delete in glob.glob(tool_dir + "/*/*"):
os.remove(file_to_delete)

result = run_command(["board", "list"])
assert result.ok
assert "builtin:serial-discovery" in result.stderr


def test_board_listall(run_command):
assert run_command(["update"])
assert run_command(["core", "install", "arduino:avr@1.8.3"])
Expand Down