Skip to content

spanconfigkvaccessor: add datadriven tests for interface#71795

Merged
craig[bot] merged 1 commit intocockroachdb:masterfrom
irfansharif:211020.datadriven-kvaccessor
Oct 22, 2021
Merged

spanconfigkvaccessor: add datadriven tests for interface#71795
craig[bot] merged 1 commit intocockroachdb:masterfrom
irfansharif:211020.datadriven-kvaccessor

Conversation

@irfansharif
Copy link
Copy Markdown
Contributor

Makes it easier to reason about what's going on. We're also planning on
using these datadriven testing primitives when testing the KVSubscriber
(#69614).

Preview of what's ahead: In #69614 we'll issue these same datadriven
directives against a KVAccessor persisting state to an appropriate SQL
table. Given the KVSubscriber can maintain an up-to-date view over such
a table, we'll verify that it's receiving+propagating all the right span
updates, and that the exported view of a spanconfig.StoreReader has the
right span configs.

Release note: None

@irfansharif irfansharif requested a review from a team as a code owner October 21, 2021 03:29
@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

@blathers-crl
Copy link
Copy Markdown

blathers-crl bot commented Oct 21, 2021

Thank you for updating your pull request.

My owl senses detect your PR is good for review. Please keep an eye out for any test failures in CI.

🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is otan.

@blathers-crl blathers-crl bot added the O-community Originated from the community label Oct 21, 2021
@irfansharif irfansharif removed the O-community Originated from the community label Oct 21, 2021
@irfansharif irfansharif force-pushed the 211020.datadriven-kvaccessor branch 2 times, most recently from 4fa3429 to 1bbd626 Compare October 21, 2021 19:36
Copy link
Copy Markdown
Collaborator

@arulajmani arulajmani left a comment

Choose a reason for hiding this comment

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

This is neat! I mostly have nits and minor suggestions.

Reviewed 10 of 14 files at r1, all commit messages.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @ajwerner, @irfansharif, and @nvanbenschoten)


pkg/roachpb/span_config.go, line 20 at r1 (raw file):

// Equal compares two span config entries.
//lint:ignore U1001 unused

Let's get rid of this method entirely if it's unused.


pkg/spanconfig/spanconfigkvaccessor/datadriven_test.go, line 11 at r1 (raw file):

// licenses/APL.txt.

package spanconfigkvaccessor_test

Looking ahead, considering these directives will be used to test the KVSubscriber as well, should we move this file a level above to the spanconfig_test package?

spanconfigkvaccessor and spanconfigkvsubscriber can have maintain their own testadata directories that this thing can walk.


pkg/spanconfig/spanconfigkvaccessor/datadriven_test.go, line 22 at r1 (raw file):

	"github.com/cockroachdb/cockroach/pkg/roachpb"
	"github.com/cockroachdb/cockroach/pkg/spanconfig/spanconfigkvaccessor"
	sctestutils "github.com/cockroachdb/cockroach/pkg/spanconfig/spanconfigtestutils"

nit: I personally prefer spanconfigtestutils over sctestutils fwiw


pkg/spanconfig/spanconfigkvaccessor/datadriven_test.go, line 30 at r1 (raw file):

)

func TestDatadriven(t *testing.T) {

This is missing a comment describing the query language for this data-driven test.


pkg/spanconfig/spanconfigkvaccessor/datadriven_test.go, line 30 at r1 (raw file):

)

