File tree Expand file tree Collapse file tree 4 files changed +58
-1
lines changed
testdata/SketchWithMultipleSymlinkLoops Expand file tree Collapse file tree 4 files changed +58
-1
lines changed Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ import (
1919 "fmt"
2020 "os"
2121 "testing"
22+ "time"
2223
2324 "github.com/arduino/go-paths-helper"
2425 "github.com/stretchr/testify/assert"
@@ -332,7 +333,59 @@ func TestNewSketchWithSymlinkLoop(t *testing.T) {
332333 os .Symlink (sketchPath .String (), someSymlinkPath .String ())
333334 defer someSymlinkPath .Remove ()
334335
335- sketch , err := New (sketchPath )
336+ // The failure condition is New() never returning, testing for which requires setting up a timeout.
337+ done := make (chan bool )
338+ var sketch * Sketch
339+ var err error
340+ go func () {
341+ sketch , err = New (sketchPath )
342+ done <- true
343+ }()
344+
345+ assert .Eventually (
346+ t ,
347+ func () bool {
348+ select {
349+ case <- done :
350+ return true
351+ default :
352+ return false
353+ }
354+ },
355+ 20 * time .Second ,
356+ 10 * time .Millisecond ,
357+ "Infinite symlink loop while loading sketch" ,
358+ )
359+ require .Error (t , err )
360+ require .Nil (t , sketch )
361+ }
362+
363+ func TestSketchWithMultipleSymlinkLoops (t * testing.T ) {
364+ sketchPath , _ := paths .New ("testdata" , "SketchWithMultipleSymlinkLoops" ).Abs ()
365+
366+ // The failure condition is New() never returning, testing for which requires setting up a timeout.
367+ done := make (chan bool )
368+ var sketch * Sketch
369+ var err error
370+ go func () {
371+ sketch , err = New (sketchPath )
372+ done <- true
373+ }()
374+
375+ assert .Eventually (
376+ t ,
377+ func () bool {
378+ select {
379+ case <- done :
380+ return true
381+ default :
382+ return false
383+ }
384+ },
385+ 20 * time .Second ,
386+ 10 * time .Millisecond ,
387+ "Infinite symlink loop while loading sketch" ,
388+ )
336389 require .Error (t , err )
337390 require .Nil (t , sketch )
338391}
Original file line number Diff line number Diff line change 1+ void setup (){}
2+ void loop (){}
Original file line number Diff line number Diff line change 1+ ..
Original file line number Diff line number Diff line change 1+ ..
You can’t perform that action at this time.
0 commit comments