From 8d2c5239f669c94eb5dc2906a3b0542b4f2f158c Mon Sep 17 00:00:00 2001 From: Andrew Werner Date: Wed, 14 Dec 2022 10:43:46 -0500 Subject: [PATCH] roachtest: display diff when failing system upgrade test Before this change, failures would not show a diff like: ``` Diff: @@ -29,11 +29,11 @@ "lastUpdated" TIMESTAMP NOT NULL DEFAULT now():::TIMESTAMP, "valueType" STRING NULL, CONSTRAINT "primary" PRIMARY KEY (name ASC), FAMILY "fam_0_name_value_lastUpdated_valueType" (name, value, "lastUpdated", "valueType") ); -CREATE SEQUENCE public.descriptor_id_seq MINVALUE 1 MAXVALUE 9223372036854775807 INCREMENT 1 START 1; +CREATE SEQUENCE public.descriptor_id_seq MINVALUE 1 MAXVALUE 9223372036854775807 INCREMENT 1 START 104; CREATE TABLE public.tenants ( id INT8 NOT NULL, active BOOL NOT NULL DEFAULT true, info BYTES NULL, name STRING NULL AS (crdb_internal.pb_to_json('cockroach.sql.sqlbase.TenantInfo':::STRING, info)->>'name':::STRING) VIRTUAL, ---- ``` Release note: None --- pkg/cmd/roachtest/tests/BUILD.bazel | 1 + ...alidate_system_schema_after_version_upgrade.go | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/pkg/cmd/roachtest/tests/BUILD.bazel b/pkg/cmd/roachtest/tests/BUILD.bazel index f59224e9bcd2..0a26f35b743f 100644 --- a/pkg/cmd/roachtest/tests/BUILD.bazel +++ b/pkg/cmd/roachtest/tests/BUILD.bazel @@ -230,6 +230,7 @@ go_library( "@com_github_kr_pretty//:pretty", "@com_github_lib_pq//:pq", "@com_github_montanaflynn_stats//:stats", + "@com_github_pmezard_go_difflib//difflib", "@com_github_prometheus_client_golang//api", "@com_github_prometheus_client_golang//api/prometheus/v1:prometheus", "@com_github_prometheus_common//model", diff --git a/pkg/cmd/roachtest/tests/validate_system_schema_after_version_upgrade.go b/pkg/cmd/roachtest/tests/validate_system_schema_after_version_upgrade.go index 716593ea90e9..2e7ecd1099a6 100644 --- a/pkg/cmd/roachtest/tests/validate_system_schema_after_version_upgrade.go +++ b/pkg/cmd/roachtest/tests/validate_system_schema_after_version_upgrade.go @@ -20,6 +20,7 @@ import ( "github.com/cockroachdb/cockroach/pkg/cmd/roachtest/registry" "github.com/cockroachdb/cockroach/pkg/cmd/roachtest/test" "github.com/cockroachdb/cockroach/pkg/testutils/sqlutils" + "github.com/pmezard/go-difflib/difflib" ) func registerValidateSystemSchemaAfterVersionUpgrade(r registry.Registry) { @@ -85,8 +86,18 @@ func registerValidateSystemSchemaAfterVersionUpgrade(r registry.Registry) { validateEquivalenceStep := func(str1, str2 *string) versionStep { return func(ctx context.Context, t test.Test, u *versionUpgradeTest) { if *str1 != *str2 { - t.Fatal("After upgrading, `USE system; SHOW CREATE ALL TABLES;` " + - "does not match expected output after version upgrade.\n") + diff, diffErr := difflib.GetUnifiedDiffString(difflib.UnifiedDiff{ + A: difflib.SplitLines(*str1), + B: difflib.SplitLines(*str2), + Context: 5, + }) + if diffErr != nil { + diff = diffErr.Error() + t.Errorf("failed to produce diff: %v", diffErr) + } + t.Fatalf("After upgrading, `USE system; SHOW CREATE ALL TABLES;` "+ + "does not match expected output after version upgrade."+ + "\nDiff:\n%s", diff) } t.L().Printf("validating succeeded:\n%v", *str1) }