From 61742139e091a39075cd7e9c80a1a19105f3c615 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20M=C3=B6hlmann?= Date: Fri, 4 Aug 2023 19:17:16 +0300 Subject: [PATCH] fix: always update the timestamp in trigger (#6326) * always reset timestamp * re-enable test (cherry picked from commit 3c7b603650531e9cf69b70c93b38cd163cf12f52) --- .../api/grpc/management/user_integration_test.go | 12 +++++++++--- internal/eventstore/handler/handler_projection.go | 6 ++++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/internal/api/grpc/management/user_integration_test.go b/internal/api/grpc/management/user_integration_test.go index c1682a5ccc..ab1e149bda 100644 --- a/internal/api/grpc/management/user_integration_test.go +++ b/internal/api/grpc/management/user_integration_test.go @@ -5,11 +5,20 @@ package management_test import ( "context" "os" + "strconv" + "strings" "testing" "time" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "golang.org/x/text/language" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" + "github.com/zitadel/zitadel/internal/integration" "github.com/zitadel/zitadel/pkg/grpc/management" + "github.com/zitadel/zitadel/pkg/grpc/user" ) var ( @@ -38,8 +47,6 @@ func TestMain(m *testing.M) { // This test Imports a user and directly tries to Get it, 100 times in a loop. // When the bug still existed, some (between 1 to 7 out of 100) // Get calls would return a Not Found error. - -/* Test disabled because it breaks the pipeline. func TestImport_and_Get(t *testing.T) { const N = 100 var misses int @@ -84,4 +91,3 @@ func TestImport_and_Get(t *testing.T) { } assert.Zerof(t, misses, "Not Found errors %d out of %d", misses, N) } -*/ diff --git a/internal/eventstore/handler/handler_projection.go b/internal/eventstore/handler/handler_projection.go index baab2d3a61..dcd24b3d7b 100644 --- a/internal/eventstore/handler/handler_projection.go +++ b/internal/eventstore/handler/handler_projection.go @@ -140,8 +140,11 @@ func (h *ProjectionHandler) Trigger(ctx context.Context, instances ...string) co // by calling FetchEvents and Process until the amount of events is smaller than the BulkLimit. // If a bulk action was executed, the call timestamp in context will be reset for subsequent queries. // The returned context is never nil. It is either the original context or an updated context. -func (h *ProjectionHandler) TriggerErr(ctx context.Context, instances ...string) (context.Context, error) { +func (h *ProjectionHandler) TriggerErr(ctx context.Context, instances ...string) (outCtx context.Context, err error) { instances = triggerInstances(ctx, instances) + defer func() { + outCtx = call.ResetTimestamp(ctx) + }() for { events, hasLimitExceeded, err := h.FetchEvents(ctx, instances...) if err != nil { @@ -151,7 +154,6 @@ func (h *ProjectionHandler) TriggerErr(ctx context.Context, instances ...string) return ctx, nil } _, err = h.Process(ctx, events...) - ctx = call.ResetTimestamp(ctx) if err != nil { return ctx, err }