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

tests: add command to compile all test files #7364

Merged
merged 7 commits into from
Oct 21, 2020
Merged

Conversation

robert-zaremba
Copy link
Collaborator

test-build-check will compile and use go cache mechanism to
check if ALL files compiles without running any test.

ref: #7362


Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.

  • Targeted PR against correct branch (see CONTRIBUTING.md)
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
  • Code follows the module structure standards.
  • Wrote unit and integration tests
  • Updated relevant documentation (docs/) or specification (x/<module>/spec/)
  • Added relevant godoc comments.
  • Added a relevant changelog entry to the Unreleased section in CHANGELOG.md
  • Re-reviewed Files changed in the Github PR explorer
  • Review Codecov Report in the comment section below once CI passes

test-build-check will compile and use go cache mechanism to
check if ALL files compiles without running any test.

ref: 7362
Makefile Outdated Show resolved Hide resolved
Makefile Outdated Show resolved Hide resolved
Copy link
Contributor

@alessio alessio left a comment

Choose a reason for hiding this comment

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

This seems a tad unnecesary. Go's cache is enabled by default, and so it must be in order to use go modules. Plus make test-all already runs all tests and avoid re-execution by leveraging Go's internal cache.

@robert-zaremba
Copy link
Collaborator Author

make test-all

  • doesn't cache all tests, (eg: ok github.com/cosmos/cosmos-sdk/server/grpc 17.180s ),

  • it takes lot of time, subsequent run takes:

      make test-all  172.39s user 10.43s system 127% cpu 2:23.07 total
    
  • Running make test-all makes me going for a break.

On the other hand, subsequent run of make test-build-check:

make test-build-check  53.37s user 6.96s system 326% cpu 18.455 total

And we can optimize it way more if we will use go test -c in each package.

@robert-zaremba
Copy link
Collaborator Author

not sure how much time it would take to go and run go test -c in all subdirectories.

@alessio
Copy link
Contributor

alessio commented Sep 22, 2020

doesn't cache all tests

Untrue. It does.

subsequent run of make test-build-check

...bring no advantages and the Makefile rule execution is faster just because it does not run all tests.

@robert-zaremba
Copy link
Collaborator Author

...bring no advantages and the Makefile rule execution is faster just because it does not run all tests.

As it's noted in the make task, that's the whole goal to not execute any test and only do a compilation.

@alessio
Copy link
Contributor

alessio commented Sep 22, 2020

As it's noted in the make task, that's the whole goal to not execute any test and only do a compilation.

Then test-build-check is a misnomer. All test* targets in our Makefile run tests. This wouldn't. Most importantly, what is the benefit of it? What other reason you want to compile your test packages for if not to actually run tests?

@robert-zaremba
Copy link
Collaborator Author

What other reason you want to compile your test packages for if not to actually run tests?

I already mentioned it -> save some time. If I'm doing some small refactoring, especially in a core package, I don't want to wait 6-10min each time to re-execute all tests. I firstly will like to check that everything compile and then after fixing compilation issues, I would run tests.

@alessio
Copy link
Contributor

alessio commented Sep 22, 2020

I don't want to wait 6-10min each time to re-execute all tests

You have to. Just compiling your tests is not enough. Your editor (with the right settings, e.g. build tags) can handle everything for you.

I already mentioned it -> save some time

Again, your editor does it for you. Adding a tests-compilation target in the Makefile that fundamentally does nothing is pointless.

@alessio
Copy link
Contributor

alessio commented Sep 22, 2020

I already mentioned it -> save some time

go test -mod=readonly -run=nope ./... does not save time at all.
When you run your tests with the various tags (and we need to do so for various reasons), you'll inevitably rebuild them.

@robert-zaremba
Copy link
Collaborator Author

You have to. Just compiling your tests is not enough.

Please re-read my comment above.

go test -mod=readonly -run=nope ./... does not save time at all.

6min vs 18sec is saving a time. I did it few times today and it helped me and saved my time a lot (BTW: it has noting to do with running a particular test).

Anyway, if it's only for me then I will add it to private scripts and update .gitignore so we can have private scripts.

@alessio
Copy link
Contributor

alessio commented Sep 22, 2020

6min vs 18sec is saving a time.

It is not, especially if the compiler has to recompile regardless of whether you had compiled before. Again, try dig into your go tests cache and you will see it yourself - different +build tags mean different objects, thus if you build your test objects without a specific build tag, and you the run exactly those tests with some build tags, the compiler will rebuild the test objects anyway.

Anyway, if it's only for me then I will add it to private scripts and update .gitignore so we can have private scripts.

That sounds like an eminently wise choice.

@alessio
Copy link
Contributor

alessio commented Oct 20, 2020

Bump - can we close this for now please?

@robert-zaremba
Copy link
Collaborator Author

I'm using test-build-check through a private Makefile. So, if nobody needs it then let's close.

@alessio
Copy link
Contributor

alessio commented Oct 20, 2020

I drop here a replacement of the proposed patch, which would cause tests to be effectively cached and not rebuilt (provided that one uses exactly the same tags in its build configuration):

diff --git a/Makefile b/Makefile
index bd667b1c0..0ee675b1d 100644
--- a/Makefile
+++ b/Makefile
@@ -218,6 +218,7 @@ test-all: test-unit test-ledger-mock test-race test-cover
 
 TEST_PACKAGES=./...
 TEST_TARGETS := test-unit test-unit-amino test-unit-proto test-ledger-mock test-race test-ledger test-race
