Skip to content

Commit

Permalink
Adapt tests for devfile handled separately
Browse files Browse the repository at this point in the history
  • Loading branch information
feloy committed Jul 8, 2022
1 parent f183e60 commit 1bc1cc7
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 6 deletions.
7 changes: 4 additions & 3 deletions pkg/watch/watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ func eventWatcher(ctx context.Context, watcher *fsnotify.Watcher, deploymentWatc
deployTimer := time.NewTimer(time.Millisecond)
<-deployTimer.C

fmt.Fprintf(out, "Status: %s\n", componentStatus.State)
//fmt.Fprintf(out, "Status: %s\n", componentStatus.State)

for {
// fmt.Fprintf(out, "=> enter select\n")
Expand Down Expand Up @@ -318,7 +318,7 @@ func eventWatcher(ctx context.Context, watcher *fsnotify.Watcher, deploymentWatc
if err != nil {
return err
}
fmt.Fprintf(out, "Status: %s\n", componentStatus.State)
// fmt.Fprintf(out, "Status: %s\n", componentStatus.State)
// empty the events to receive new events
if componentStatus.State == StateReady {
events = []fsnotify.Event{} // empty the events slice to capture new events
Expand Down Expand Up @@ -347,14 +347,15 @@ func eventWatcher(ctx context.Context, watcher *fsnotify.Watcher, deploymentWatc
if err != nil {
return err
}
fmt.Fprintf(out, "Status: %s\n", componentStatus.State)
// fmt.Fprintf(out, "Status: %s\n", componentStatus.State)

case <-devfileWatcher.Events:
// fmt.Fprintf(out, " devfileWatcher.Events: %s\n", ev.String())
devfileTimer.Reset(100 * time.Millisecond)

case <-devfileTimer.C:
// fmt.Fprintf(out, "send new devfile")
fmt.Fprintf(out, "Updating Component...\n\n")
err := processEventsHandler(nil, nil, parameters, out, &componentStatus, expBackoff)
if err != nil {
return err
Expand Down
3 changes: 2 additions & 1 deletion pkg/watch/watch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ func Test_eventWatcher(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
watcher, _ := fsnotify.NewWatcher()
fileWatcher, _ := fsnotify.NewWatcher()
var cancel context.CancelFunc
ctx, cancel := context.WithCancel(context.Background())
out := &bytes.Buffer{}
Expand All @@ -135,7 +136,7 @@ func Test_eventWatcher(t *testing.T) {
componentStatus := ComponentStatus{
State: StateReady,
}
err := eventWatcher(ctx, watcher, fakeWatcher{}, tt.args.parameters, out, evaluateChangesHandler, processEventsHandler, cleanupHandler, componentStatus)
err := eventWatcher(ctx, watcher, fakeWatcher{}, fileWatcher, tt.args.parameters, out, evaluateChangesHandler, processEventsHandler, cleanupHandler, componentStatus)
if (err != nil) != tt.wantErr {
t.Errorf("eventWatcher() error = %v, wantErr %v", err, tt.wantErr)
return
Expand Down
2 changes: 1 addition & 1 deletion tests/helper/helper_dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func (o DevSession) WaitEnd() {
// It returns the contents of the standard and error outputs
// since the end of the dev mode started or previous sync, and until the end of the synchronization.
func (o DevSession) WaitSync() ([]byte, []byte, map[string]string, error) {
WaitForOutputToContain("Pushing files...", 180, 10, o.session)
WaitForOutputToContainOne([]string{"Pushing files...", "Updating Component..."}, 180, 10, o.session)
WaitForOutputToContain("Watching for changes in the current directory", 240, 10, o.session)
outContents := o.session.Out.Contents()
errContents := o.session.Err.Contents()
Expand Down
13 changes: 13 additions & 0 deletions tests/helper/helper_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/onsi/gomega/gexec"
"github.com/onsi/gomega/types"
"github.com/redhat-developer/odo/pkg/labels"
)

Expand Down Expand Up @@ -40,6 +41,18 @@ func WaitForOutputToContain(substring string, timeoutInSeconds int, intervalInSe

}

func WaitForOutputToContainOne(substrings []string, timeoutInSeconds int, intervalInSeconds int, session *gexec.Session) {

matchers := make([]types.GomegaMatcher, 0, len(substrings))
for _, substring := range substrings {
matchers = append(matchers, ContainSubstring(substring))
}
Eventually(func() string {
contents := string(session.Out.Contents())
return contents
}, timeoutInSeconds, intervalInSeconds).Should(SatisfyAny(matchers...))
}

// WaitForErroutToContain waits for the session stdout output to contain a particular substring
func WaitForErroutToContain(substring string, timeoutInSeconds int, intervalInSeconds int, session *gexec.Session) {

Expand Down
7 changes: 6 additions & 1 deletion tests/integration/devfile/cmd_dev_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1670,7 +1670,7 @@ var _ = Describe("odo dev command tests", func() {
When("Update the devfile.yaml", func() {

BeforeEach(func() {
helper.ReplaceString("devfile.yaml", "memoryLimit: 1024Mi", "memoryLimit: 1023Mi")
helper.ReplaceString("devfile.yaml", "memoryLimit: 768Mi", "memoryLimit: 767Mi")
var err error
_, _, _, err = session.WaitSync()
Expect(err).ToNot(HaveOccurred())
Expand Down Expand Up @@ -1721,6 +1721,11 @@ var _ = Describe("odo dev command tests", func() {
return nil
}

// devfile is not synchronized
if newPath == "devfile.yaml" {
return nil
}

localFiles = append(localFiles, newPath)
return nil
})
Expand Down

0 comments on commit 1bc1cc7

Please sign in to comment.