Skip to content

testutils: add infrastructure for reusable test fixtures#99624

Merged
craig[bot] merged 1 commit intocockroachdb:masterfrom
RaduBerinde:text-fixtures
Mar 30, 2023
Merged

testutils: add infrastructure for reusable test fixtures#99624
craig[bot] merged 1 commit intocockroachdb:masterfrom
RaduBerinde:text-fixtures

Conversation

@RaduBerinde
Copy link
Copy Markdown
Member

@RaduBerinde RaduBerinde commented Mar 27, 2023

Certain storage-related tests/benchmarks generate fixtures and attempt to reuse them across invocations. This is important because fixtures can be large and slow to generate; but more importantly the generation is non-deterministic and we want to use the exact same fixture when comparing benchmark data.

Currently the tests achieve this by using a .gitignored subdirectory inside the source tree. This does not work with bazel (which executes the test in a sandbox).

This commit addresses the issue by adding new test infrastructure for reusable fixtures. We use the user's .cache directory instead of the source tree (specifically $HOME/.cache/crdb-test-fixtures/...). For bazel, we make sure the path is available (and writable) in the sandbox and we pass the path to the test through an env var.

Fixes #83599.

Release note: None
Epic: none

@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

@RaduBerinde RaduBerinde force-pushed the text-fixtures branch 6 times, most recently from 27eb2da to fa91cd1 Compare March 27, 2023 21:43
Copy link
Copy Markdown
Contributor

@jbowens jbowens left a comment

Choose a reason for hiding this comment

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

:lgtm:

thanks for doing this! using make for these has been a nuisance

Reviewed 16 of 16 files at r1, all commit messages.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @erikgrinaker, @RaduBerinde, and @rickystewart)


pkg/testutils/testfixtures/test_fixtures.go line 99 at r1 (raw file):

	tb.Logf("generating fixture %q in %q", name, dir)
	generate(dir)
	if err := os.WriteFile(completedPath, []byte("foo"), 0755); err != nil {

maybe should we write the current timestamp to the file?

Copy link
Copy Markdown
Member Author

@RaduBerinde RaduBerinde left a comment

Choose a reason for hiding this comment

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

Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @erikgrinaker, @jbowens, and @rickystewart)


pkg/testutils/testfixtures/test_fixtures.go line 99 at r1 (raw file):

Previously, jbowens (Jackson Owens) wrote…

maybe should we write the current timestamp to the file?

Hehe, that same thought crossed my mind, but as I was doing it I realized the file will have a modification time anyway. Is there some other info we may want in there?

Copy link
Copy Markdown
Contributor

@jbowens jbowens left a comment

Choose a reason for hiding this comment

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

Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @erikgrinaker, @RaduBerinde, and @rickystewart)


pkg/testutils/testfixtures/test_fixtures.go line 99 at r1 (raw file):

Previously, RaduBerinde wrote…

Hehe, that same thought crossed my mind, but as I was doing it I realized the file will have a modification time anyway. Is there some other info we may want in there?

:) good point. I think ideally we'd have the git SHA that built the fixture, but I don't think we have that available during test builds anymore. Can't think of anything else.

@RaduBerinde
Copy link
Copy Markdown
Member Author

@rickystewart could I get a review of the cmd/dev changes?

Copy link
Copy Markdown
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.

Benchmarks run in CI. Do any of the scripts in build/teamcity need to updated accordingly to give the benchmarks write-access to the cache directory?

args = append(args, "--test_sharding_strategy=disabled")
}

args = append(args, d.getGoTestEnvArgs()...)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks like this reusable fixture stuff is used for benchmarks rather than unit tests (which is the correct behavior as far as I can tell). Can you please add this extra argument to dev bench invocations and NOT dev test invocations?

Copy link
Copy Markdown
Member Author

@RaduBerinde RaduBerinde left a comment

Choose a reason for hiding this comment

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

The bench build inside Bazel Extended CI passed on this PR. I checked the logs from that build and we are using /home/roach/.cache/:

generating fixture "mvcc-fmtver_10-numKeys_100000-numVersions_2-valueBytes_8-numColFams_0-numRangeKeys_0-transactional_true" in "/home/roach/.cache/crdb-test-fixtures/mvcc-fmtver_10-numKeys_100000-numVersions_2-valueBytes_8-numColFams_0-numRangeKeys_0-transactional_true"

But I'm not sure how that works because bench_impl.sh doesn't pass the env flag or add .cache to the sandbox.. Any idea how it works? Perhaps they are not running inside a sandbox here?

In any case, note that if we are in a sandbox and the special env var isn't set, we fall back to using a temp dir (which would also be ok behavior for CI).

Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @erikgrinaker and @jbowens)

@rickystewart
Copy link
Copy Markdown
Collaborator

But I'm not sure how that works because bench_impl.sh doesn't pass the env flag or add .cache to the sandbox.. Any idea how it works? Perhaps they are not running inside a sandbox here?

Ah -- so in CI the benchmarks run with bazel run. This is unlike dev which uses bazel test for the same benchmarks. bazel test has this behavior where you cannot write to a directory unless you explicitly allow it, but bazel run does not.

Certain storage-related tests/benchmarks generate fixtures and attempt
to reuse them across invocations. This is important because fixtures
can be large and slow to generate; but more importantly the generation
is non-deterministic and we want to use the exact same fixture when
comparing benchmark data.

Currently the tests achieve this by using a `.gitignore`d subdirectory
inside the source tree. This does not work with bazel (which executes
the test in a sandbox).

This commit addresses the issue by adding new test infrastructure for
reusable fixtures. We use the user's `.cache` directory instead of the
source tree (specifically $HOME/.cache/crdb-test-fixtures/...).
For bazel, we make sure the path is available (and writable) in the
sandbox and we pass the path to the test through an env var.

Fixes cockroachdb#83599.

Release note: None
Epic: none
Copy link
Copy Markdown
Member Author

@RaduBerinde RaduBerinde left a comment

Choose a reason for hiding this comment

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

Cool, so we should be good. TFTR!

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (and 1 stale) (waiting on @erikgrinaker, @jbowens, and @rickystewart)


pkg/cmd/dev/test.go line 350 at r1 (raw file):

Previously, rickystewart (Ricky Stewart) wrote…

Looks like this reusable fixture stuff is used for benchmarks rather than unit tests (which is the correct behavior as far as I can tell). Can you please add this extra argument to dev bench invocations and NOT dev test invocations?

Done.

@RaduBerinde
Copy link
Copy Markdown
Member Author

bors r+

@craig craig bot merged commit 99b655d into cockroachdb:master Mar 30, 2023
@craig
Copy link
Copy Markdown
Contributor

craig bot commented Mar 30, 2023

Build succeeded:

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.

storage: MVCC benchmarks unreliable under Bazel

4 participants