Skip to content
This repository has been archived by the owner on Sep 26, 2018. It is now read-only.

Speed up st2contrib tests #332

Closed
wants to merge 4 commits into from
Closed

Speed up st2contrib tests #332

wants to merge 4 commits into from

Conversation

jfryman
Copy link
Contributor

@jfryman jfryman commented Dec 8, 2015

Got a little upset today at the long build times, so I 😡 and fixed it.

Below are updates to the st2contrib repo, changing up the way that files are parsed. This removes the generic find glob from each of the tests and replaces with only the files that have changed.

Might require a bit of fixups, but hopefully you get the gist.

@jfryman
Copy link
Contributor Author

jfryman commented Dec 8, 2015

Before

before

After

after

@jfryman
Copy link
Contributor Author

jfryman commented Dec 8, 2015

Oh, and I also disabled CI on PR, since we're already doing it on Push... it's redundant.

@manasdk
Copy link
Contributor

manasdk commented Dec 8, 2015

Can you direct some of this rage to the main st2 repo as well :)

@jfryman
Copy link
Contributor Author

jfryman commented Dec 8, 2015

🔜

@manasdk
Copy link
Contributor

manasdk commented Dec 8, 2015

Excellent!

I am going to +1 simply looking at the time improvements :)

@lakshmi-kannan
Copy link
Contributor

Nice!

@Kami
Copy link
Member

Kami commented Dec 9, 2015

Overall, I like the idea 👍 and we did a similar thing in the past projects I worked on, but it's also worth pointing out that it has limitations. It really only works on simple checks which operate on a single file (e.g. flake8, json lint, yaml lint). I doesn't work on other more complex checks which do cross file stuff or depend on changes from other files (e.g. pylint and tests). In short - file change is just one type of a change and it's a very simplistic one - there are many other types of changes this approach doesn't detect and where we still want to run the tests (dependency is updated / changed, imported file has changed, etc.).

Another thing which is also important is that if we get this to work reliably, we should only enable "run only on changed files" for branches / PRs. On master branch we still want to run it on all the files, not just changed one (otherwise bad changes might slip through and the process is not directly reproducible).

Most importantly - the biggest offender right now should be the step where we install the dependencies. The tests and pylint step are relatively fast, only thing which takes a while is dependency installation. We do cache dependencies, but it will take a while in the following cases:

  • new dependency is added / updated
  • new version of dependency is released (we don't pin to a specific version)
  • new pack is added

In any of those scenarios we still want to run the tests - dependency change could cause pylint or tests to fail.

In short - there are many edge cases so I'm not sure this will work reliably. In the past we pretty much always ended up reverting similar changes and simply do "run on all" - it requires a lot of code changes, it's not really directly reproducible and as mentioned above, there are many edge cases and only a couple of places where it's worth doing it.

@Kami
Copy link
Member

Kami commented Dec 9, 2015

Oh, and I also disabled CI on PR, since we're already doing it on Push... it's redundant.

I believe the "PR" one is actually the PR merge commit - running the checks after branch has been merged into master. If that's the case, we should still run the check (PR / branch by itself can pass just fine, but it fails in merge into master).

@jfryman
Copy link
Contributor Author

jfryman commented Dec 9, 2015

I believe the "PR" one is actually the PR merge commit - running the checks after branch has been merged into master. If that's the case, we should still run the check (PR / branch by itself can pass just fine, but it fails in merge into master).

Yup. I messed up there. Reverted. Now enabled for PRs as well. Thanks! 🙇

@Kami
Copy link
Member

Kami commented Dec 10, 2015

I'll dig in next week and see if we can get some of those changes in without affecting the "correctness" and "reproduciability" of the tests.

In this case (st2contrib) it might be possible if we treat the whole pack as an atomic unit - I believe you already do that, but I haven't checked yet (if we ignore changes in the st2 repo since pylint also does cross checking and referencing files from st2 repo), but in st2 repo we need to treat whole repo as an atomic unit so sadly not much we can do with the file / directory change.

@jfryman
Copy link
Contributor Author

jfryman commented Dec 10, 2015

@Kami good deal! thanks.


.PHONY: configs-check
configs-check: requirements
@echo
@echo "==================== configs-check ===================="
@echo
. $(VIRTUALENV_DIR)/bin/activate; find ${ROOT_DIR}/packs/* -name "*.json" -print0 | xargs -0 -I FILENAME ./scripts/validate-json-file.sh FILENAME
. $(VIRTUALENV_DIR)/bin/activate; find ${ROOT_DIR}/packs/* -name "*.yaml" -print0 | xargs -0 -I FILENAME ./scripts/validate-yaml-file.sh FILENAME
. $(VIRTUALENV_DIR)/bin/activate; for file in "$(CHANGED_YAML)"; do if [ -n "$$file" ]; then ./scripts/validate-yaml-file.sh $$file; fi; done
Copy link
Member

Choose a reason for hiding this comment

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

I'm cherry picking and modifying those changes and I just noticed there is a bug here.

Since the whole string is quoted if there are multiple changed files it will actually only iterate once over the whole string (and not over all the words).

Kami added a commit that referenced this pull request Dec 14, 2015
…changed on

safe checks.

In addition to that we only run if changes in branch - on master branch we still
run checks on all the files.
@Kami Kami mentioned this pull request Dec 14, 2015
@Kami
Copy link
Member

Kami commented Dec 14, 2015

Superseded by #343.

@Kami Kami closed this Dec 14, 2015
@jfryman jfryman deleted the speed-up-tests branch December 18, 2015 14:10
emedvedev pushed a commit that referenced this pull request Apr 4, 2016
…changed on

safe checks.

In addition to that we only run if changes in branch - on master branch we still
run checks on all the files.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants