Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 1923ac4

Browse files
Fix double 100% progress on CompileResponse (#2225)
1 parent 0e05ca1 commit 1923ac4

File tree

5 files changed

+86
-9
lines changed

5 files changed

+86
-9
lines changed

‎internal/integrationtest/daemon/daemon_test.go‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"time"
2424

2525
"github.com/arduino/arduino-cli/arduino"
26+
f "github.com/arduino/arduino-cli/internal/algorithms"
2627
"github.com/arduino/arduino-cli/internal/integrationtest"
2728
"github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
2829
"github.com/arduino/go-paths-helper"
@@ -171,6 +172,7 @@ func TestDaemonCompileOptions(t *testing.T) {
171172
// Build sketch (without errors)
172173
compile, err = grpcInst.Compile(context.Background(), "arduino:avr:uno:some_menu=good", sk.String(), "")
173174
require.NoError(t, err)
175+
analyzer := NewTaskProgressAnalyzer(t)
174176
for {
175177
msg, err := compile.Recv()
176178
if err == io.EOF {
@@ -180,7 +182,13 @@ func TestDaemonCompileOptions(t *testing.T) {
180182
if msg.ErrStream != nil {
181183
fmt.Printf("COMPILE> %v\n", string(msg.GetErrStream()))
182184
}
185+
analyzer.Process(msg.GetProgress())
183186
}
187+
// https://github.com/arduino/arduino-cli/issues/2016
188+
// assert that the task progress is increasing and doesn't contain multiple 100% values
189+
results := analyzer.Results[""]
190+
require.True(t, results[len(results)-1].Completed)
191+
require.IsNonDecreasing(t, f.Map(results, (*commands.TaskProgress).GetPercent))
184192
}
185193

186194
func TestDaemonCompileAfterFailedLibInstall(t *testing.T) {
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// This file is part of arduino-cli.
2+
//
3+
// Copyright 2022 ARDUINO SA (http://www.arduino.cc/)
4+
//
5+
// This software is released under the GNU General Public License version 3,
6+
// which covers the main part of arduino-cli.
7+
// The terms of this license can be found at:
8+
// https://www.gnu.org/licenses/gpl-3.0.en.html
9+
//
10+
// You can be released from the requirements of the above licenses by purchasing
11+
// a commercial license. Buying such a license is mandatory if you want to
12+
// modify or otherwise use the software for commercial activities involving the
13+
// Arduino software without disclosing the source code of your own applications.
14+
// To purchase a commercial license, send an email to license@arduino.cc.
15+
16+
package daemon_test
17+
18+
import (
19+
"testing"
20+
21+
"github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
22+
)
23+
24+
// TaskProgressAnalyzer analyzes TaskProgress messages for consistency
25+
type TaskProgressAnalyzer struct {
26+
t *testing.T
27+
Results map[string][]*commands.TaskProgress
28+
}
29+
30+
// NewTaskProgressAnalyzer creates a new TaskProgressAnalyzer
31+
func NewTaskProgressAnalyzer(t *testing.T) *TaskProgressAnalyzer {
32+
return &TaskProgressAnalyzer{
33+
t: t,
34+
Results: map[string][]*commands.TaskProgress{},
35+
}
36+
}
37+
38+
// Process the given TaskProgress message.
39+
func (a *TaskProgressAnalyzer) Process(progress *commands.TaskProgress) {
40+
if progress == nil {
41+
return
42+
}
43+
44+
taskName := progress.GetName()
45+
a.Results[taskName] = append(a.Results[taskName], progress)
46+
}

‎legacy/builder/builder.go‎

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func (s *Builder) Run(ctx *types.Context) error {
4141
return err
4242
}
4343

44-
var _err error
44+
var _err, mainErr error
4545
commands := []types.Command{
4646
&ContainerSetupHardwareToolsLibsSketchAndProps{},
4747

@@ -92,12 +92,25 @@ func (s *Builder) Run(ctx *types.Context) error {
9292
&RecipeByPrefixSuffixRunner{Prefix: "recipe.hooks.postbuild", Suffix: ".pattern", SkipIfOnlyUpdatingCompilationDatabase: true},
9393
}
9494

95-
mainErr := runCommands(ctx, commands)
95+
ctx.Progress.AddSubSteps(len(commands) + 4)
96+
defer ctx.Progress.RemoveSubSteps()
97+
98+
for _, command := range commands {
99+
PrintRingNameIfDebug(ctx, command)
100+
err := command.Run(ctx)
101+
if err != nil {
102+
mainErr = errors.WithStack(err)
103+
break
104+
}
105+
ctx.Progress.CompleteStep()
106+
ctx.PushProgress()
107+
}
96108

97109
if ctx.CompilationDatabase != nil {
98110
ctx.CompilationDatabase.SaveToFile()
99111
}
100112

113+
var otherErr error
101114
commands = []types.Command{
102115
&PrintUsedAndNotUsedLibraries{SketchError: mainErr != nil},
103116

@@ -107,7 +120,16 @@ func (s *Builder) Run(ctx *types.Context) error {
107120

108121
&phases.Sizer{SketchError: mainErr != nil},
109122
}
110-
otherErr := runCommands(ctx, commands)
123+
for _, command := range commands {
124+
PrintRingNameIfDebug(ctx, command)
125+
err := command.Run(ctx)
126+
if err != nil {
127+
otherErr = errors.WithStack(err)
128+
break
129+
}
130+
ctx.Progress.CompleteStep()
131+
ctx.PushProgress()
132+
}
111133

112134
if mainErr != nil {
113135
return mainErr
@@ -193,8 +215,7 @@ func PrintRingNameIfDebug(ctx *types.Context, command types.Command) {
193215
}
194216

195217
func RunBuilder(ctx *types.Context) error {
196-
command := Builder{}
197-
return command.Run(ctx)
218+
return runCommands(ctx, []types.Command{&Builder{}})
198219
}
199220

200221
func RunParseHardware(ctx *types.Context) error {

‎legacy/builder/container_setup.go‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,13 @@ import (
2323
type ContainerSetupHardwareToolsLibsSketchAndProps struct{}
2424

2525
func (s *ContainerSetupHardwareToolsLibsSketchAndProps) Run(ctx *types.Context) error {
26-
// total number of steps in this container: 4
27-
ctx.Progress.AddSubSteps(4)
28-
defer ctx.Progress.RemoveSubSteps()
2926
commands := []types.Command{
3027
&AddAdditionalEntriesToContext{},
3128
&FailIfBuildPathEqualsSketchPath{},
3229
&LibrariesLoader{},
3330
}
31+
ctx.Progress.AddSubSteps(len(commands))
32+
defer ctx.Progress.RemoveSubSteps()
3433
for _, command := range commands {
3534
PrintRingNameIfDebug(ctx, command)
3635
err := command.Run(ctx)

‎legacy/builder/types/context.go‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,10 @@ func (ctx *Context) ExtractBuildOptions() *properties.Map {
200200

201201
func (ctx *Context) PushProgress() {
202202
if ctx.ProgressCB != nil {
203-
ctx.ProgressCB(&rpc.TaskProgress{Percent: ctx.Progress.Progress})
203+
ctx.ProgressCB(&rpc.TaskProgress{
204+
Percent: ctx.Progress.Progress,
205+
Completed: ctx.Progress.Progress >= 100.0,
206+
})
204207
}
205208
}
206209

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /