mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-12 07:57:32 +00:00
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:
@@ -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)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
Reference in New Issue
Block a user