Skip to content

Commit

Permalink
fix galley fssource flakey test (istio#9524)
Browse files Browse the repository at this point in the history
* fix galley fssource flakey test

* fix galley fssource flakey test

* fix mixer lint issue
  • Loading branch information
Iris authored and linsun committed Oct 31, 2018
1 parent c11b9a9 commit 4d9d7d6
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions galley/pkg/fs/fssource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"path/filepath"
"strings"
"testing"
"time"

"istio.io/istio/galley/pkg/runtime/resource"
)
Expand Down Expand Up @@ -326,16 +327,16 @@ func TestFsSource_DeletePartResorceInFile(t *testing.T) {
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}

log := logChannelOutput(ch, 4)
donec := make(chan bool)
expected := "[Event](Deleted: [VKey](type.googleapis.com/istio.policy.v1beta1.Rule:some.mixer.rule @v0))"

if log != expected {
t.Fatalf("Event mismatch:\nActual:\n%s\nExpected:\n%s\n", log, expected)
go checkEventOccurs(expected, ch, donec)
select {
case <-time.After(5 * time.Second):
t.Fatalf("Expected Event does not occur:\n%s\n", expected)
case <-donec:
return
}

s.Stop()

}

//Only log the last event out
Expand All @@ -346,3 +347,12 @@ func logChannelOutput(ch chan resource.Event, count int) string {
}
return strings.TrimSpace(fmt.Sprintf("%v\n", result))
}

// Check whether a specif event occurs
func checkEventOccurs(expectedEvent string, ch chan resource.Event, donec chan bool) {
for event := range ch {
if expectedEvent == strings.TrimSpace(fmt.Sprintf("%v\n", event)) {
donec <- true
}
}
}

0 comments on commit 4d9d7d6

Please sign in to comment.