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

dev: avoid re-generating logictest files if unnecessary #110735

Merged

Conversation

liamgillies
Copy link
Contributor

@liamgillies liamgillies commented Sep 15, 2023

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: #94845
Release note: None

@liamgillies liamgillies requested a review from a team as a code owner September 15, 2023 17:25
@blathers-crl
Copy link

blathers-crl bot commented Sep 15, 2023

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.

@cockroach-teamcity
Copy link
Member

This change is Reviewable

@liamgillies liamgillies force-pushed the avoid-rerunning-unchanged-tests branch from 5bb7c3e to 2ee5472 Compare September 15, 2023 17:26
Copy link
Collaborator

@rickystewart rickystewart left a 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.

@@ -97,6 +97,8 @@ func (d *dev) testlogic(cmd *cobra.Command, commandLine []string) error {
ignoreCache = true
}

changes, _ := d.exec.CommandContextSilent(ctx, "git", "status")
Copy link
Collaborator

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.

Copy link
Collaborator

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.

@rickystewart
Copy link
Collaborator

Beforehand, running dev testlogic would always run all tests regarldess if they were changed or not, which wastes time.

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.

@liamgillies liamgillies changed the title dev: avoid rerunning unchanged tests dev: avoid re-generating logictest files if unnecessary Sep 15, 2023
@liamgillies liamgillies force-pushed the avoid-rerunning-unchanged-tests branch from 2ee5472 to 973eabb Compare September 15, 2023 20:34
@@ -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")
Copy link
Collaborator

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.

if err != nil {
return err
}
if (shouldGen && !noGen) || forceGen {
Copy link
Collaborator

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.

@@ -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) {
Copy link
Collaborator

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.

// 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")
Copy link
Collaborator

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.

}
}
if upstream == "" {
return true, fmt.Errorf("could not find git upstream, run `git remote add upstream [email protected]:cockroachdb/cockroach.git`")
Copy link
Collaborator

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.

@liamgillies liamgillies force-pushed the avoid-rerunning-unchanged-tests branch from 973eabb to 8d750af Compare September 18, 2023 15:58
@@ -127,11 +131,18 @@ func (d *dev) testlogic(cmd *cobra.Command, commandLine []string) error {
return err
}

if !noGen {
if forceGen {
Copy link
Collaborator

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)) {
   ....
}

}

// This function retrieves the merge-base hash between the current branch and master
func (d *dev) getMergeBaseHash(ctx context.Context) (string, error) {
Copy link
Collaborator

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.

@liamgillies liamgillies force-pushed the avoid-rerunning-unchanged-tests branch 5 times, most recently from 2979aaa to 6ce4ad8 Compare September 18, 2023 18:15
if base == "" {
return true
}
changedFiles, _ := d.exec.CommandContextSilent(ctx, "git", "diff", "--no-ext-diff", "--name-only", base, "--", "**/logic_test/**", "**/execbuilder/testdata/**")
Copy link
Collaborator

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/**

Copy link
Contributor Author

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.

@liamgillies liamgillies force-pushed the avoid-rerunning-unchanged-tests branch from 6ce4ad8 to 37fc9ef Compare September 18, 2023 19:29
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
@liamgillies liamgillies force-pushed the avoid-rerunning-unchanged-tests branch from 37fc9ef to 9e653ae Compare September 18, 2023 20:02
@liamgillies
Copy link
Contributor Author

bors r=rickystewart

@craig
Copy link
Contributor

craig bot commented Sep 19, 2023

Build failed (retrying...):

@craig
Copy link
Contributor

craig bot commented Sep 19, 2023

Build succeeded:

@craig craig bot merged commit 3071cac into cockroachdb:master Sep 19, 2023
liamgillies pushed a commit to liamgillies/cockroach that referenced this pull request Sep 19, 2023
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
liamgillies pushed a commit to liamgillies/cockroach that referenced this pull request Sep 20, 2023
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
liamgillies pushed a commit to liamgillies/cockroach that referenced this pull request Sep 21, 2023
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
craig bot pushed a commit that referenced this pull request Sep 21, 2023
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

dev: detect when no new logic test files have been added and apply --no-gen
3 participants