Skip to content

Conversation

qlzh727
Copy link
Member

@qlzh727 qlzh727 commented Mar 28, 2018

No description provided.

@qlzh727 qlzh727 requested review from k-w-w, karmel and nealwu as code owners March 28, 2018 19:35
@qlzh727 qlzh727 requested a review from robieta March 28, 2018 20:08
Copy link
Contributor

@robieta robieta left a comment

Choose a reason for hiding this comment

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

I have some requests, but the broad strokes look good.

set +x

# Assume the pwd is under models.
cd official
Copy link
Contributor

Choose a reason for hiding this comment

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

cd "$(git rev-parse --show-toplevel)/official" is a bit more flexible, as you can be anywhere in the project.

Copy link
Contributor

Choose a reason for hiding this comment

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

I am wary of adding git magic into the script. Maybe instructions above with the alias lint_and_test, along with setting $TF_MODELS_ROOT or something to that effect, which, if empty, will mean you cd into just official as now, but, if set, the right place.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done. Changed to check the file location of the script and cd into the relative directory of the git repository root.

# Check lint:
RC_FILE="utils/testing/pylint.rcfile"

echo "===========Running lint test============"
Copy link
Contributor

Choose a reason for hiding this comment

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

git diff --name-only origin/master ./official/ has the nice property that you only have to care about stuff you touched. (And it makes linting faster.) The one caveat is it includes deleted files so you would have to do an existence test.

Copy link
Contributor

Choose a reason for hiding this comment

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

If there are errors in things you didn't touch, the tests on Kokoro will fail as well. Printing them all will make us fix them faster. One hopes.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yea, currently running all the tests rather than the touched one. Since the file depend on each other, you cannot tell whether the test will break or not even its not touched.

echo "===========Running Python test============"

for test_file in `find . -name '*test.py' -print`
do
Copy link
Contributor

Choose a reason for hiding this comment

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

May as well run in parallel. I looks like xargs can do it; otherwise it's pretty trivial to do in python with subprocess. The reason being...

Copy link
Contributor

Choose a reason for hiding this comment

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

It's worth noting that even our unit tests take a long time now. How long will this take locally? In my experience, once testing takes longer than ~5 min, people stop doing it. That said, I don't want to add a ton of logic here that has to be separately maintained from the Kokoro files. In fact, I already feel nervous about this duplication. It's easy to imagine the two sets of files diverging. I don't have a solution there, but... maybe the better way to handle this is a private wrapper around the kokoro files. That way, we can include git magic, whatever you want. Runs from the internal files, on external files.

Copy link
Contributor

Choose a reason for hiding this comment

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

In total it's something like 7-8 min. (So ~15 if you do py2 and py3) I agree that likelihood of being run goes down with run time.

As far as code duplication, what if the heavy lifting is in a public script and Kokoro's build.sh just finds and runs that script? (At least for testing and linting.) I think this is the same as what Karmel is suggesting?

Copy link
Member Author

Choose a reason for hiding this comment

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

The updated version of script will the one for all. Kokoro tests will just call it.

for test_file in `find . -name '*test.py' -print`
do
echo "Testing ${test_file}"
python "${test_file}" || exit_code=$?
Copy link
Contributor

Choose a reason for hiding this comment

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

... this should probably do py2 and py3.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

@@ -0,0 +1,43 @@
#!/bin/bash
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be nice to provide a command to run this from anywhere in the repo. For instance:
alias lint_and_test=$(git rev-parse --show-toplevel)/official/utils/testing/scripts/presubmit.sh
Either in the README or in this file.

Copy link
Member Author

Choose a reason for hiding this comment

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

Have usage example on the top of the script.

for file in `find . -name '*.py' ! -name '*test.py' -print`
do
echo "Linting ${file}"
pylint --rcfile="${RC_FILE}" "${file}" || exit_code=$?
Copy link
Contributor

Choose a reason for hiding this comment

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

If you change the cd at the top, you should also inject the absolute path into the rcfile path. It has trouble finding it otherwise. (Not sure if there is some weird cd related bash behavior.)

Copy link
Member Author

Choose a reason for hiding this comment

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

Ack.

Copy link
Contributor

@karmel karmel left a comment

Choose a reason for hiding this comment

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

Code duplication causes me anxiety.

set +x

# Assume the pwd is under models.
cd official
Copy link
Contributor

Choose a reason for hiding this comment

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

I am wary of adding git magic into the script. Maybe instructions above with the alias lint_and_test, along with setting $TF_MODELS_ROOT or something to that effect, which, if empty, will mean you cd into just official as now, but, if set, the right place.

# Check lint:
RC_FILE="utils/testing/pylint.rcfile"

echo "===========Running lint test============"
Copy link
Contributor

Choose a reason for hiding this comment

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

If there are errors in things you didn't touch, the tests on Kokoro will fail as well. Printing them all will make us fix them faster. One hopes.

echo "===========Running Python test============"

for test_file in `find . -name '*test.py' -print`
do
Copy link
Contributor

Choose a reason for hiding this comment

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

It's worth noting that even our unit tests take a long time now. How long will this take locally? In my experience, once testing takes longer than ~5 min, people stop doing it. That said, I don't want to add a ton of logic here that has to be separately maintained from the Kokoro files. In fact, I already feel nervous about this duplication. It's easy to imagine the two sets of files diverging. I don't have a solution there, but... maybe the better way to handle this is a private wrapper around the kokoro files. That way, we can include git magic, whatever you want. Runs from the internal files, on external files.

1. Check the script file location and cd into repo root dir.
2. Allow caller to call differnt tests.
@qlzh727 qlzh727 changed the title Add presubmit testing script for local testing. Add testing script for local lint and python test. Mar 29, 2018
@qlzh727
Copy link
Member Author

qlzh727 commented Apr 2, 2018

Done. The script has been updated so that it can be run both on Kokoro and local. We can update Kokoro scripts once this PR is committed.

@robieta
Copy link
Contributor

robieta commented Apr 2, 2018

The tests are still serial though, right?

@qlzh727
Copy link
Member Author

qlzh727 commented Apr 2, 2018

Correct. Running tests in parallel might generate confusing error logs since they are mixed together. On the other hand, Bazel is helpful for those case, since it generate a summary at the end the run.

Copy link
Contributor

@karmel karmel left a comment

Choose a reason for hiding this comment

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

Great, thanks

@robieta
Copy link
Contributor

robieta commented Apr 2, 2018

Discussed offline. I am fine with the plan of "serial for now, Bazel eventually" rather than have a somewhat complicated python script that we'll eventually get rid of anyway.

@qlzh727 qlzh727 merged commit 03bf0d3 into tensorflow:master Apr 2, 2018
@qlzh727 qlzh727 deleted the test-script branch April 2, 2018 22:54
omegafragger pushed a commit to omegafragger/models that referenced this pull request May 15, 2018
* Add presubmit testing script for local testing.

* Update the test script to be more modularized.

1. Check the script file location and cd into repo root dir.
2. Allow caller to call differnt tests.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants