-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
importccl: Bazelify importccl test #56127
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks for trying it out Yevgeniy! TIL.
(Irrelevant aside, from https://cockroachlabs.atlassian.net/wiki/spaces/CRDB/pages/73072807/Git+Commit+Messages, for our commit titles I think we generally don't "end the title with a period".)
|
||
// RunningUnderBazel returns true if the test is executed by bazel. | ||
func RunningUnderBazel() bool { | ||
return os.Getenv(testSrcDirEnv) != "" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We've soured on using os.Getenv
directly in favor or envutil
.
pkg/testutils/bazel.go
Outdated
// If testSrcDirEnv is not set, it means we are not running under bazel, | ||
// and so we can use "" as our directory which should point to the | ||
// src root. | ||
return os.Getenv(testSrcDirEnv) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nit] Mild preference for explicitly returning an empty string if not running under bazel. We could just piggy back our newly added RunningUnderBazel
helper here. It would look similar to TestTempDir below.
DEPS.bzl
Outdated
sum = "h1:KQqSlwJmTr7NmxtVOl6nPNSZQEk8XuLoLyNDYcmniBo=", | ||
version = "v1.0.1-0.20200826112548-92602d883b11", | ||
sum = "h1:p4AOBShzCogHTl1n5Ff16j5a24tvk1lc7fzRqduSpKM=", | ||
version = "v1.0.1-0.20201022032720-3e27adf87325", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
James will take a look, thanks for picking it up: #56128
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @adityamaru, @irfansharif, @jlinder, and @miretskiy)
pkg/ccl/importccl/BUILD.bazel, line 110 at r2 (raw file):
Previously, otan (Oliver Tan) wrote…
i think gazelle only modifies some fields -- shard_count is not one of them given i don't see it as
MergeableAttrs
anywhere
Ahh.. Cool. I'll keep it off, but I'll leave the comment.
pkg/testutils/bazel.go, line 23 at r1 (raw file):
Previously, irfansharif (irfan sharif) wrote…
We've soured on using
os.Getenv
directly in favor orenvutil
.
Done.
pkg/testutils/bazel.go, line 45 at r1 (raw file):
Previously, irfansharif (irfan sharif) wrote…
[nit] Mild preference for explicitly returning an empty string if not running under bazel. We could just piggy back our newly added
RunningUnderBazel
helper here. It would look similar to TestTempDir below.
Done.
pkg/testutils/bazel.go, line 49 at r1 (raw file):
Previously, irfansharif (irfan sharif) wrote…
Am I correct in understanding that for any test running under bazel, we'll eventually want to use TestTempDir instead of just TempDir?
Correct.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @adityamaru, @irfansharif, @jlinder, @miretskiy, and @otan)
pkg/testutils/bazel.go, line 45 at r1 (raw file):
Previously, miretskiy (Yevgeniy Miretskiy) wrote…
Done.
Sorry... I decided to just use envutil directly... Don't like calling getenv on the same var if it can be helped.
df625e2
to
ad0321a
Compare
FYI: I reverted the use of envutil in favor of OS due to failing tests: https://teamcity.cockroachdb.com/buildConfiguration/Cockroach_UnitTests/2405846? |
a6922ef
to
45d13cb
Compare
@irfansharif Can you take another look? I had to make some changes to bazel.go |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM mod comments below. Thanks for breaking new ground here, I'm hopeful these testutils APIs will see further usage as we start measuring test times of other packages in earnest. +cc @alan-mas.
pkg/testutils/bazel.go
Outdated
if v := os.Getenv(env); v != "" { | ||
return v | ||
} | ||
panic("expected value for env " + env) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We generally avoid direct string concatenation (citations needed), in favor of something like
panic(errors.AssertionFailedf("missing env var: %s", env))
pkg/testutils/bazel.go
Outdated
// TestSrcDir returns the path to the "source" tree. | ||
// | ||
// If running under bazel, this will point to a private, *readonly* | ||
// directory containing symlinks (or copies) of the test data depencies. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/depencies/dependencies
pkg/testutils/bazel.go
Outdated
// TestDataPath returns a path to the directory containing test data files. | ||
// | ||
// Test files are usually checked into the repository under "testdata" directory. | ||
// If we are not using bazel, then the test executes with current working directory of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"executes in the directory of the actual tests"
pkg/testutils/bazel.go
Outdated
// the actual test, so the files can be referenced via "testdata/subdir/file" relative path. | ||
// | ||
// However, if we are running under bazel, the data files are specified | ||
// via go_test "data" attribute. These files, in turn, are available under run files directory. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"are available within the runfiles directory" (looks like it's one word: https://docs.bazel.build/versions/master/skylark/lib/runfiles.html)
pkg/testutils/bazel.go
Outdated
// | ||
// However, if we are running under bazel, the data files are specified | ||
// via go_test "data" attribute. These files, in turn, are available under run files directory. | ||
// This helper attempts to construct appropriate path to the run files directory |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
`s/run files/runfiles/
pkg/testutils/bazel.go
Outdated
func TestDataPath(relative ...string) string { | ||
if RunningUnderBazel() { | ||
pieces := append(bazelRelativeTargetPath(), relative...) | ||
return path.Join(TestSrcDir(), os.Getenv(testWorkspaceEnv), path.Join(pieces...)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we want to use requireEnv
here for testWorkspaceEnv
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feel free to ignore, but a comment reference to https://docs.bazel.build/versions/master/test-encyclopedia.html here would make this all a bit more friendly to future readers.
The initial working directory shall be $TEST_SRCDIR/$TEST_WORKSPACE.
pkg/testutils/bazel.go
Outdated
// Strip out leading package "//" | ||
target = strings.TrimPrefix(target, "//") | ||
|
||
// Strip out ":XXX" from the last component |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not split on ":", drop the last name, and then split on "/" to get the relative target path?
It would also make it easier to add a comment up top showing the transformation taking place here. If I've understood correctly, it's the following: //pkg/ccl/importccl:importccl_test -> pkg/ccl/importccl
(?).
I was actually a bit surprised that this was not something provided out of the box, or at least easier. I assume we've looked at https://docs.bazel.build/versions/master/test-encyclopedia.html#location and found it inapplicable?
//foo/bar:unittest is the directory
$(WORKSPACE)/$ (BINDIR)/foo/bar/unittest.runfiles
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Somewhat related, I couldn't find official documentation on it, but https://github.com/bazelbuild/bazel/blob/c266ac966761c4b3d8a408a03e407505c93effdd/tools/bash/runfiles/runfiles.bash#L57 has a reference to RUNFILES_DIR
. I'm curious if that would help. Feel free to ignore though.
Add a bazel testutils file to help tests use correct paths. Release Notes: None
Make importccl test hermetic by using correct directories and avoiding test data regeneration. Use 16 shards for the test to speed it up. Release Notes: None
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @adityamaru, @irfansharif, @jlinder, @miretskiy, and @otan)
pkg/testutils/bazel.go, line 34 at r4 (raw file):
Previously, irfansharif (irfan sharif) wrote…
We generally avoid direct string concatenation (citations needed), in favor of something like
panic(errors.AssertionFailedf("missing env var: %s", env))
Ty. Done.
pkg/testutils/bazel.go, line 40 at r4 (raw file):
Previously, irfansharif (irfan sharif) wrote…
s/depencies/dependencies
Done.
pkg/testutils/bazel.go, line 74 at r4 (raw file):
Previously, irfansharif (irfan sharif) wrote…
Somewhat related, I couldn't find official documentation on it, but https://github.com/bazelbuild/bazel/blob/c266ac966761c4b3d8a408a03e407505c93effdd/tools/bash/runfiles/runfiles.bash#L57 has a reference to
RUNFILES_DIR
. I'm curious if that would help. Feel free to ignore though.
Re splitting: You're right -- i'm trying to transform //pkg/cmd/foo:bar -> pkg/cmd/foo.
I was worried about path containing multiple ":", but that would break many things...
So, yeah, thanks for the suggestion -- changed. I actually, don't even need to split on "/".
Just return that as a string ("pkg/ccl/...")
Yeah -- I tried not to use things not mentioned explicitly in the test encyclopedial.
Added large comment block with the above link.
pkg/testutils/bazel.go, line 89 at r4 (raw file):
Previously, irfansharif (irfan sharif) wrote…
"executes in the directory of the actual tests"
Done
pkg/testutils/bazel.go, line 93 at r4 (raw file):
Previously, irfansharif (irfan sharif) wrote…
"are available within the runfiles directory" (looks like it's one word: https://docs.bazel.build/versions/master/skylark/lib/runfiles.html)
Added large comment block on top to introduce the concept of RUNFILES.
pkg/testutils/bazel.go, line 94 at r4 (raw file):
Previously, irfansharif (irfan sharif) wrote…
`s/run files/runfiles/
Done.
pkg/testutils/bazel.go, line 99 at r4 (raw file):
https://docs.bazel.build/versions/master/test-encyclopedia.html
I could have used requireEnv... It's just for whatever reason, WORKSPACE is marked optional.
Though, I suppose, for all intents and purposes it should exist in our environment.
Changed to requireEnv.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 1 of 5 files at r3, 1 of 4 files at r5.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @adityamaru, @irfansharif, @jlinder, @miretskiy, and @otan)
bors r+ |
Build succeeded: |
Make importccl test hermetic by using correct directories
and avoiding test data regeneration.
Use 16 shards for the test to speed it up.
Release Notes: None