@@ -75,7 +75,7 @@ public async Task ValidateDeliveryLimit_Should_Update_Old_Unlimited_Policy_Creat
7575 Assert . Ignore ( "Test not valid for broker versions before 4.0.0" ) ;
7676 }
7777
78- var queueName = nameof ( ValidateDeliveryLimit_Should_Set_Delivery_Limit_Policy ) ;
78+ var queueName = nameof ( ValidateDeliveryLimit_Should_Update_Old_Unlimited_Policy_Created_By_Transport ) ;
7979 var policyName = $ "nsb.{ queueName } .delivery-limit";
8080
8181 var oldUnlimitedPolicy = new Policy
@@ -133,6 +133,79 @@ public async Task ValidateDeliveryLimit_Should_Update_Old_Unlimited_Policy_Creat
133133 Assert . Fail ( $ "Policy '{ policyName } ' was not applied to queue '{ queueName } '.") ;
134134 }
135135
136+ [ Test ]
137+ public async Task ValidateDeliveryLimit_Should_Update_Old_Overeager_Policy ( )
138+ {
139+ var managementClient = new ManagementClient ( connectionConfiguration ) ;
140+ using var brokerVerifier = new BrokerVerifier ( managementClient , BrokerRequirementChecks . None , true ) ;
141+ await brokerVerifier . Initialize ( ) ;
142+
143+ if ( brokerVerifier . BrokerVersion < BrokerVerifier . BrokerVersion4 )
144+ {
145+ Assert . Ignore ( "Test not valid for broker versions before 4.0.0" ) ;
146+ }
147+
148+ var queueName = nameof ( ValidateDeliveryLimit_Should_Update_Old_Overeager_Policy ) ;
149+ var policyName = $ "nsb.{ queueName } .delivery-limit";
150+
151+ var oldQueueName = queueName [ ..^ 7 ] ;
152+ var oldPolicyName = $ "nsb.{ oldQueueName } .delivery-limit";
153+
154+ var oldPolicy = new Policy
155+ {
156+ ApplyTo = PolicyTarget . QuorumQueues ,
157+ Definition = new PolicyDefinition { DeliveryLimit = - 1 } ,
158+ Pattern = oldQueueName ,
159+ Priority = 0
160+ } ;
161+
162+ await CreateQueue ( queueName ) ;
163+ await managementClient . CreatePolicy ( oldPolicyName , oldPolicy ) ;
164+
165+ // It can take some time for updated policies to be applied, so we need to wait.
166+ // If this test is randomly failing, consider increasing the attempts
167+ var attempts = 20 ;
168+
169+ int deliveryLimit = 0 ;
170+
171+ for ( int i = 0 ; i < attempts ; i ++ )
172+ {
173+ var queue = await managementClient . GetQueue ( queueName ) ;
174+ deliveryLimit = queue . GetDeliveryLimit ( ) ;
175+
176+ if ( deliveryLimit == - 1 && queue . AppliedPolicyName == oldPolicyName )
177+ {
178+ // Policy applied successfully
179+ break ;
180+ }
181+
182+ await Task . Delay ( TimeSpan . FromSeconds ( 3 ) ) ;
183+ }
184+
185+ if ( deliveryLimit != - 1 )
186+ {
187+ Assert . Fail ( $ "Old Policy '{ oldPolicyName } ' was not applied to queue '{ queueName } '.") ;
188+ }
189+
190+ await brokerVerifier . ValidateDeliveryLimit ( queueName ) ;
191+
192+ for ( int i = 0 ; i < attempts ; i ++ )
193+ {
194+ var queue = await managementClient . GetQueue ( queueName ) ;
195+ deliveryLimit = queue . GetDeliveryLimit ( ) ;
196+
197+ if ( deliveryLimit == Queue . BigValueInsteadOfActuallyUnlimited && queue . AppliedPolicyName == policyName )
198+ {
199+ // Policy applied successfully
200+ return ;
201+ }
202+
203+ await Task . Delay ( TimeSpan . FromSeconds ( 3 ) ) ;
204+ }
205+
206+ Assert . Fail ( $ "Policy '{ policyName } ' was not applied to queue '{ queueName } '.") ;
207+ }
208+
136209 [ Test ]
137210 public async Task ValidateDeliveryLimit_Should_Throw_When_Queue_Does_Not_Exist ( )
138211 {
@@ -195,7 +268,7 @@ public async Task ValidateDeliveryLimit_Should_Throw_When_A_Policy_On_Queue_Has_
195268
196269 await managementClient . CreatePolicy ( policyName , policy ) . ConfigureAwait ( false ) ;
197270
198- // If this test appears flaky, the delay should be increased to give the broker more time to apply the oldUnlimitedPolicy before calling ValidateDeliveryLimit
271+ // If this test appears flaky, the delay should be increased to give the broker more time to apply the policy before calling ValidateDeliveryLimit
199272 await Task . Delay ( TimeSpan . FromSeconds ( 30 ) ) ;
200273
201274 var exception = Assert . ThrowsAsync < InvalidOperationException > ( async ( ) => await brokerVerifier . ValidateDeliveryLimit ( queueName ) ) ;
0 commit comments