@@ -25,6 +25,7 @@ import (
25
25
"github.com/cockroachdb/cockroach/pkg/util/leaktest"
26
26
"github.com/cockroachdb/cockroach/pkg/util/log"
27
27
"github.com/cockroachdb/errors"
28
+ "github.com/cockroachdb/redact"
28
29
"github.com/stretchr/testify/require"
29
30
)
30
31
@@ -144,6 +145,10 @@ func TestDetectIndexConsistencyErrors(t *testing.T) {
144
145
// expectedErrRegex is the regex pattern that the error message should match.
145
146
// If empty then no error is expected.
146
147
expectedErrRegex string
148
+ // expectedInternalErrorPatterns contains patterns for validating internal error details.
149
+ // Each element corresponds to the issue at the same index in expectedIssues.
150
+ // For non-internal-error issues, the corresponding element should be nil.
151
+ expectedInternalErrorPatterns []map [string ]string
147
152
}{
148
153
{
149
154
desc : "happy path sanity" ,
@@ -192,16 +197,24 @@ func TestDetectIndexConsistencyErrors(t *testing.T) {
192
197
expectedErrRegex : expectedInspectFoundInconsistencies ,
193
198
},
194
199
{
195
- desc : "2 ranges, secondary index on 'a', 1 dangling entry" ,
200
+ desc : "2 ranges, secondary index on 'a', 1 dangling entry with internal error " ,
196
201
splitRangeDDL : "ALTER TABLE test.t SPLIT AT VALUES (500)" ,
197
202
indexDDL : []string {
198
203
"CREATE INDEX idx_t_a ON test.t (a) STORING (f)" ,
199
204
},
200
205
danglingIndexEntryInsertQuery : "SELECT 3, 30, 300, 'd_3', 'e_3', -56.712" ,
201
- // TODO(148299): We eventually want to detect internal errors. Currently
202
- // this test passes by expecting the internal error pattern rather than
203
- // detecting the dangling entry.
204
- expectedErrRegex : "error decoding 6 bytes: float64 value should be exactly 8 bytes: 5" ,
206
+ expectedIssues : []inspectIssue {
207
+ {ErrorType : "internal_error" },
208
+ },
209
+ expectedErrRegex : expectedInspectFoundInconsistencies ,
210
+ expectedInternalErrorPatterns : []map [string ]string {
211
+ {
212
+ "error_message" : "error decoding.*float64" ,
213
+ "error_type" : "internal_query_error" ,
214
+ "index_name" : "idx_t_a" ,
215
+ "query" : "FROM.*table_" ,
216
+ },
217
+ },
205
218
},
206
219
{
207
220
desc : "2 ranges, secondary index on 'b' storing 'f', 1 dangling entry" ,
@@ -368,6 +381,28 @@ func TestDetectIndexConsistencyErrors(t *testing.T) {
368
381
require .NotEqual (t , 0 , foundIssue .SchemaID , "expected issue to have a schema ID: %s" , expectedIssue )
369
382
require .NotEqual (t , 0 , foundIssue .ObjectID , "expected issue to have an object ID: %s" , expectedIssue )
370
383
require .NotEqual (t , time.Time {}, foundIssue .AOST , "expected issue to have an AOST time: %s" , expectedIssue )
384
+
385
+ // Additional validation for internal errors
386
+ if foundIssue .ErrorType == "internal_error" {
387
+ require .NotNil (t , foundIssue .Details , "internal error should have details" )
388
+
389
+ // Validate patterns if provided for this specific issue
390
+ if tc .expectedInternalErrorPatterns != nil && i < len (tc .expectedInternalErrorPatterns ) &&
391
+ tc .expectedInternalErrorPatterns [i ] != nil {
392
+ expectedPatterns := tc .expectedInternalErrorPatterns [i ]
393
+
394
+ // Validate each expected pattern
395
+ for detailKey , expectedPattern := range expectedPatterns {
396
+ redactableKey := redact .RedactableString (detailKey )
397
+ require .Contains (t , foundIssue .Details , redactableKey , "internal error should contain detail key: %s" , detailKey )
398
+
399
+ detailValue , ok := foundIssue .Details [redactableKey ].(string )
400
+ require .True (t , ok , "detail value for key %s should be a string" , detailKey )
401
+ require .Regexp (t , expectedPattern , detailValue ,
402
+ "detail %s should match pattern %s, got: %s" , detailKey , expectedPattern , detailValue )
403
+ }
404
+ }
405
+ }
371
406
}
372
407
373
408
// Validate job status matches expected outcome
0 commit comments