8000 [breaking] `core update-index` do not stop at the first download error by cmaglie · Pull Request #1866 · arduino/arduino-cli · GitHub
[go: up one dir, main page]

Skip to content

[breaking] core update-index do not stop at the first download error #1866

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 7 commits into from
Sep 9, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
UpdateIndex: Fixed a wrong success report and added test.
  • Loading branch information
cmaglie committed Sep 7, 2022
commit 84642efadbd9cc80858cba1bd6d910e56d88f751
1 change: 1 addition & 0 deletions commands/instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,7 @@ func UpdateIndex(ctx context.Context, req *rpc.UpdateIndexRequest, downloadCB rp
Error: err.Error(),
})
failed = true
continue
}

downloadResultCB(&rpc.DownloadResult{
Expand Down
11 changes: 11 additions & 0 deletions internal/integrationtest/arduino-cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,3 +367,14 @@ func (inst *ArduinoCLIInstance) LibraryUninstall(ctx context.Context, name, vers
logCallf(">>> LibraryUninstall(%+v)\n", req)
return installCl, err
}

// UpdateIndex calls the "UpdateIndex" gRPC method.
func (inst *ArduinoCLIInstance) UpdateIndex(ctx context.Context, ignoreCustomPackages bool) (commands.ArduinoCoreService_UpdateIndexClient, error) {
req := &commands.UpdateIndexRequest{
Instance: inst.instance,
IgnoreCustomPackageIndexes: ignoreCustomPackages,
}
updCl, err := inst.cli.daemonClient.UpdateIndex(ctx, req)
logCallf(">>> UpdateIndex(%+v)\n", req)
return updCl, err
}
99 changes: 99 additions & 0 deletions internal/integrationtest/daemon/daemon_core_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
// This file is part of arduino-cli.
//
// Copyright 2022 ARDUINO SA (http://www.arduino.cc/)
//
// This software is released under the GNU General Public License version 3,
// which covers the main part of arduino-cli.
// The terms of this license can be found at:
// https://www.gnu.org/licenses/gpl-3.0.en.html
//
// You can be released from the requirements of the above licenses by purchasing
// a commercial license. Buying such a license is mandatory if you want to
// modify or otherwise use the software for commercial activities involving the
// Arduino software without disclosing the source code of your own applications.
// To purchase a commercial license, send an email to license@arduino.cc.

package daemon_test

import (
"context"
"fmt"
"io"
"testing"

"github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
"github.com/stretchr/testify/require"
)

func TestDaemonCoreUpdateIndex(t *testing.T) {
env, cli := createEnvForDaemon(t)
defer env.CleanUp()

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

// Set extra indexes
err := cli.SetValue(
"board_manager.additional_urls", ""+
`["http://arduino.esp8266.com/stable/package_esp8266com_index.json",`+
` "http://downloads.arduino.cc/package_inexistent_index.json"]`)
require.NoError(t, err)

{
cl, err := grpcInst.UpdateIndex(context.Background(), true)
require.NoError(t, err)
res, err := analyzeUpdateIndexStream(t, cl)
require.NoError(t, err)
require.Len(t, res, 1)
require.True(t, res["https://downloads.arduino.cc/packages/package_index.tar.bz2"].Successful)
}
{
cl, err := grpcInst.UpdateIndex(context.Background(), false)
require.NoError(t, err)
res, err := analyzeUpdateIndexStream(t, cl)
require.Error(t, err)
require.Len(t, res, 3)
require.True(t, res["https://downloads.arduino.cc/packages/package_index.tar.bz2"].Successful)
require.True(t, res["http://arduino.esp8266.com/stable/package_esp8266com_index.json"].Successful)
require.False(t, res["http://downloads.arduino.cc/package_inexistent_index.json"].Successful)
}
}

// analyzeUpdateIndexStream runs an update index checking if the sequence of DownloadProgress and
// DownloadResult messages is correct. It returns a map reporting all the DownloadResults messages
// received (it maps urls to DownloadResults).
func analyzeUpdateIndexStream(t *testing.T, cl commands.ArduinoCoreService_UpdateIndexClient) (map[string]*commands.DownloadResult, error) {
ongoingDownload := ""
results := map[string]*commands.DownloadResult{}
for {
msg, err := cl.Recv()
if err == io.EOF {
return results, nil
}
if err != nil {
return results, err
}
require.NoError(t, err)
fmt.Printf("UPDATE> %+v\n", msg)
if progress := msg.GetDownloadProgress(); progress != nil {
if progress.Url != "" && progress.Url != ongoingDownload {
require.Empty(t, ongoingDownload, "DownloadProgress: initiated a new download with closing the previous one")
ongoingDownload = progress.Url
}
if progress.Completed {
require.NotEmpty(t, ongoingDownload, "DownloadProgress: sent a 'completed' download message without starting it")
ongoingDownload = ""
}
if progress.Downloaded > 0 {
require.NotEmpty(t, ongoingDownload, "DownloadProgress: sent an update but never initiated a download")
}
} else if result := msg.GetDownloadResult(); result != nil {
require.Empty(t, ongoingDownload, "DownloadResult: got a download result with closing it first")
results[result.Url] = result
} else {
require.FailNow(t, "DownloadProgress: received a message without a Progress or a Result")
}
}
}
0