[release-23.0] vttestserver: fail, don't panic, on a vschema missing a table or vindex (#20740) - #20744
[release-23.0] vttestserver: fail, don't panic, on a vschema missing a table or vindex (#20740)#20744vitess-bot[bot] wants to merge 2 commits into
Conversation
|
Hello @arthurschreiber, there are conflicts in this backport. Please address them in order to merge this Pull Request. You can execute the snippet below to reset your branch and resolve the conflict manually. Make sure you replace |
There was a problem hiding this comment.
Pull request overview
Note
Copilot could not run the full agentic suite for this review because it was automatically requested on a bot-authored pull request. Request a review from Copilot under Reviewers to retry with the full agentic suite. Improved support for bot-authored pull requests is coming soon.
This PR updates the vttestserver CLI tests to avoid panics when a vschema is missing expected entries, aiming to fail with clearer, assertion-based error messages instead.
Changes:
- Adds safer vschema lookups (table/vindex) prior to dereferencing to prevent nil-map-entry panics.
- Switches JSON unmarshal handling to
require.*-style assertions for immediate test failure. - Updates imports to support sorted/stable debug output for missing vschema keys.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| "context" | ||
| "fmt" | ||
| "io" | ||
| "maps" | ||
| "math/rand/v2" | ||
| "os/exec" | ||
| "path" | ||
| <<<<<<< HEAD | ||
| ||||||| parent of bf2a56ab9e (vttestserver: fail, don't panic, on a vschema missing a table or vindex (#20740)) | ||
| "strconv" | ||
| ======= | ||
| "slices" | ||
| "strconv" | ||
| >>>>>>> bf2a56ab9e (vttestserver: fail, don't panic, on a vschema missing a table or vindex (#20740)) | ||
| "strings" |
| err := vtctlclient.RunCommandAndWait(ctx, server, args, func(e *logutilpb.Event) { | ||
| var keyspace vschemapb.Keyspace | ||
| <<<<<<< HEAD | ||
| if err := protojson.Unmarshal([]byte(e.Value), &keyspace); err != nil { | ||
| t.Error(err) | ||
| } | ||
| ||||||| parent of bf2a56ab9e (vttestserver: fail, don't panic, on a vschema missing a table or vindex (#20740)) | ||
| if err := protojson.Unmarshal([]byte(e.Value), &keyspace); err != nil { | ||
| assert.NoError(t, err) | ||
| } | ||
| ======= | ||
| require.NoError(t, protojson.Unmarshal([]byte(e.Value), &keyspace)) | ||
|
|
||
| // Look the table and vindex up before dereferencing them, so that a | ||
| // vschema missing either fails with a message naming what was missing | ||
| // instead of panicking on a nil map entry and taking down the whole | ||
| // test binary. | ||
| table, ok := keyspace.Tables[expected.table] | ||
| require.Truef(t, ok, "keyspace %s has no table %s in its vschema, found tables %v", expected.keyspace, expected.table, slices.Sorted(maps.Keys(keyspace.Tables))) | ||
| require.NotEmptyf(t, table.ColumnVindexes, "table %s.%s has no column vindexes", expected.keyspace, expected.table) | ||
| columnVindex := table.ColumnVindexes[0] | ||
| require.NotEmptyf(t, columnVindex.Columns, "column vindex %s on %s.%s has no columns", columnVindex.Name, expected.keyspace, expected.table) | ||
|
|
||
| actualVindex, ok := keyspace.Vindexes[expected.vindex] | ||
| require.Truef(t, ok, "keyspace %s has no vindex %s in its vschema, found vindexes %v", expected.keyspace, expected.vindex, slices.Sorted(maps.Keys(keyspace.Vindexes))) | ||
| >>>>>>> bf2a56ab9e (vttestserver: fail, don't panic, on a vschema missing a table or vindex (#20740)) |
Signed-off-by: Arthur Schreiber <arthur@planetscale.com>
|
Resolved the committed conflicts in |
|
CI note: the |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4800f9d376
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| table, ok := keyspace.Tables[expected.table] | ||
| require.Truef(t, ok, "keyspace %s has no table %s in its vschema, found tables %v", expected.keyspace, expected.table, slices.Sorted(maps.Keys(keyspace.Tables))) |
There was a problem hiding this comment.
Add a regression test that reaches the missing-entry guards
Every caller still requests tables and vindexes present in the fixture, so these new branches are never exercised and the suite passes identically if the guards are reverted to the panicking implementation. Add a focused test that supplies a missing table and vindex and verifies that validation reports a test failure rather than panicking; otherwise CI does not prove the behavior this commit claims to fix.
AGENTS.md reference: AGENTS.md:L72-L73
Useful? React with 👍 / 👎.
|
This PR is being marked as stale because it has been open for 30 days with no activity. To rectify, you may do any of the following:
If no action is taken within 7 days, this PR will be closed. |
Description
This is a backport of #20740