Skip to content

Commit 1fe0533

Browse files
committed
Fixed TaskProgress test
1 parent 0540cee commit 1fe0533

File tree

4 files changed

+23
-9
lines changed

4 files changed

+23
-9
lines changed

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

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=

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) {

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)