Skip to content

[skip changelog] Change discoveries not starting when created #1331

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 23, 2021
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
20 changes: 14 additions & 6 deletions arduino/discovery/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,6 @@ func New(id string, args ...string) (*PluggableDiscovery, error) {
if err != nil {
return nil, err
}
if err := proc.Start(); err != nil {
return nil, err
}
messageChan := make(chan *discoveryMessage)
disc := &PluggableDiscovery{
id: id,
Expand Down Expand Up @@ -201,9 +198,20 @@ func (disc *PluggableDiscovery) sendCommand(command string) error {
}
}

// Hello sends the HELLO command to the discovery to agree on the pluggable discovery protocol. This
// must be the first command to run in the communication with the discovery.
func (disc *PluggableDiscovery) Hello() error {
func (disc *PluggableDiscovery) runProcess() error {
if err := disc.process.Start(); err != nil {
return err
}
return nil
}

// Run starts the discovery executable process and sends the HELLO command to the discovery to agree on the
// pluggable discovery protocol. This must be the first command to run in the communication with the discovery.
func (disc *PluggableDiscovery) Run() error {
if err := disc.runProcess(); err != nil {
return err
}

if err := disc.sendCommand("HELLO 1 \"arduino-cli " + globals.VersionInfo.VersionString + "\"\n"); err != nil {
return err
}
Expand Down
3 changes: 3 additions & 0 deletions arduino/discovery/discovery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ func TestDiscoveryStdioHandling(t *testing.T) {
disc, err := New("test", "testdata/cat/cat") // copy stdin to stdout
require.NoError(t, err)

err = disc.runProcess()
require.NoError(t, err)

_, err = disc.outgoingCommandsPipe.Write([]byte(`{ "eventType":`)) // send partial JSON
require.NoError(t, err)
msg, err := disc.waitMessage(time.Millisecond * 100)
Expand Down
4 changes: 2 additions & 2 deletions commands/bundled_tools_serial_discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func ListBoards(pm *packagemanager.PackageManager) ([]*discovery.Port, error) {
}
defer disc.Quit()

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

Expand Down Expand Up @@ -160,7 +160,7 @@ func WatchListBoards(pm *packagemanager.PackageManager) (<-chan *discovery.Event
return nil, err
}

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

Expand Down