Skip to content

Fixed invalid gRPC TaskProgress message on compile #2731

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 2 commits into from
Oct 14, 2024
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
5 changes: 2 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
module github.com/arduino/arduino-cli

go 1.22

toolchain go1.22.3
go 1.22.3

// We must use this fork until https://github.com/mailru/easyjson/pull/372 is merged
replace github.com/mailru/easyjson => github.com/cmaglie/easyjson v0.8.1
Expand Down Expand Up @@ -38,6 +36,7 @@ require (
github.com/xeipuuv/gojsonschema v1.2.0
go.bug.st/cleanup v1.0.0
go.bug.st/downloader/v2 v2.2.0
go.bug.st/f v0.4.0
go.bug.st/relaxed-semver v0.12.0
go.bug.st/testifyjson v1.2.0
golang.org/x/term v0.25.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,8 @@ go.bug.st/cleanup v1.0.0 h1:XVj1HZxkBXeq3gMT7ijWUpHyIC1j8XAoNSyQ06CskgA=
go.bug.st/cleanup v1.0.0/go.mod h1:EqVmTg2IBk4znLbPD28xne3abjsJftMdqqJEjhn70bk=
go.bug.st/downloader/v2 v2.2.0 h1:Y0jSuDISNhrzePkrAWqz9xUC3xol9hqZo/+tz1D4EqY=
go.bug.st/downloader/v2 v2.2.0/go.mod h1:VZW2V1iGKV8rJL2ZEGIDzzBeKowYv34AedJz13RzVII=
go.bug.st/f v0.4.0 h1:Vstqb950nMA+PhAlRxUw8QL1ntHy/gXHNyyzjkQLJ10=
go.bug.st/f v0.4.0/go.mod h1:bMo23205ll7UW63KwO1ut5RdlJ9JK8RyEEr88CmOF5Y=
go.bug.st/relaxed-semver v0.12.0 h1:se8v3lTdAAFp68+/RS/0Y/nFdnpdzkP5ICY04SPau4E=
go.bug.st/relaxed-semver v0.12.0/go.mod h1:Cpcbiig6Omwlq6bS7i3MQWiqS7W7HDd8CAnZFC40Cl0=
go.bug.st/serial v1.6.1 h1:VSSWmUxlj1T/YlRo2J104Zv3wJFrjHIl/T3NeruWAHY=
Expand Down
10 changes: 4 additions & 6 deletions internal/arduino/builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,10 @@ func (b *Builder) logIfVerbose(warn bool, msg string) {

// Build fixdoc
func (b *Builder) Build() error {
b.Progress.AddSubSteps(6 /** preprocess **/ + 21 /** build **/)
b.Progress.AddSubSteps(6 + // preprocess
18 + // build
1, // size
)
defer b.Progress.RemoveSubSteps()

if err := b.preprocess(); err != nil {
Expand All @@ -362,15 +365,10 @@ func (b *Builder) Build() error {
buildErr := b.build()

b.libsDetector.PrintUsedAndNotUsedLibraries(buildErr != nil)
b.Progress.CompleteStep()

b.printUsedLibraries(b.libsDetector.ImportedLibraries())
b.Progress.CompleteStep()

if buildErr != nil {
return buildErr
}
b.Progress.CompleteStep()

if err := b.size(); err != nil {
return err
Expand Down
13 changes: 7 additions & 6 deletions internal/integrationtest/daemon/daemon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"time"

"github.com/arduino/arduino-cli/commands/cmderrors"
f "github.com/arduino/arduino-cli/internal/algorithms"
"github.com/arduino/arduino-cli/internal/integrationtest"
"github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
"github.com/arduino/go-paths-helper"
Expand Down Expand Up @@ -194,13 +193,15 @@ func TestDaemonCompileOptions(t *testing.T) {
if msg.GetErrStream() != nil {
fmt.Printf("COMPILE> %v\n", string(msg.GetErrStream()))
}
analyzer.Process(msg.GetProgress())
if pr := msg.GetProgress(); pr != nil {
fmt.Printf("COMPILE PROGRESS> %v\n", pr)
analyzer.Process(pr)
}
}

// https://github.com/arduino/arduino-cli/issues/2016
// assert that the task progress is increasing and doesn't contain multiple 100% values
results := analyzer.Results[""]
require.True(t, results[len(results)-1].GetCompleted(), fmt.Sprintf("latest percent value: %v", results[len(results)-1].GetPercent()))
require.IsNonDecreasing(t, f.Map(results, (*commands.TaskProgress).GetPercent))
// https://github.com/arduino/arduino-cli/issues/2711
analyzer.Check(t)
}

func TestDaemonCompileAfterFailedLibInstall(t *testing.T) {
Expand Down
12 changes: 12 additions & 0 deletions internal/integrationtest/daemon/task_progress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import (
"testing"

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

// TaskProgressAnalyzer analyzes TaskProgress messages for consistency
Expand All @@ -44,3 +46,13 @@ func (a *TaskProgressAnalyzer) Process(progress *commands.TaskProgress) {
taskName := progress.GetName()
a.Results[taskName] = append(a.Results[taskName], progress)
}

func (a *TaskProgressAnalyzer) Check(t *testing.T) {
for task, results := range a.Results {
require.Equal(t, 1, f.Count(results, (*commands.TaskProgress).GetCompleted), "Got multiple 'completed' messages on task %s", task)
l := len(results)
require.True(t, results[l-1].GetCompleted(), "Last message is not 'completed' on task: %s", task)
require.Equal(t, results[l-1].GetPercent(), float32(100), "Last message is not 100% on task: %s", task)
require.IsNonDecreasing(t, f.Map(results, (*commands.TaskProgress).GetPercent), "Percentages are not increasing on task: %s", task)
}
}
Loading