fix(eventstore): precise decimal (#8527)

# Which Problems Are Solved

Float64 which was used for the event.Position field is [not precise in
go and gets rounded](https://github.com/golang/go/issues/47300). This
can lead to unprecies position tracking of events and therefore
projections especially on cockcoachdb as the position used there is a
big number.

example of a unprecies position:
exact: 1725257931223002628
float64: 1725257931223002624.000000

# How the Problems Are Solved

The float64 was replaced by
[github.com/jackc/pgx-shopspring-decimal](https://github.com/jackc/pgx-shopspring-decimal).

# Additional Changes

Correct behaviour of makefile for load tests.
Rename `latestSequence`-queries to `latestPosition`
This commit is contained in:
Silvan
2024-09-06 11:19:19 +02:00
committed by GitHub
parent 2981ff04da
commit b522588d98
47 changed files with 319 additions and 215 deletions

View File

@@ -4,6 +4,8 @@ import (
"context"
"testing"
"github.com/shopspring/decimal"
"github.com/zitadel/zitadel/internal/eventstore"
)
@@ -98,7 +100,7 @@ func TestCRDB_Filter(t *testing.T) {
}
}
func TestCRDB_LatestSequence(t *testing.T) {
func TestCRDB_LatestPosition(t *testing.T) {
type args struct {
searchQuery *eventstore.SearchQueryBuilder
}
@@ -106,7 +108,7 @@ func TestCRDB_LatestSequence(t *testing.T) {
existingEvents []eventstore.Command
}
type res struct {
sequence float64
position decimal.Decimal
}
tests := []struct {
name string
@@ -118,7 +120,7 @@ func TestCRDB_LatestSequence(t *testing.T) {
{
name: "aggregate type filter no sequence",
args: args{
searchQuery: eventstore.NewSearchQueryBuilder(eventstore.ColumnsMaxSequence).
searchQuery: eventstore.NewSearchQueryBuilder(eventstore.ColumnsMaxPosition).
AddQuery().
AggregateTypes("not found").
Builder(),
@@ -135,7 +137,7 @@ func TestCRDB_LatestSequence(t *testing.T) {
{
name: "aggregate type filter sequence",
args: args{
searchQuery: eventstore.NewSearchQueryBuilder(eventstore.ColumnsMaxSequence).
searchQuery: eventstore.NewSearchQueryBuilder(eventstore.ColumnsMaxPosition).
AddQuery().
AggregateTypes(eventstore.AggregateType(t.Name())).
Builder(),
@@ -169,12 +171,12 @@ func TestCRDB_LatestSequence(t *testing.T) {
return
}
sequence, err := db.LatestSequence(context.Background(), tt.args.searchQuery)
position, err := db.LatestPosition(context.Background(), tt.args.searchQuery)
if (err != nil) != tt.wantErr {
t.Errorf("CRDB.query() error = %v, wantErr %v", err, tt.wantErr)
}
if tt.res.sequence > sequence {
t.Errorf("CRDB.query() expected sequence: %v got %v", tt.res.sequence, sequence)
if tt.res.position.GreaterThan(position) {
t.Errorf("CRDB.query() expected sequence: %v got %v", tt.res.position, position)
}
})
}