Add more test cases for kv range keys-only#21229
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: nwnt The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
7273c42 to
3c2e4b0
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted filessee 26 files with indirect coverage changes @@ Coverage Diff @@
## main #21229 +/- ##
==========================================
- Coverage 68.41% 68.39% -0.02%
==========================================
Files 429 429
Lines 35288 35291 +3
==========================================
- Hits 24142 24138 -4
- Misses 9751 9757 +6
- Partials 1395 1396 +1 Continue to review full report in Codecov by Sentry.
🚀 New features to boost your workflow:
|
tests/common/kv_test.go
Outdated
| slices.Reverse(reversedKvsKeysOnly) | ||
| allKvsSortedByValue := []*mvccpb.KeyValue{kvA, kvB, kvC, kvFoo, kvFooAbc, kvFop} | ||
| allKvsSortedByVersion := []*mvccpb.KeyValue{kvA, kvB, kvFoo, kvFooAbc, kvFop, kvC} | ||
| allKvsSortedByVersionDesc := append([]*mvccpb.KeyValue{kvC}, allKvsSortedByVersion[:5]...) |
There was a problem hiding this comment.
Not following how allKvsSortedByVersionDesc depends on allKvsSortedByVersion[:5]
There was a problem hiding this comment.
Sorting by version descending for version doesn't reverse the non-descending version, but it moves kvC which has the highest version to the front while leaving the rest, which all have the same version number, in tact.
I was thinking that having allKvsSortedByVersion[:5] maybe would tell what happen better, but if it's not then making it {kvC, kvA, kvB, kvFoo, kvFooAbc, kvFop} is better then. What do you think?
There was a problem hiding this comment.
Please not this should be readable and natural to humans. It's not obvious why SortedByVersion depends on SortedByVersionDesc. However this showed an separate interested property, how etcd sorts if the sorted key is constant across items.
There was a problem hiding this comment.
Removed this and used literals instead.
tests/common/kv_test.go
Outdated
| {name: "all KVs with maximimum create revision, sorted by value", begin: "", options: config.GetOptions{Prefix: true, MaxCreateRevision: int(firstRev) + 5, Order: clientv3.SortDescend, SortBy: clientv3.SortByValue}, wantResponse: &clientv3.GetResponse{Header: createHeader(firstRev + 7), Count: 6, Kvs: reverse(allKvsSortedByValue[:4])}}, | ||
| {name: "all KVs keys only, ascending", begin: "", options: config.GetOptions{Prefix: true, Order: clientv3.SortAscend, KeysOnly: true}, wantResponse: &clientv3.GetResponse{Header: createHeader(firstRev + 7), Count: 6, Kvs: dropValue(allKvs)}}, | ||
| {name: "all KVs keys only, descending", begin: "", options: config.GetOptions{Prefix: true, Order: clientv3.SortDescend, KeysOnly: true}, wantResponse: &clientv3.GetResponse{Header: createHeader(firstRev + 7), Count: 6, Kvs: dropValue(reversedKvs)}}, | ||
| {name: "all KVs keys only, sorted by value", begin: "", options: config.GetOptions{Prefix: true, SortBy: clientv3.SortByValue, KeysOnly: true}, wantResponse: &clientv3.GetResponse{Header: createHeader(firstRev + 7), Count: 6, Kvs: dropValue(allKvsSortedByValue)}}, | ||
| {name: "all KVs keys only, sorted by value descending", begin: "", options: config.GetOptions{Prefix: true, SortBy: clientv3.SortByValue, Order: clientv3.SortDescend, KeysOnly: true}, wantResponse: &clientv3.GetResponse{Header: createHeader(firstRev + 7), Count: 6, Kvs: dropValue(reverse(allKvsSortedByValue))}}, | ||
| {name: "all KVs keys only, sorted by value descending limit 2", begin: "", options: config.GetOptions{Prefix: true, SortBy: clientv3.SortByValue, Order: clientv3.SortDescend, KeysOnly: true, Limit: 2}, wantResponse: &clientv3.GetResponse{Header: createHeader(firstRev + 7), Count: 6, More: true, Kvs: dropValue(reverse(allKvsSortedByValue)[:2])}}, | ||
| {name: "all KVs keys only, sorted by version", begin: "", options: config.GetOptions{Prefix: true, SortBy: clientv3.SortByVersion, KeysOnly: true}, wantResponse: &clientv3.GetResponse{Header: createHeader(firstRev + 7), Count: 6, Kvs: dropValue(allKvsSortedByVersion)}}, | ||
| {name: "all KVs keys only, sorted by version descending", begin: "", options: config.GetOptions{Prefix: true, SortBy: clientv3.SortByVersion, Order: clientv3.SortDescend, KeysOnly: true}, wantResponse: &clientv3.GetResponse{Header: createHeader(firstRev + 7), Count: 6, Kvs: dropValue(allKvsSortedByVersionDesc)}}, | ||
| {name: "all KVs keys only, sorted by key", begin: "", options: config.GetOptions{Prefix: true, SortBy: clientv3.SortByKey, KeysOnly: true}, wantResponse: &clientv3.GetResponse{Header: createHeader(firstRev + 7), Count: 6, Kvs: dropValue(allKvs)}}, | ||
| {name: "all KVs keys only, sorted by key", begin: "", options: config.GetOptions{Prefix: true, SortBy: clientv3.SortByKey, Order: clientv3.SortDescend, KeysOnly: true}, wantResponse: &clientv3.GetResponse{Header: createHeader(firstRev + 7), Count: 6, Kvs: dropValue(reversedKvs)}}, | ||
| {name: "all KVs keys only, sorted by create rev", begin: "", options: config.GetOptions{Prefix: true, SortBy: clientv3.SortByCreateRevision, KeysOnly: true}, wantResponse: &clientv3.GetResponse{Header: createHeader(firstRev + 7), Count: 6, Kvs: dropValue(allKvs)}}, | ||
| {name: "all KVs keys only, sorted by create rev desc", begin: "", options: config.GetOptions{Prefix: true, SortBy: clientv3.SortByCreateRevision, Order: clientv3.SortDescend, KeysOnly: true}, wantResponse: &clientv3.GetResponse{Header: createHeader(firstRev + 7), Count: 6, Kvs: dropValue(reversedKvs)}}, | ||
| {name: "all KVs keys only, sorted by mod rev", begin: "", options: config.GetOptions{Prefix: true, SortBy: clientv3.SortByModRevision, KeysOnly: true}, wantResponse: &clientv3.GetResponse{Header: createHeader(firstRev + 7), Count: 6, Kvs: dropValue(allKvs)}}, | ||
| {name: "all KVs keys only, sorted by mod rev desc", begin: "", options: config.GetOptions{Prefix: true, SortBy: clientv3.SortByModRevision, Order: clientv3.SortDescend, KeysOnly: true}, wantResponse: &clientv3.GetResponse{Header: createHeader(firstRev + 7), Count: 6, Kvs: dropValue(reversedKvs)}}, | ||
| } |
There was a problem hiding this comment.
| {name: "all KVs with maximimum create revision, sorted by value", begin: "", options: config.GetOptions{Prefix: true, MaxCreateRevision: int(firstRev) + 5, Order: clientv3.SortDescend, SortBy: clientv3.SortByValue}, wantResponse: &clientv3.GetResponse{Header: createHeader(firstRev + 7), Count: 6, Kvs: reverse(allKvsSortedByValue[:4])}}, | |
| {name: "all KVs keys only, ascending", begin: "", options: config.GetOptions{Prefix: true, Order: clientv3.SortAscend, KeysOnly: true}, wantResponse: &clientv3.GetResponse{Header: createHeader(firstRev + 7), Count: 6, Kvs: dropValue(allKvs)}}, | |
| {name: "all KVs keys only, descending", begin: "", options: config.GetOptions{Prefix: true, Order: clientv3.SortDescend, KeysOnly: true}, wantResponse: &clientv3.GetResponse{Header: createHeader(firstRev + 7), Count: 6, Kvs: dropValue(reversedKvs)}}, | |
| {name: "all KVs keys only, sorted by value", begin: "", options: config.GetOptions{Prefix: true, SortBy: clientv3.SortByValue, KeysOnly: true}, wantResponse: &clientv3.GetResponse{Header: createHeader(firstRev + 7), Count: 6, Kvs: dropValue(allKvsSortedByValue)}}, | |
| {name: "all KVs keys only, sorted by value descending", begin: "", options: config.GetOptions{Prefix: true, SortBy: clientv3.SortByValue, Order: clientv3.SortDescend, KeysOnly: true}, wantResponse: &clientv3.GetResponse{Header: createHeader(firstRev + 7), Count: 6, Kvs: dropValue(reverse(allKvsSortedByValue))}}, | |
| {name: "all KVs keys only, sorted by value descending limit 2", begin: "", options: config.GetOptions{Prefix: true, SortBy: clientv3.SortByValue, Order: clientv3.SortDescend, KeysOnly: true, Limit: 2}, wantResponse: &clientv3.GetResponse{Header: createHeader(firstRev + 7), Count: 6, More: true, Kvs: dropValue(reverse(allKvsSortedByValue)[:2])}}, | |
| {name: "all KVs keys only, sorted by version", begin: "", options: config.GetOptions{Prefix: true, SortBy: clientv3.SortByVersion, KeysOnly: true}, wantResponse: &clientv3.GetResponse{Header: createHeader(firstRev + 7), Count: 6, Kvs: dropValue(allKvsSortedByVersion)}}, | |
| {name: "all KVs keys only, sorted by version descending", begin: "", options: config.GetOptions{Prefix: true, SortBy: clientv3.SortByVersion, Order: clientv3.SortDescend, KeysOnly: true}, wantResponse: &clientv3.GetResponse{Header: createHeader(firstRev + 7), Count: 6, Kvs: dropValue(allKvsSortedByVersionDesc)}}, | |
| {name: "all KVs keys only, sorted by key", begin: "", options: config.GetOptions{Prefix: true, SortBy: clientv3.SortByKey, KeysOnly: true}, wantResponse: &clientv3.GetResponse{Header: createHeader(firstRev + 7), Count: 6, Kvs: dropValue(allKvs)}}, | |
| {name: "all KVs keys only, sorted by key", begin: "", options: config.GetOptions{Prefix: true, SortBy: clientv3.SortByKey, Order: clientv3.SortDescend, KeysOnly: true}, wantResponse: &clientv3.GetResponse{Header: createHeader(firstRev + 7), Count: 6, Kvs: dropValue(reversedKvs)}}, | |
| {name: "all KVs keys only, sorted by create rev", begin: "", options: config.GetOptions{Prefix: true, SortBy: clientv3.SortByCreateRevision, KeysOnly: true}, wantResponse: &clientv3.GetResponse{Header: createHeader(firstRev + 7), Count: 6, Kvs: dropValue(allKvs)}}, | |
| {name: "all KVs keys only, sorted by create rev desc", begin: "", options: config.GetOptions{Prefix: true, SortBy: clientv3.SortByCreateRevision, Order: clientv3.SortDescend, KeysOnly: true}, wantResponse: &clientv3.GetResponse{Header: createHeader(firstRev + 7), Count: 6, Kvs: dropValue(reversedKvs)}}, | |
| {name: "all KVs keys only, sorted by mod rev", begin: "", options: config.GetOptions{Prefix: true, SortBy: clientv3.SortByModRevision, KeysOnly: true}, wantResponse: &clientv3.GetResponse{Header: createHeader(firstRev + 7), Count: 6, Kvs: dropValue(allKvs)}}, | |
| {name: "all KVs keys only, sorted by mod rev desc", begin: "", options: config.GetOptions{Prefix: true, SortBy: clientv3.SortByModRevision, Order: clientv3.SortDescend, KeysOnly: true}, wantResponse: &clientv3.GetResponse{Header: createHeader(firstRev + 7), Count: 6, Kvs: dropValue(reversedKvs)}}, | |
| } | |
| } | |
| testsWithKeysOnly := []struct{}{} | |
| for _, t := range tests { | |
| withKeyOnly := t | |
| withKeyOnly.options.KeysOnly = true | |
| withKeyOnly.wantResponse.Kvs = dropValue(withKeyOnly.wantResponse.Kvs) | |
| testsWithKeysOnly = append(testsWithKeysOnly, withKeyOnly) | |
| } | |
| tests = append(tests, testsWithKeysOnly...) |
Those test cases seem redundant.
There was a problem hiding this comment.
Thanks for this suggestion, it's really good. Had to debug some pointer issue, but should be good now.
Signed-off-by: Nont <nont@duck.com>
3c2e4b0 to
e0ba3bb
Compare
| withKeysOnly.wantResponse = &wantResponse | ||
| testsWithKeysOnly = append(testsWithKeysOnly, withKeysOnly) | ||
| } | ||
| for _, tt := range slices.Concat(tests, testsWithKeysOnly) { |
There was a problem hiding this comment.
Could you split the PR into smaller steps? There are to many changes at once to properly review it.
There was a problem hiding this comment.
Broke this down to two new PRs: one adding the sorting test cases, the other making the test cases do --keys-only.
|
@nwnt: The following tests failed, say
Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here. |
|
PR needs rebase. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
Part of #20386
cc @serathius - trying to improve the readability only for the newly added test cases. If this works better than #21227, I'll adopt this approach instead.