func TestDatadriven(t *testing.T) {

s/TestDatadriven/TestDataDriven/g


pkg/spanconfig/spanconfigkvaccessor/testdata/basic, line 27 at r1 (raw file):

span [b,d)
----
[a,b):D

Should we add a test for kvaccessor-get with partially overlapping and enclosed spans as well?


pkg/spanconfig/spanconfigkvaccessor/testdata/full, line 55 at r1 (raw file):

[d,e):D

# Verify that updating entries (including noops) show up as such

nit: fullstop


pkg/spanconfig/spanconfigkvaccessor/testdata/full, line 93 at r1 (raw file):

[d,e):x

# Attempts to delete non-existent spans should error out.

Let's add one where we try to upsert a span that overlaps with another span and ensure we error out.


pkg/spanconfig/spanconfigkvaccessor/testdata/full, line 108 at r1 (raw file):


# Verify that we're able to merge span configs correctly.
kvaccessor-update

It might be worth doing a kvaccessor-get before doing this update for readability -- the upsert semantics here which require us to delete [d,e) but not [c,d) are subtle.


pkg/spanconfig/spanconfigstore/store_test.go, line 22 at r1 (raw file):

	"github.com/cockroachdb/cockroach/pkg/roachpb"
	"github.com/cockroachdb/cockroach/pkg/spanconfig"
	testutils "github.com/cockroachdb/cockroach/pkg/spanconfig/spanconfigtestutils"

nit: s/testutils//

Makes it easier to reason about what's going on. We're also planning on
using these datadriven testing primitives when testing the KVSubscriber
(cockroachdb#69614).

Preview of what's ahead: In cockroachdb#69614 we'll issue these same datadriven
directives against a KVAccessor persisting state to an appropriate SQL
table. Given the KVSubscriber can maintain an up-to-date view over such
a table, we'll verify that it's receiving+propagating all the right span
updates, and that the exported view of a spanconfig.StoreReader has the
right span configs.

Release note: None
@irfansharif irfansharif force-pushed the 211020.datadriven-kvaccessor branch from 1bbd626 to 283d3ba Compare October 22, 2021 00:06
@irfansharif irfansharif requested a review from a team as a code owner October 22, 2021 00:06
Copy link
Copy Markdown
Contributor Author

@irfansharif irfansharif 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! 0 of 0 LGTMs obtained (waiting on @ajwerner, @arulajmani, and @nvanbenschoten)


pkg/roachpb/span_config.go, line 20 at r1 (raw file):

Previously, arulajmani (Arul Ajmani) wrote…

Let's get rid of this method entirely if it's unused.

Done.


pkg/spanconfig/spanconfigkvaccessor/datadriven_test.go, line 11 at r1 (raw file):

Previously, arulajmani (Arul Ajmani) wrote…

Looking ahead, considering these directives will be used to test the KVSubscriber as well, should we move this file a level above to the spanconfig_test package?

spanconfigkvaccessor and spanconfigkvsubscriber can have maintain their own testadata directories that this thing can walk.

Easy enough to do it in the PR that re-uses these components. I was actually thinking to just copy some of these methods over instead of making a package out of it -- it's just parsing code and is for a new datadriven test syntax anyway.


pkg/spanconfig/spanconfigkvaccessor/datadriven_test.go, line 22 at r1 (raw file):

Previously, arulajmani (Arul Ajmani) wrote…

nit: I personally prefer spanconfigtestutils over sctestutils fwiw

Sure, done.


pkg/spanconfig/spanconfigkvaccessor/datadriven_test.go, line 30 at r1 (raw file):

Previously, arulajmani (Arul Ajmani) wrote…

This is missing a comment describing the query language for this data-driven test.

Done.


pkg/spanconfig/spanconfigkvaccessor/datadriven_test.go, line 30 at r1 (raw file):

Previously, arulajmani (Arul Ajmani) wrote…

s/TestDatadriven/TestDataDriven/g

Done.


pkg/spanconfig/spanconfigkvaccessor/testdata/basic, line 27 at r1 (raw file):

Previously, arulajmani (Arul Ajmani) wrote…

Should we add a test for kvaccessor-get with partially overlapping and enclosed spans as well?

Done.


pkg/spanconfig/spanconfigkvaccessor/testdata/full, line 93 at r1 (raw file):

Previously, arulajmani (Arul Ajmani) wrote…

Let's add one where we try to upsert a span that overlaps with another span and ensure we error out.

Done.


pkg/spanconfig/spanconfigkvaccessor/testdata/full, line 108 at r1 (raw file):

Previously, arulajmani (Arul Ajmani) wrote…

It might be worth doing a kvaccessor-get before doing this update for readability -- the upsert semantics here which require us to delete [d,e) but not [c,d) are subtle.

Done.

Copy link
Copy Markdown
Collaborator

@arulajmani arulajmani left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewed 4 of 6 files at r2.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @ajwerner, @arulajmani, @irfansharif, and @nvanbenschoten)


pkg/cmd/dev/datadriven_test.go, line 40 at r2 (raw file):

// runnable through:
//
// 		go test -run TestDataDriven/<fname>

revert these?


pkg/spanconfig/spanconfigkvaccessor/datadriven_test.go, line 11 at r1 (raw file):

Previously, irfansharif (irfan sharif) wrote…

Easy enough to do it in the PR that re-uses these components. I was actually thinking to just copy some of these methods over instead of making a package out of it -- it's just parsing code and is for a new datadriven test syntax anyway.

No objections to handling this in a followup PR, though I think we can structure it in a way that avoids copying over some of these directives.


pkg/spanconfig/spanconfigkvaccessor/testdata/full, line 93 at r1 (raw file):

Previously, irfansharif (irfan sharif) wrote…

Done.

Is this done?

@irfansharif
Copy link
Copy Markdown
Contributor Author

AFK, but yeah added a new test file with the cases you suggested.

bors r+

@craig
Copy link
Copy Markdown
Contributor

craig bot commented Oct 22, 2021

Build succeeded:

@craig craig bot merged commit 1acebb5 into cockroachdb:master Oct 22, 2021
@irfansharif irfansharif deleted the 211020.datadriven-kvaccessor branch October 22, 2021 20:31
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.

3 participants