Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix infinite loop in e2e tests #383

Merged
merged 1 commit into from
Apr 23, 2018

Conversation

ashetty1
Copy link
Contributor

Fixes #368

Fail(err.Error())
}

outInt, _ := strconv.Atoi(string(out))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are we converting the output to int?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kadel I need the output in int since I am doing wc -l comparison

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

then we need a different name for this function. It is really specific one command, and it won't work for anything that is not ending with wc

Copy link
Contributor Author

@ashetty1 ashetty1 Apr 17, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kadel , how about we pass expected value in the function. Something like this:

func pingCmd(cmd string, expOut string) bool {
...
            out, err := exec.Command("/bin/sh", "-c", cmd).Output()
             if err != nil {
                  Fail(err.Error())
             }

             if string(out) == expOut {
                   return true
              }
...
}


pingCmd("curl -s getRoute  | grep -i odo | wc -l | tr -d '\n'" , "1")

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 that looks better.
It might be good to change function name pingCmd doesn't really indicate what this function does.
Also, don't forget to add a comment with a description what this function is for.

}

outInt, _ := strconv.Atoi(string(out))
if outInt > 0 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what happens when outInt is 0 or less?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kadel continues in the loop for 5 minutes

for {
select {
case <-pingTimeout:
Fail("timeout out after 5 minutes")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't be this timeout shorter? 5mins is really long time.
How about 1min? Is there a chance that after 1min the command will succeed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. Have changed it to 1min for now. ALso, have changed the function name to waitForCmdOut

@ashetty1 ashetty1 force-pushed the fix-infinite-loop branch from e2927f8 to e7e4920 Compare April 19, 2018 09:19
@@ -73,6 +73,35 @@ func pingSvc(url string) {
}
}

func waitForCmdOut(cmd string, expOut string) bool {
// This function runs the command until it \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment should be before the function.
Check this out https://blog.golang.org/godoc-documenting-go-code

@ashetty1 ashetty1 force-pushed the fix-infinite-loop branch 2 times, most recently from 493dae1 to c9ed219 Compare April 19, 2018 13:36
@@ -73,6 +73,35 @@ func pingSvc(url string) {
}
}

// This function runs the command until it \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why \ at the end of each line?

There is a standard in go, that comment for function starts with a function name.

@ashetty1 ashetty1 force-pushed the fix-infinite-loop branch from c9ed219 to c8045c5 Compare April 20, 2018 09:38
@ashetty1
Copy link
Contributor Author

@kadel hope this works.

@kadel kadel merged commit e83f0d1 into redhat-developer:master Apr 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants