Skip to content

Commit c7a7212

Browse files
add integration test
1 parent b7f5db4 commit c7a7212

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

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

+13
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ func TestDaemonCompileOptions(t *testing.T) {
171171
// Build sketch (without errors)
172172
compile, err = grpcInst.Compile(context.Background(), "arduino:avr:uno:some_menu=good", sk.String(), "")
173173
require.NoError(t, err)
174+
analyzer := NewTaskProgressAnalyzer(t)
174175
for {
175176
msg, err := compile.Recv()
176177
if err == io.EOF {
@@ -180,7 +181,19 @@ func TestDaemonCompileOptions(t *testing.T) {
180181
if msg.ErrStream != nil {
181182
fmt.Printf("COMPILE> %v\n", string(msg.GetErrStream()))
182183
}
184+
analyzer.Process(msg.GetProgress())
183185
}
186+
// https://github.com/arduino/arduino-cli/issues/2016
187+
// assert that the task progress is increasing and doesn't contain multiple 100% values
188+
results := analyzer.Results[""]
189+
require.True(t, results[len(results)-1].Completed)
190+
require.IsNonDecreasing(t, func() []float32{
191+
res := make([]float32, len(results))
192+
for i := 0; i < len(results); i++ {
193+
res[i] = results[i].Percent
194+
}
195+
return res
196+
}())
184197
}
185198

186199
func TestDaemonCompileAfterFailedLibInstall(t *testing.T) {
+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package daemon_test
2+
3+
import (
4+
"testing"
5+
6+
"github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
7+
)
8+
9+
// TaskProgressAnalyzer analyzes TaskProgress messages for consistency
10+
type TaskProgressAnalyzer struct {
11+
t *testing.T
12+
Results map[string][]*commands.TaskProgress
13+
}
14+
15+
// NewTaskProgressAnalyzer creates a new TaskProgressAnalyzer
16+
func NewTaskProgressAnalyzer(t *testing.T) *TaskProgressAnalyzer {
17+
return &TaskProgressAnalyzer{
18+
t: t,
19+
Results: map[string][]*commands.TaskProgress{},
20+
}
21+
}
22+
23+
// Process the given TaskProgress message.
24+
func (a *TaskProgressAnalyzer) Process(progress *commands.TaskProgress) {
25+
if progress == nil {
26+
return
27+
}
28+
29+
taskName := progress.GetName()
30+
a.Results[taskName] = append(a.Results[taskName], progress)
31+
}

0 commit comments

Comments
 (0)