perf: query data AS OF SYSTEM TIME (#5231)

Queries the data in the storage layser at the timestamp when the call hit the API layer
This commit is contained in:
Silvan
2023-02-27 22:36:43 +01:00
committed by GitHub
parent 80003939ad
commit e38abdcdf3
170 changed files with 3101 additions and 3169 deletions

View File

@@ -9,6 +9,26 @@ import (
"testing"
)
var (
prepareFailedEventsStmt = `SELECT projections.failed_events.projection_name,` +
` projections.failed_events.failed_sequence,` +
` projections.failed_events.failure_count,` +
` projections.failed_events.last_failed,` +
` projections.failed_events.error,` +
` COUNT(*) OVER ()` +
` FROM projections.failed_events` +
` AS OF SYSTEM TIME '-1 ms'`
prepareFailedEventsCols = []string{
"projection_name",
"failed_sequence",
"failure_count",
"last_failed",
"error",
"count",
}
)
func Test_FailedEventsPrepares(t *testing.T) {
type want struct {
sqlExpectations sqlExpectation
@@ -25,13 +45,7 @@ func Test_FailedEventsPrepares(t *testing.T) {
prepare: prepareFailedEventsQuery,
want: want{
sqlExpectations: mockQueries(
regexp.QuoteMeta(`SELECT projections.failed_events.projection_name,`+
` projections.failed_events.failed_sequence,`+
` projections.failed_events.failure_count,`+
` projections.failed_events.last_failed,`+
` projections.failed_events.error,`+
` COUNT(*) OVER ()`+
` FROM projections.failed_events`),
regexp.QuoteMeta(prepareFailedEventsStmt),
nil,
nil,
),
@@ -43,21 +57,8 @@ func Test_FailedEventsPrepares(t *testing.T) {
prepare: prepareFailedEventsQuery,
want: want{
sqlExpectations: mockQueries(
regexp.QuoteMeta(`SELECT projections.failed_events.projection_name,`+
` projections.failed_events.failed_sequence,`+
` projections.failed_events.failure_count,`+
` projections.failed_events.last_failed,`+
` projections.failed_events.error,`+
` COUNT(*) OVER ()`+
` FROM projections.failed_events`),
[]string{
"projection_name",
"failed_sequence",
"failure_count",
"last_failed",
"error",
"count",
},
regexp.QuoteMeta(prepareFailedEventsStmt),
prepareFailedEventsCols,
[][]driver.Value{
{
"projection-name",
@@ -89,21 +90,8 @@ func Test_FailedEventsPrepares(t *testing.T) {
prepare: prepareFailedEventsQuery,
want: want{
sqlExpectations: mockQueries(
regexp.QuoteMeta(`SELECT projections.failed_events.projection_name,`+
` projections.failed_events.failed_sequence,`+
` projections.failed_events.failure_count,`+
` projections.failed_events.last_failed,`+
` projections.failed_events.error,`+
` COUNT(*) OVER ()`+
` FROM projections.failed_events`),
[]string{
"projection_name",
"failed_sequence",
"failure_count",
"last_failed",
"error",
"count",
},
regexp.QuoteMeta(prepareFailedEventsStmt),
prepareFailedEventsCols,
[][]driver.Value{
{
"projection-name",
@@ -148,13 +136,7 @@ func Test_FailedEventsPrepares(t *testing.T) {
prepare: prepareFailedEventsQuery,
want: want{
sqlExpectations: mockQueryErr(
regexp.QuoteMeta(`SELECT projections.failed_events.projection_name,`+
` projections.failed_events.failed_sequence,`+
` projections.failed_events.failure_count,`+
` projections.failed_events.last_failed,`+
` projections.failed_events.error,`+
` COUNT(*) OVER ()`+
` FROM projections.failed_events`),
regexp.QuoteMeta(prepareFailedEventsStmt),
sql.ErrConnDone,
),
err: func(err error) (error, bool) {
@@ -169,7 +151,7 @@ func Test_FailedEventsPrepares(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assertPrepare(t, tt.prepare, tt.object, tt.want.sqlExpectations, tt.want.err)
assertPrepare(t, tt.prepare, tt.object, tt.want.sqlExpectations, tt.want.err, defaultPrepareArgs...)
})
}
}