+CHECK_TEST_TARGETS := check-test-unit check-test-unit-amino check-test-unit-proto check-test-ledger-mock check-test-race check-test-ledger check-test-race
 
 # Test runs-specific rules. To add a new test target, just add
 # a new rule, customise ARGS or TEST_PACKAGES ad libitum, and
@@ -230,13 +231,22 @@ test-ledger-mock: ARGS=-tags='ledger test_ledger_mock norace'
 test-race: ARGS=-race -tags='cgo ledger test_ledger_mock'
 test-race: TEST_PACKAGES=$(PACKAGES_NOSIMULATION)
 
+check-test-unit: test-unit
+check-test-unit-amino: test-unit-amino
+check-test-ledger: test-ledger
+check-test-ledger-mock: test-ledger-mock
+check-test-race: test-race
+
 $(TEST_TARGETS): run-tests
 
+$(CHECK_TEST_TARGETS): run-tests
+$(CHECK_TEST_TARGETS): EXTRA_ARGS=-run=none
+
 run-tests:
 ifneq (,$(shell which tparse 2>/dev/null))
-       go test -mod=readonly -json $(ARGS) $(TEST_PACKAGES) | tparse
+       go test -mod=readonly -json $(ARGS) $(EXTRA_ARGS) $(TEST_PACKAGES) | tparse
 else
-       go test -mod=readonly $(ARGS) $(TEST_PACKAGES)
+       go test -mod=readonly $(ARGS) $(EXTRA_ARGS) $(TEST_PACKAGES)
 endif
 
 .PHONY: run-tests test test-all $(TEST_TARGETS)

@robert-zaremba
Copy link
Collaborator Author

looks good. Do you want to commit it here?

@robert-zaremba
Copy link
Collaborator Author

BTW: we only really need to build all tests, we don't need to split them in multiple categories.

@alessio
Copy link
Contributor

alessio commented Oct 21, 2020

we only really need to build all tests

If you build all tests with the same flags, cache won't work when you run make test-$WHATEVER, e.g. if you run go build ./... first, then make test-unit tests won't be cached. See my comment above for an explanation.

For what concerns me, this could be closed and my patch should be adopted. @robert-zaremba feel free to close this yourself. Thanks!

@robert-zaremba
Copy link
Collaborator Author

OK. @alessio - so you prefer to close this and make a new PR with your patch? That works for me. Do you want me to do it?

@alessio
Copy link
Contributor

alessio commented Oct 21, 2020

I don't believe it brings much benefit, I will hardly use it. But if you want and need it, feel free to either amend this PR or open a new one and I'll approve it 👍

@robert-zaremba
Copy link
Collaborator Author

@alessio , I've updated the PR. Added only check-test-unit and check-test-unit-amino. I the entry I created before.

Makefile Outdated Show resolved Hide resolved
Makefile Outdated Show resolved Hide resolved
@robert-zaremba robert-zaremba added the A:automerge Automatically merge PR once all prerequisites pass. label Oct 21, 2020
Copy link
Member

@aaronc aaronc left a comment

Choose a reason for hiding this comment

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

ACK

@mergify mergify bot merged commit 55d7d0c into master Oct 21, 2020
@mergify mergify bot deleted the robert/test-build branch October 21, 2020 20:51
CHECK_TEST_TARGETS := test-unit test-unit-amino
check-test-unit: test-unit
check-test-unit-amino: test-unit-amino
$(CHECK_TEST_TARGETS): EXTRA_ARGS=-run=none
Copy link
Member

@tac0turtle tac0turtle Oct 26, 2020

Choose a reason for hiding this comment

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

is this suppose to be inserted on make test? I cant find any updates in the contributing on how to run tests?

cosmos-sdk on  marko/remove_toTM2 [!?] via 🐹 v1.15.3 on ☁️ markobaricevic3778@gmail.com 
❯ make test
go test -mod=readonly -tags='cgo ledger test_ledger_mock norace'  -run=none ./...

cc @alessio @robert-zaremba

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It introduces new jobs, but it doesn't change a way how you run tests. The new jobs are to compile and not runing any test.

Copy link
Member

@tac0turtle tac0turtle Oct 26, 2020

Choose a reason for hiding this comment

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

but the old command to run tests doesn't run tests, so it does change how you run tests.

Copy link
Contributor

Choose a reason for hiding this comment

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

@marbar3778 fix is here - mind opening a PR?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I will do it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

$(TEST_TARGETS): run-tests

# check-* compiles and collects tests without running them
# note: go test -c doesn't support multiple packages yet (https://github.com/golang/go/issues/15513)
CHECK_TEST_TARGETS := test-unit test-unit-amino
Copy link
Contributor

Choose a reason for hiding this comment

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

That's the offendling line @marbar3778, this should be:

CHECK_TEST_TARGETS := check-test-unit check-test-unit-amino

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ah, right. Sorry didn't notice. Wrong copy-paste 🤕

@alessio alessio mentioned this pull request Oct 26, 2020
9 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A:automerge Automatically merge PR once all prerequisites pass. T: Dev UX UX for SDK developers (i.e. how to call our code) T: Tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants