-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
dev: avoid re-generating logictest files if unnecessary #110735
dev: avoid re-generating logictest files if unnecessary #110735
Conversation
It looks like your PR touches production code but doesn't add or edit any test code. Did you consider adding tests to your PR? 🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf. |
5bb7c3e
to
2ee5472
Compare
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.
Let's tighten up the commit title a bit. avoid rerunning unchanged tests
is not the point of this PR. avoid re-generating logictest files if unnecessary
is closer, for example.
pkg/cmd/dev/testlogic.go
Outdated
@@ -97,6 +97,8 @@ func (d *dev) testlogic(cmd *cobra.Command, commandLine []string) error { | |||
ignoreCache = true | |||
} | |||
|
|||
changes, _ := d.exec.CommandContextSilent(ctx, "git", "status") |
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.
git status
reports the changed files on top of the currently-checked-out commit. This is not sufficient to accomplish what we want. For example, consider that I might make a change to the logic test files, then git commit
the result -- this wouldn't trigger since git status
won't report any changed files, but that's incorrect.
What we want to do is diff the changed files between the merge-base
and HEAD
. The function determineAffectedTargets()
demonstrates one way to do this. You will probably have to refactor that function into a different function to do the remote
parsing, the merge-base
calculation, and the diff
.
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 want to skip code generation if there are no updated relevant files. It has no bearing on which tests are run.
Actually, we are going to run the same set of tests either way, so this part of the commit message is not correct either. What we specifically want to do is skip code generation in this case. |
2ee5472
to
973eabb
Compare
pkg/cmd/dev/testlogic.go
Outdated
@@ -58,6 +60,7 @@ func makeTestLogicCmd(runE func(cmd *cobra.Command, args []string) error) *cobra | |||
testLogicCmd.Flags().Bool(showSQLFlag, false, "show SQL statements/queries immediately before they are tested") | |||
testLogicCmd.Flags().Bool(rewriteFlag, false, "rewrite test files using results from test run") | |||
testLogicCmd.Flags().Bool(noGenFlag, false, "skip generating logic test files before running logic tests") | |||
testLogicCmd.Flags().Bool(forceGenFlag, false, "skip generating logic test files before running logic tests") |
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.
Incorrect comment on the flag -- looks like a bad copy-paste.
pkg/cmd/dev/testlogic.go
Outdated
if err != nil { | ||
return err | ||
} | ||
if (shouldGen && !noGen) || forceGen { |
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.
If someone passes --no-gen
or --force-gen
, it's a big waste of time to perform the checks with git
. Instead, short-circuit if one of those flags is passed.
pkg/cmd/dev/testlogic.go
Outdated
@@ -297,6 +305,39 @@ func (d *dev) testlogic(cmd *cobra.Command, commandLine []string) error { | |||
return nil | |||
} | |||
|
|||
// This function determines if any test_logic or execbuilder/testdata files were | |||
// modified in the current branch, and if so, determines if we should re-generate logic tests. | |||
func (d *dev) shouldGen(ctx context.Context) (bool, error) { |
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.
Let's call this shouldGenerateLogicTests
or something -- shouldGen
is not descriptive enough.
pkg/cmd/dev/testlogic.go
Outdated
// modified in the current branch, and if so, determines if we should re-generate logic tests. | ||
func (d *dev) shouldGen(ctx context.Context) (bool, error) { | ||
// List files changed against `master`. | ||
remotes, err := d.exec.CommandContextSilent(ctx, "git", "remote", "-v") |
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.
There is lots of duplicated code with pkg/cmd/dev/test.go
. Please refactor into a helper function.
pkg/cmd/dev/testlogic.go
Outdated
} | ||
} | ||
if upstream == "" { | ||
return true, fmt.Errorf("could not find git upstream, run `git remote add upstream [email protected]:cockroachdb/cockroach.git`") |
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.
As discussed in DM: failures should probably be ignored rather than causing everything to fail. The tests don't literally need this optimization to run.
973eabb
to
8d750af
Compare
pkg/cmd/dev/testlogic.go
Outdated
@@ -127,11 +131,18 @@ func (d *dev) testlogic(cmd *cobra.Command, commandLine []string) error { | |||
return err | |||
} | |||
|
|||
if !noGen { | |||
if forceGen { |
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.
if !noGen {
if forceGen || d.shouldGenerateLogicTests(ctx) {
...
}
}
Just reduces some duplication to write the conditional this way. I suppose this is equivalent:
if !noGen && (forceGen || d.shouldGenerateLogicTests(ctx)) {
....
}
pkg/cmd/dev/testlogic.go
Outdated
} | ||
|
||
// This function retrieves the merge-base hash between the current branch and master | ||
func (d *dev) getMergeBaseHash(ctx context.Context) (string, error) { |
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.
Let's put this in util.go
as it is not specific to logic tests or any other specific subcommand.
2979aaa
to
6ce4ad8
Compare
pkg/cmd/dev/testlogic.go
Outdated
if base == "" { | ||
return true | ||
} | ||
changedFiles, _ := d.exec.CommandContextSilent(ctx, "git", "diff", "--no-ext-diff", "--name-only", base, "--", "**/logic_test/**", "**/execbuilder/testdata/**") |
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.
As mentioned in DM: use the list of files from build/bazelutil/bazel-generate.sh
so we're consistent with it.
if files_unchanged_from_upstream WORKSPACE $(find_relevant ./pkg/sql/logictest/logictestbase -name BUILD.bazel -or -name '*.go') $(find_relevant ./pkg/sql/logictest/testdata -name '*') $(find_relevant ./pkg/sql/sqlitelogictest -name BUILD.bazel -or -name '*.go') $(find_relevant ./pkg/ccl/logictestccl/testdata -name '*') $(find_relevant pkg/sql/opt/exec/execbuilder/testdata -name '*'); then
I translate that to the following git diff
command:
git diff ... -- pkg/sql/logictest/logictestbase/** pkg/sql/logictest/testdata/** pkg/sql/sqlitelogictest/BUILD.bazel pkg/sql/sqlitelogictest/sqlitelogictest.go pkg/ccl/logictestccl/testdata/** pkg/sql/opt/exec/execbuilder/testdata/**
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.
Oh sorry I was a little confused reading the DM -- thought you meant those files referred to the second option in avoiding failing unit tests. Fixed now.
6ce4ad8
to
37fc9ef
Compare
Beforehand, running `dev testlogic` would always run all tests regardless if they were modified, which wastes time. This PR will check to see if logic test folders were modified and only re-generates them if they are modified. It also introduces a new flag, `--force-gen`, which will force generate the logic tests. Fixes: cockroachdb#94845 Release note: None
37fc9ef
to
9e653ae
Compare
bors r=rickystewart |
Build failed (retrying...): |
Build succeeded: |
Beforehand, running a cross build inside a git worktree would always fail. This PR adds code to also mount the main git repo into docker when in a git worktree, so that running cross builds will succeed. Fixes: cockroachdb#110735 Release note: None
Beforehand, running a cross build inside a git worktree would always fail. This PR adds code to also mount the main git repo into docker when in a git worktree, so that running cross builds will succeed. Fixes: cockroachdb#110735 Release note: None
Beforehand, running a cross build inside a git worktree would always fail. This PR adds code to also mount the main git repo into docker when in a git worktree, so that running cross builds will succeed. Fixes: cockroachdb#110735 Release note: None
110919: kvcoord: Replace rangefeed catchup semaphore with rate limiter r=miretskiy a=miretskiy The catchup scan limit was added in #77725 in order to attempt to restrict a single rangefeed from consuming all catchup scan slots on the KV side. This client side limit has been largely ineffective. More recently, this semaphore has been coopted in #109346 in order to pace goroutine creation rate on the client. This functionality is important, but the implementation is not very good. Namely, we are interested in controling the rate of new catchup scans being started by the client (and thus, control the rate of goroutine creation). This implementation replaces the old implementation with rate limit based approach. The rate limits are configured using `kv.rangefeed.client.stream_startup_rate` setting which sets the rate on the number of newly established rangefeed streams (default 100). Closes #110439 Epic: CRDB-26372 Release note: None 110929: dev: fix cross builds running in git worktrees r=rickystewart a=liamgillies Beforehand, running a cross build inside a git worktree would always fail. This PR adds code to also mount the main git repo into docker when in a git worktree, so that running cross builds will succeed. Fixes: #110735 Release note: None Co-authored-by: Yevgeniy Miretskiy <[email protected]> Co-authored-by: Liam Gillies <[email protected]>
Beforehand, running
dev testlogic
would always run alltests regardless if they were modified, which wastes time.
This PR will check to see if logic test folders were modified
and only re-generates them if they are modified. It also
introduces a new flag,
--force-gen
, which will forcegenerate the logic tests.
Fixes: #94845
Release note: None