From 0337a861ba74eda4e560920d7bf7904a648c48e1 Mon Sep 17 00:00:00 2001 From: Stefan Benz <46600784+stebenz@users.noreply.github.com> Date: Thu, 20 Mar 2025 07:47:19 +0100 Subject: [PATCH] test: correct notifications integration test with eventual consistency (#9569) # Which Problems Are Solved Quota notification integration test failed sometimes due to eventual consistency issues, which resulted in calls which should have been counted to the quota not being added. This resulted in flaky integration tests as the expected API calls to be limited were executed normally. # How the Problems Are Solved As there is no API call to query the currently applied Quota, there was a sleep added as a last effort, to give some time that the event gets processed into the projection. # Additional Changes None # Additional Context Related to https://github.com/zitadel/zitadel/actions/runs/13922326003/job/38959595055 Co-authored-by: Livio Spring (cherry picked from commit 5ca76af7790769273ee0e27375510b78b37e859e) --- .../quotas_enabled/quota_test.go | 62 +++++++------------ 1 file changed, 22 insertions(+), 40 deletions(-) diff --git a/internal/api/grpc/system/integration_test/quotas_enabled/quota_test.go b/internal/api/grpc/system/integration_test/quotas_enabled/quota_test.go index 09c42eeb97..e11169421d 100644 --- a/internal/api/grpc/system/integration_test/quotas_enabled/quota_test.go +++ b/internal/api/grpc/system/integration_test/quotas_enabled/quota_test.go @@ -31,27 +31,10 @@ func TestServer_QuotaNotification_Limit(t *testing.T) { percent := 50 percentAmount := amount * percent / 100 - _, err := integration.SystemClient().SetQuota(CTX, &system.SetQuotaRequest{ - InstanceId: instance.Instance.Id, - Unit: quota_pb.Unit_UNIT_REQUESTS_ALL_AUTHENTICATED, - From: timestamppb.Now(), - ResetInterval: durationpb.New(time.Minute * 5), - Amount: uint64(amount), - Limit: true, - Notifications: []*quota_pb.Notification{ - { - Percent: uint32(percent), - Repeat: true, - CallUrl: callURL, - }, - { - Percent: 100, - Repeat: true, - CallUrl: callURL, - }, - }, + setQuota(t, instance.Instance.Id, amount, true, []*quota_pb.Notification{ + {Percent: uint32(percent), Repeat: true, CallUrl: callURL}, + {Percent: 100, Repeat: true, CallUrl: callURL}, }) - require.NoError(t, err) sub := sink.Subscribe(CTX, sink.ChannelQuota) defer sub.Close() @@ -72,6 +55,22 @@ func TestServer_QuotaNotification_Limit(t *testing.T) { require.Error(t, limitErr) } +func setQuota(t *testing.T, instanceID string, amount int, limit bool, notifications []*quota_pb.Notification) { + _, err := integration.SystemClient().SetQuota(CTX, &system.SetQuotaRequest{ + InstanceId: instanceID, + Unit: quota_pb.Unit_UNIT_REQUESTS_ALL_AUTHENTICATED, + From: timestamppb.Now(), + ResetInterval: durationpb.New(time.Minute * 5), + Amount: uint64(amount), + Limit: limit, + Notifications: notifications, + }) + require.NoError(t, err) + + // wait for some time as there is an eventual consistency until the quota is applied and used in the interceptor + time.Sleep(time.Second * 5) +} + func TestServer_QuotaNotification_NoLimit(t *testing.T) { instance := integration.NewInstance(CTX) iamCTX := instance.WithAuthorization(CTX, integration.UserTypeIAMOwner) @@ -80,27 +79,10 @@ func TestServer_QuotaNotification_NoLimit(t *testing.T) { percent := 50 percentAmount := amount * percent / 100 - _, err := integration.SystemClient().SetQuota(CTX, &system.SetQuotaRequest{ - InstanceId: instance.Instance.Id, - Unit: quota_pb.Unit_UNIT_REQUESTS_ALL_AUTHENTICATED, - From: timestamppb.Now(), - ResetInterval: durationpb.New(time.Minute * 5), - Amount: uint64(amount), - Limit: false, - Notifications: []*quota_pb.Notification{ - { - Percent: uint32(percent), - Repeat: false, - CallUrl: callURL, - }, - { - Percent: 100, - Repeat: true, - CallUrl: callURL, - }, - }, + setQuota(t, instance.Instance.Id, amount, false, []*quota_pb.Notification{ + {Percent: uint32(percent), Repeat: false, CallUrl: callURL}, + {Percent: 100, Repeat: true, CallUrl: callURL}, }) - require.NoError(t, err) sub := sink.Subscribe(CTX, sink.ChannelQuota) defer sub.Close()