mirror of
https://github.com/zitadel/zitadel.git
synced 2025-12-07 07:16:54 +00:00
fix(projections): added check to make sure there cannot be 2 projections for the same table (#10439)
# Which Problems Are Solved
It should not be possible to start 2 projections with the same name.
If this happens, it can cause issues with the event store such as events
being skipped/unprocessed and can be very hard/time-consuming to
diagnose.
# How the Problems Are Solved
A check was added to make sure no 2 projections have the same table
Closes https://github.com/zitadel/zitadel/issues/10453
---------
Co-authored-by: Silvan <27845747+adlerhurst@users.noreply.github.com>
(cherry picked from commit 10bd747105)
This commit is contained in:
69
internal/query/projection/projection_test.go
Normal file
69
internal/query/projection/projection_test.go
Normal file
@@ -0,0 +1,69 @@
|
||||
package projection
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/brianvoe/gofakeit/v6"
|
||||
"github.com/stretchr/testify/require"
|
||||
gomock "go.uber.org/mock/gomock"
|
||||
)
|
||||
|
||||
func TestStart(t *testing.T) {
|
||||
duplicateName := gofakeit.Name()
|
||||
tests := []struct {
|
||||
name string
|
||||
projections func(t *testing.T) []projection
|
||||
err error
|
||||
}{
|
||||
{
|
||||
name: "happy path",
|
||||
projections: func(t *testing.T) []projection {
|
||||
ctrl := gomock.NewController(t)
|
||||
projections := make([]projection, 5)
|
||||
|
||||
for i := range 5 {
|
||||
mock := NewMockprojection(ctrl)
|
||||
mock.EXPECT().Start(gomock.Any())
|
||||
mock.EXPECT().String().Return(gofakeit.Name())
|
||||
projections[i] = mock
|
||||
}
|
||||
|
||||
return projections
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "same projection used twice error",
|
||||
projections: func(t *testing.T) []projection {
|
||||
projections := make([]projection, 5)
|
||||
|
||||
ctrl := gomock.NewController(t)
|
||||
mock := NewMockprojection(ctrl)
|
||||
mock.EXPECT().String().Return(duplicateName)
|
||||
mock.EXPECT().Start(gomock.Any())
|
||||
projections[0] = mock
|
||||
|
||||
for i := 1; i < 4; i++ {
|
||||
mock := NewMockprojection(ctrl)
|
||||
mock.EXPECT().String().Return(gofakeit.Name())
|
||||
mock.EXPECT().Start(gomock.Any())
|
||||
projections[i] = mock
|
||||
}
|
||||
|
||||
mock = NewMockprojection(ctrl)
|
||||
mock.EXPECT().String().Return(duplicateName)
|
||||
projections[4] = mock
|
||||
|
||||
return projections
|
||||
},
|
||||
err: fmt.Errorf("projeciton for %s already added", duplicateName),
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
projections = tt.projections(t)
|
||||
err := Start(t.Context())
|
||||
require.Equal(t, tt.err, err)
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user