Skip to content

Commit d2cd387

Browse files
authored
Fixed invalid gRPC TaskProgress message on compile (#2731)
* Fixed TaskProgress test * Fixed invalid gRPC TaskProgress message on compile
1 parent 0540cee commit d2cd387

File tree

5 files changed

+27
-15
lines changed

5 files changed

+27
-15
lines changed

Diff for: go.mod

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
module github.com/arduino/arduino-cli
22

3-
go 1.22
4-
5-
toolchain go1.22.3
3+
go 1.22.3
64

75
// We must use this fork until https://github.com/mailru/easyjson/pull/372 is merged
86
replace github.com/mailru/easyjson => github.com/cmaglie/easyjson v0.8.1
@@ -38,6 +36,7 @@ require (
3836
github.com/xeipuuv/gojsonschema v1.2.0
3937
go.bug.st/cleanup v1.0.0
4038
go.bug.st/downloader/v2 v2.2.0
39+
go.bug.st/f v0.4.0
4140
go.bug.st/relaxed-semver v0.12.0
4241
go.bug.st/testifyjson v1.2.0
4342
golang.org/x/term v0.25.0

Diff for: go.sum

+2
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,8 @@ go.bug.st/cleanup v1.0.0 h1:XVj1HZxkBXeq3gMT7ijWUpHyIC1j8XAoNSyQ06CskgA=
215215
go.bug.st/cleanup v1.0.0/go.mod h1:EqVmTg2IBk4znLbPD28xne3abjsJftMdqqJEjhn70bk=
216216
go.bug.st/downloader/v2 v2.2.0 h1:Y0jSuDISNhrzePkrAWqz9xUC3xol9hqZo/+tz1D4EqY=
217217
go.bug.st/downloader/v2 v2.2.0/go.mod h1:VZW2V1iGKV8rJL2ZEGIDzzBeKowYv34AedJz13RzVII=
218+
go.bug.st/f v0.4.0 h1:Vstqb950nMA+PhAlRxUw8QL1ntHy/gXHNyyzjkQLJ10=
219+
go.bug.st/f v0.4.0/go.mod h1:bMo23205ll7UW63KwO1ut5RdlJ9JK8RyEEr88CmOF5Y=
218220
go.bug.st/relaxed-semver v0.12.0 h1:se8v3lTdAAFp68+/RS/0Y/nFdnpdzkP5ICY04SPau4E=
219221
go.bug.st/relaxed-semver v0.12.0/go.mod h1:Cpcbiig6Omwlq6bS7i3MQWiqS7W7HDd8CAnZFC40Cl0=
220222
go.bug.st/serial v1.6.1 h1:VSSWmUxlj1T/YlRo2J104Zv3wJFrjHIl/T3NeruWAHY=

Diff for: internal/arduino/builder/builder.go

+4-6
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,10 @@ func (b *Builder) logIfVerbose(warn bool, msg string) {
352352

353353
// Build fixdoc
354354
func (b *Builder) Build() error {
355-
b.Progress.AddSubSteps(6 /** preprocess **/ + 21 /** build **/)
355+
b.Progress.AddSubSteps(6 + // preprocess
356+
18 + // build
357+
1, // size
358+
)
356359
defer b.Progress.RemoveSubSteps()
357360

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

364367
b.libsDetector.PrintUsedAndNotUsedLibraries(buildErr != nil)
365-
b.Progress.CompleteStep()
366-
367368
b.printUsedLibraries(b.libsDetector.ImportedLibraries())
368-
b.Progress.CompleteStep()
369-
370369
if buildErr != nil {
371370
return buildErr
372371
}
373-
b.Progress.CompleteStep()
374372

375373
if err := b.size(); err != nil {
376374
return err

Diff for: internal/integrationtest/daemon/daemon_test.go

+7-6
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import (
2424
"time"
2525

2626
"github.com/arduino/arduino-cli/commands/cmderrors"
27-
f "github.com/arduino/arduino-cli/internal/algorithms"
2827
"github.com/arduino/arduino-cli/internal/integrationtest"
2928
"github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
3029
"github.com/arduino/go-paths-helper"
@@ -194,13 +193,15 @@ func TestDaemonCompileOptions(t *testing.T) {
194193
if msg.GetErrStream() != nil {
195194
fmt.Printf("COMPILE> %v\n", string(msg.GetErrStream()))
196195
}
197-
analyzer.Process(msg.GetProgress())
196+
if pr := msg.GetProgress(); pr != nil {
197+
fmt.Printf("COMPILE PROGRESS> %v\n", pr)
198+
analyzer.Process(pr)
199+
}
198200
}
201+
199202
// https://github.com/arduino/arduino-cli/issues/2016
200-
// assert that the task progress is increasing and doesn't contain multiple 100% values
201-
results := analyzer.Results[""]
202-
require.True(t, results[len(results)-1].GetCompleted(), fmt.Sprintf("latest percent value: %v", results[len(results)-1].GetPercent()))
203-
require.IsNonDecreasing(t, f.Map(results, (*commands.TaskProgress).GetPercent))
203+
// https://github.com/arduino/arduino-cli/issues/2711
204+
analyzer.Check(t)
204205
}
205206

206207
func TestDaemonCompileAfterFailedLibInstall(t *testing.T) {

Diff for: internal/integrationtest/daemon/task_progress_test.go

+12
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ import (
1919
"testing"
2020

2121
"github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
22+
"github.com/stretchr/testify/require"
23+
"go.bug.st/f"
2224
)
2325

2426
// TaskProgressAnalyzer analyzes TaskProgress messages for consistency
@@ -44,3 +46,13 @@ func (a *TaskProgressAnalyzer) Process(progress *commands.TaskProgress) {
4446
taskName := progress.GetName()
4547
a.Results[taskName] = append(a.Results[taskName], progress)
4648
}
49+
50+
func (a *TaskProgressAnalyzer) Check(t *testing.T) {
51+
for task, results := range a.Results {
52+
require.Equal(t, 1, f.Count(results, (*commands.TaskProgress).GetCompleted), "Got multiple 'completed' messages on task %s", task)
53+
l := len(results)
54+
require.True(t, results[l-1].GetCompleted(), "Last message is not 'completed' on task: %s", task)
55+
require.Equal(t, results[l-1].GetPercent(), float32(100), "Last message is not 100% on task: %s", task)
56+
require.IsNonDecreasing(t, f.Map(results, (*commands.TaskProgress).GetPercent), "Percentages are not increasing on task: %s", task)
57+
}
58+
}

0 commit comments

Comments
 (0)