satellite/metabasetest: include copies in raw state.
It can be useful to compare object copies created during unit tests. They appear in the segment_copies table as couple (stream_id, ancestor_stream_id). Change-Id: Id335c3ff7084fe30346456d27e670aff329154ea
This commit is contained in:
parent
9688c574b7
commit
5c7c4fedde
@ -377,6 +377,10 @@ func TestFinishCopyObject(t *testing.T) {
|
||||
metabase.RawObject(copyObj),
|
||||
},
|
||||
Segments: expectedSegments,
|
||||
Copies: []metabase.RawCopy{{
|
||||
StreamID: copyStream.StreamID,
|
||||
AncestorStreamID: originalObj.StreamID,
|
||||
}},
|
||||
}.Check(ctx, t, db)
|
||||
})
|
||||
})
|
||||
|
@ -39,6 +39,8 @@ func (step Verify) Check(ctx *testcontext.Context, t testing.TB, db *metabase.DB
|
||||
sortRawObjects(step.Objects)
|
||||
sortRawSegments(state.Segments)
|
||||
sortRawSegments(step.Segments)
|
||||
sortRawCopies(state.Copies)
|
||||
sortRawCopies(step.Copies)
|
||||
|
||||
diff := cmp.Diff(metabase.RawState(step), *state,
|
||||
cmpopts.EquateApproxTime(5*time.Second))
|
||||
@ -63,6 +65,12 @@ func sortRawSegments(segments []metabase.RawSegment) {
|
||||
})
|
||||
}
|
||||
|
||||
func sortRawCopies(copies []metabase.RawCopy) {
|
||||
sort.Slice(copies, func(i, j int) bool {
|
||||
return bytes.Compare(copies[i].StreamID[:], copies[j].StreamID[:]) < 0
|
||||
})
|
||||
}
|
||||
|
||||
func sortDeletedSegments(segments []metabase.DeletedSegmentInfo) {
|
||||
sort.Slice(segments, func(i, j int) bool {
|
||||
return bytes.Compare(segments[i].RootPieceID[:], segments[j].RootPieceID[:]) < 0
|
||||
|
@ -69,10 +69,17 @@ type RawSegment struct {
|
||||
Placement storj.PlacementConstraint
|
||||
}
|
||||
|
||||
// RawCopy contains a copy that is stored in the database.
|
||||
type RawCopy struct {
|
||||
StreamID uuid.UUID
|
||||
AncestorStreamID uuid.UUID
|
||||
}
|
||||
|
||||
// RawState contains full state of a table.
|
||||
type RawState struct {
|
||||
Objects []RawObject
|
||||
Segments []RawSegment
|
||||
Copies []RawCopy
|
||||
}
|
||||
|
||||
// TestingGetState returns the state of the database.
|
||||
@ -89,6 +96,11 @@ func (db *DB) TestingGetState(ctx context.Context) (_ *RawState, err error) {
|
||||
return nil, Error.New("GetState: %w", err)
|
||||
}
|
||||
|
||||
state.Copies, err = db.testingGetAllCopies(ctx)
|
||||
if err != nil {
|
||||
return nil, Error.New("GetState: %w", err)
|
||||
}
|
||||
|
||||
return state, nil
|
||||
}
|
||||
|
||||
@ -234,3 +246,38 @@ func (db *DB) testingGetAllSegments(ctx context.Context) (_ []RawSegment, err er
|
||||
}
|
||||
return segs, nil
|
||||
}
|
||||
|
||||
// testingGetAllCopies returns the state of the database.
|
||||
func (db *DB) testingGetAllCopies(ctx context.Context) (_ []RawCopy, err error) {
|
||||
copies := []RawCopy{}
|
||||
|
||||
rows, err := db.db.QueryContext(ctx, `
|
||||
SELECT
|
||||
stream_id, ancestor_stream_id
|
||||
FROM segment_copies
|
||||
ORDER BY stream_id ASC, ancestor_stream_id ASC
|
||||
`)
|
||||
if err != nil {
|
||||
return nil, Error.New("testingGetAllCopies query: %w", err)
|
||||
}
|
||||
defer func() { err = errs.Combine(err, rows.Close()) }()
|
||||
for rows.Next() {
|
||||
var copy RawCopy
|
||||
err := rows.Scan(
|
||||
©.StreamID,
|
||||
©.AncestorStreamID,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, Error.New("testingGetAllCopies scan failed: %w", err)
|
||||
}
|
||||
copies = append(copies, copy)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, Error.New("testingGetAllCopies scan failed: %w", err)
|
||||
}
|
||||
|
||||
if len(copies) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
return copies, nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user