satellite/metabase/test: extend default time diff for comparison
Tests are intermittently fail with similar error: ``` --- FAIL: TestDeletePendingObject/Cockroach (15.85s) test.go:380: Error Trace: test.go:380 delete_test.go:221 Error: Should be zero, but was metabase.DeleteObjectResult{ Objects: []metabase.Object{ { ObjectStream: {ProjectID: {0x0f, 0x40, 0x70, 0x41, ...}, BucketName: "txxywyg4", ObjectKey: "\xbb+$\x17\x80\xc6\xcaC\xa3\xdb\xc3z*\xa8\xbe\xaf", Version: 1, ...}, - CreatedAt: s"2022-05-20 14:40:15.995376773 +0200 CEST", + CreatedAt: s"2022-05-20 14:40:21.04949 +0200 CEST", ExpiresAt: nil, Status: 1, ... // 9 identical fields }, }, Segments: {{RootPieceID: {0x01, 0x00, 0x00, 0x00, ...}, Pieces: {{...}}}, {RootPieceID: {0x01, 0x00, 0x00, 0x00, ...}, Pieces: {{...}}}}, } Test: TestDeletePendingObject/Cockroach/with_segments --- FAIL: TestDeletePendingObject/Cockroach/with_segments (0.68s) ``` Looks like we shouldn't have an assumption that all tests can be finished in 5 seconds, especially not in highly parallel environment. These tests use `time.Now` at the beginning and compare the time saved in the database (usually filled by the database). The difference shouldn't be higher than 20 seconds (before this commit: 5 seconds) which assumes that the records are saved in this timeframe... Change-Id: Ia6f52897d13f88c6857c05d728bf8e72ab863c9b
This commit is contained in:
parent
99237d5c78
commit
31560c94f8
@ -43,7 +43,7 @@ func (step Verify) Check(ctx *testcontext.Context, t testing.TB, db *metabase.DB
|
||||
sortRawCopies(step.Copies)
|
||||
|
||||
diff := cmp.Diff(metabase.RawState(step), *state,
|
||||
cmpopts.EquateApproxTime(5*time.Second),
|
||||
DefaultTimeDiff(),
|
||||
cmpopts.EquateEmpty())
|
||||
require.Zero(t, diff)
|
||||
}
|
||||
@ -92,3 +92,8 @@ func checkError(t testing.TB, err error, errClass *errs.Class, errText string) {
|
||||
require.NoError(t, err)
|
||||
}
|
||||
}
|
||||
|
||||
// DefaultTimeDiff is the central place to adjust test sql "timeout" (accepted diff between start and end of the test).
|
||||
func DefaultTimeDiff() cmp.Option {
|
||||
return cmpopts.EquateApproxTime(20 * time.Second)
|
||||
}
|
||||
|
@ -193,7 +193,7 @@ func (step GetObjectExactVersion) Check(ctx *testcontext.Context, t testing.TB,
|
||||
result, err := db.GetObjectExactVersion(ctx, step.Opts)
|
||||
checkError(t, err, step.ErrClass, step.ErrText)
|
||||
|
||||
diff := cmp.Diff(step.Result, result, cmpopts.EquateApproxTime(5*time.Second))
|
||||
diff := cmp.Diff(step.Result, result, DefaultTimeDiff())
|
||||
require.Zero(t, diff)
|
||||
}
|
||||
|
||||
@ -210,7 +210,7 @@ func (step GetSegmentByPosition) Check(ctx *testcontext.Context, t testing.TB, d
|
||||
result, err := db.GetSegmentByPosition(ctx, step.Opts)
|
||||
checkError(t, err, step.ErrClass, step.ErrText)
|
||||
|
||||
diff := cmp.Diff(step.Result, result, cmpopts.EquateApproxTime(5*time.Second))
|
||||
diff := cmp.Diff(step.Result, result, DefaultTimeDiff())
|
||||
require.Zero(t, diff)
|
||||
}
|
||||
|
||||
@ -227,7 +227,7 @@ func (step GetLatestObjectLastSegment) Check(ctx *testcontext.Context, t testing
|
||||
result, err := db.GetLatestObjectLastSegment(ctx, step.Opts)
|
||||
checkError(t, err, step.ErrClass, step.ErrText)
|
||||
|
||||
diff := cmp.Diff(step.Result, result, cmpopts.EquateApproxTime(5*time.Second))
|
||||
diff := cmp.Diff(step.Result, result, DefaultTimeDiff())
|
||||
require.Zero(t, diff)
|
||||
}
|
||||
|
||||
@ -264,7 +264,7 @@ func (step ListSegments) Check(ctx *testcontext.Context, t testing.TB, db *metab
|
||||
return
|
||||
}
|
||||
|
||||
diff := cmp.Diff(step.Result, result, cmpopts.EquateApproxTime(5*time.Second))
|
||||
diff := cmp.Diff(step.Result, result, DefaultTimeDiff())
|
||||
require.Zero(t, diff)
|
||||
}
|
||||
|
||||
@ -281,7 +281,7 @@ func (step ListStreamPositions) Check(ctx *testcontext.Context, t testing.TB, db
|
||||
result, err := db.ListStreamPositions(ctx, step.Opts)
|
||||
checkError(t, err, step.ErrClass, step.ErrText)
|
||||
|
||||
diff := cmp.Diff(step.Result, result, cmpopts.EquateApproxTime(5*time.Second))
|
||||
diff := cmp.Diff(step.Result, result, DefaultTimeDiff())
|
||||
require.Zero(t, diff)
|
||||
}
|
||||
|
||||
@ -330,7 +330,7 @@ func (step IterateLoopSegments) Check(ctx *testcontext.Context, t testing.TB, db
|
||||
sort.Slice(step.Result, func(i, j int) bool {
|
||||
return bytes.Compare(step.Result[i].StreamID[:], step.Result[j].StreamID[:]) < 0
|
||||
})
|
||||
diff := cmp.Diff(step.Result, result, cmpopts.EquateApproxTime(5*time.Second))
|
||||
diff := cmp.Diff(step.Result, result, DefaultTimeDiff())
|
||||
require.Zero(t, diff)
|
||||
}
|
||||
|
||||
@ -353,7 +353,7 @@ func (step DeleteObjectExactVersion) Check(ctx *testcontext.Context, t testing.T
|
||||
sortDeletedSegments(result.Segments)
|
||||
sortDeletedSegments(step.Result.Segments)
|
||||
|
||||
diff := cmp.Diff(step.Result, result, cmpopts.EquateApproxTime(5*time.Second), cmpopts.EquateEmpty())
|
||||
diff := cmp.Diff(step.Result, result, DefaultTimeDiff(), cmpopts.EquateEmpty())
|
||||
require.Zero(t, diff)
|
||||
}
|
||||
|
||||
@ -376,7 +376,7 @@ func (step DeletePendingObject) Check(ctx *testcontext.Context, t testing.TB, db
|
||||
sortDeletedSegments(result.Segments)
|
||||
sortDeletedSegments(step.Result.Segments)
|
||||
|
||||
diff := cmp.Diff(step.Result, result, cmpopts.EquateApproxTime(5*time.Second))
|
||||
diff := cmp.Diff(step.Result, result, DefaultTimeDiff())
|
||||
require.Zero(t, diff)
|
||||
}
|
||||
|
||||
@ -399,7 +399,7 @@ func (step DeleteObjectAnyStatusAllVersions) Check(ctx *testcontext.Context, t t
|
||||
sortDeletedSegments(result.Segments)
|
||||
sortDeletedSegments(step.Result.Segments)
|
||||
|
||||
diff := cmp.Diff(step.Result, result, cmpopts.EquateApproxTime(5*time.Second))
|
||||
diff := cmp.Diff(step.Result, result, DefaultTimeDiff())
|
||||
require.Zero(t, diff)
|
||||
}
|
||||
|
||||
@ -422,7 +422,7 @@ func (step DeleteObjectsAllVersions) Check(ctx *testcontext.Context, t testing.T
|
||||
sortDeletedSegments(result.Segments)
|
||||
sortDeletedSegments(step.Result.Segments)
|
||||
|
||||
diff := cmp.Diff(step.Result, result, cmpopts.EquateApproxTime(5*time.Second))
|
||||
diff := cmp.Diff(step.Result, result, DefaultTimeDiff())
|
||||
require.Zero(t, diff)
|
||||
}
|
||||
|
||||
@ -500,7 +500,7 @@ func (step IterateObjects) Check(ctx *testcontext.Context, t testing.TB, db *met
|
||||
sort.Slice(result, func(i, j int) bool {
|
||||
return result[i].ObjectKey < result[j].ObjectKey
|
||||
})
|
||||
diff := cmp.Diff(step.Result, result, cmpopts.EquateApproxTime(5*time.Second))
|
||||
diff := cmp.Diff(step.Result, result, DefaultTimeDiff())
|
||||
require.Zero(t, diff)
|
||||
}
|
||||
|
||||
@ -522,7 +522,7 @@ func (step IteratePendingObjectsByKey) Check(ctx *testcontext.Context, t *testin
|
||||
|
||||
result := []metabase.ObjectEntry(collector)
|
||||
|
||||
diff := cmp.Diff(step.Result, result, cmpopts.EquateApproxTime(5*time.Second))
|
||||
diff := cmp.Diff(step.Result, result, DefaultTimeDiff())
|
||||
require.Zero(t, diff)
|
||||
}
|
||||
|
||||
@ -542,7 +542,7 @@ func (step IterateObjectsWithStatus) Check(ctx *testcontext.Context, t testing.T
|
||||
err := db.IterateObjectsAllVersionsWithStatus(ctx, step.Opts, result.Add)
|
||||
checkError(t, err, step.ErrClass, step.ErrText)
|
||||
|
||||
diff := cmp.Diff(step.Result, []metabase.ObjectEntry(result), cmpopts.EquateApproxTime(5*time.Second))
|
||||
diff := cmp.Diff(step.Result, []metabase.ObjectEntry(result), DefaultTimeDiff())
|
||||
require.Zero(t, diff)
|
||||
}
|
||||
|
||||
@ -562,7 +562,7 @@ func (step IterateLoopObjects) Check(ctx *testcontext.Context, t testing.TB, db
|
||||
err := db.IterateLoopObjects(ctx, step.Opts, result.Add)
|
||||
checkError(t, err, step.ErrClass, step.ErrText)
|
||||
|
||||
diff := cmp.Diff(step.Result, []metabase.LoopObjectEntry(result), cmpopts.EquateApproxTime(5*time.Second))
|
||||
diff := cmp.Diff(step.Result, []metabase.LoopObjectEntry(result), DefaultTimeDiff())
|
||||
require.Zero(t, diff)
|
||||
}
|
||||
|
||||
@ -672,7 +672,7 @@ func (step FinishCopyObject) Check(ctx *testcontext.Context, t testing.TB, db *m
|
||||
result, err := db.FinishCopyObject(ctx, step.Opts)
|
||||
checkError(t, err, step.ErrClass, step.ErrText)
|
||||
|
||||
diff := cmp.Diff(step.Result, result, cmpopts.EquateApproxTime(5*time.Second))
|
||||
diff := cmp.Diff(step.Result, result, DefaultTimeDiff())
|
||||
require.Zero(t, diff)
|
||||
return result
|
||||
}
|
||||
|
@ -8,7 +8,6 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
"github.com/google/go-cmp/cmp/cmpopts"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"storj.io/common/storj"
|
||||
@ -386,7 +385,7 @@ func TestUpdateSegmentPieces(t *testing.T) {
|
||||
segment = segments[0]
|
||||
|
||||
require.NoError(t, err)
|
||||
diff := cmp.Diff(expectedSegment, segment, cmpopts.EquateApproxTime(5*time.Second))
|
||||
diff := cmp.Diff(expectedSegment, segment, metabasetest.DefaultTimeDiff())
|
||||
require.Zero(t, diff)
|
||||
|
||||
segment, err = db.GetSegmentByPosition(ctx, metabase.GetSegmentByPosition{
|
||||
@ -394,7 +393,7 @@ func TestUpdateSegmentPieces(t *testing.T) {
|
||||
Position: metabase.SegmentPosition{Index: 0},
|
||||
})
|
||||
require.NoError(t, err)
|
||||
diff = cmp.Diff(expectedSegment, segment, cmpopts.EquateApproxTime(5*time.Second))
|
||||
diff = cmp.Diff(expectedSegment, segment, metabasetest.DefaultTimeDiff())
|
||||
require.Zero(t, diff)
|
||||
|
||||
metabasetest.Verify{
|
||||
|
Loading…
Reference in New Issue
Block a user