Skip to content

Commit 374ebc9

Browse files
committed
Added test for build caching
1 parent a6854b4 commit 374ebc9

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

Diff for: legacy/builder/test/try_build_of_problematic_sketch_test.go

+17
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,15 @@
1717
package test
1818

1919
import (
20+
"fmt"
2021
"path/filepath"
2122
"testing"
23+
"time"
2224

2325
"github.com/arduino/arduino-cli/legacy/builder"
2426
"github.com/arduino/arduino-cli/legacy/builder/types"
2527
paths "github.com/arduino/go-paths-helper"
28+
"github.com/stretchr/testify/require"
2629
)
2730

2831
func TestTryBuild001(t *testing.T) {
@@ -225,7 +228,21 @@ func makeDefaultContext(t *testing.T) *types.Context {
225228

226229
func tryBuild(t *testing.T, sketchPath ...string) {
227230
ctx := makeDefaultContext(t)
231+
ctx.DebugLevel = 999
232+
s1 := time.Now()
228233
tryBuildWithContext(t, ctx, sketchPath...)
234+
t1 := time.Now().Sub(s1)
235+
236+
ctx2 := makeDefaultContext(t)
237+
ctx2.DebugLevel = 999
238+
ctx2.BuildPath = ctx.BuildPath
239+
s2 := time.Now()
240+
tryBuildWithContext(t, ctx2, sketchPath...)
241+
t2 := time.Now().Sub(s2)
242+
243+
fmt.Println("Build time non-cached:", t1)
244+
fmt.Println("Build time cached:", t2)
245+
require.True(t, t1.Microseconds() > t2.Microseconds()*9/10, "cached build time should be much lower")
229246
}
230247

231248
func tryBuildWithContext(t *testing.T, ctx *types.Context, sketchPath ...string) {

0 commit comments

Comments
 (0)