Skip to content

Commit

Permalink
Fixed invalid gRPC TaskProgress message on compile (#2731)
Browse files Browse the repository at this point in the history
* Fixed TaskProgress test

* Fixed invalid gRPC TaskProgress message on compile
  • Loading branch information
cmaglie authored Oct 14, 2024
1 parent 0540cee commit d2cd387
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 15 deletions.
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)
}
}

0 comments on commit d2cd387

Please sign in to comment.