-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Continue renewing lock while processing #22257
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -829,5 +829,44 @@ Task ProcessMessage(ProcessMessageEventArgs args) | |||||
await processor.StopProcessingAsync(); | ||||||
} | ||||||
} | ||||||
|
||||||
[Test] | ||||||
public async Task AutoLockRenewalContinuesUntilProcessingCompletes() | ||||||
{ | ||||||
var lockDuration = TimeSpan.FromSeconds(10); | ||||||
await using (var scope = await ServiceBusScope.CreateWithQueue(enablePartitioning: false, enableSession: false, lockDuration: lockDuration)) | ||||||
{ | ||||||
await using var client = CreateClient(); | ||||||
var sender = client.CreateSender(scope.QueueName); | ||||||
int messageCount = 10; | ||||||
|
||||||
await sender.SendMessagesAsync(GetMessages(messageCount)); | ||||||
|
||||||
await using var processor = client.CreateProcessor(scope.QueueName, new ServiceBusProcessorOptions | ||||||
{ | ||||||
MaxConcurrentCalls = 10 | ||||||
}); | ||||||
|
||||||
int receivedCount = 0; | ||||||
var tcs = new TaskCompletionSource<bool>(); | ||||||
|
||||||
async Task ProcessMessage(ProcessMessageEventArgs args) | ||||||
{ | ||||||
var ct = Interlocked.Increment(ref receivedCount); | ||||||
if (ct == messageCount) | ||||||
{ | ||||||
tcs.SetResult(true); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably not necessary due to the increment, but can't hurt. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This shouldn't be necessary and could potentially obscure other issues in the test. |
||||||
} | ||||||
|
||||||
await Task.Delay(lockDuration.Add(lockDuration)); | ||||||
} | ||||||
processor.ProcessMessageAsync += ProcessMessage; | ||||||
processor.ProcessErrorAsync += ExceptionHandler; | ||||||
|
||||||
await processor.StartProcessingAsync(); | ||||||
await tcs.Task; | ||||||
await processor.StopProcessingAsync(); | ||||||
} | ||||||
} | ||||||
} | ||||||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -854,7 +854,7 @@ Task ExceptionHandler(ProcessErrorEventArgs args) | |||||
|
||||||
await processor.StartProcessingAsync(); | ||||||
await tcs.Task; | ||||||
await processor.StopProcessingAsync(); | ||||||
await processor.CloseAsync(); | ||||||
|
||||||
if (settleMethod == "" || settleMethod == "Abandon") | ||||||
{ | ||||||
|
@@ -1291,14 +1291,7 @@ public async Task ErrorSourceRespected(ServiceBusErrorSource errorSource) | |||||
|
||||||
Task CloseSessionHandler(ProcessSessionEventArgs arg) | ||||||
{ | ||||||
try | ||||||
{ | ||||||
throw new TestException(); | ||||||
} | ||||||
finally | ||||||
{ | ||||||
tcs.TrySetResult(true); | ||||||
} | ||||||
throw new TestException(); | ||||||
} | ||||||
|
||||||
async Task SessionErrorHandler(ProcessErrorEventArgs eventArgs) | ||||||
|
@@ -1388,6 +1381,9 @@ await client.AcceptSessionAsync( | |||||
case ServiceBusErrorSource.Complete: | ||||||
await Task.Delay(delayDuration); | ||||||
break; | ||||||
case ServiceBusErrorSource.CloseSession: | ||||||
tcs.TrySetResult(true); | ||||||
break; | ||||||
} | ||||||
} | ||||||
finally | ||||||
|
@@ -1396,7 +1392,7 @@ await client.AcceptSessionAsync( | |||||
} | ||||||
} | ||||||
await tcs.Task; | ||||||
await processor.StopProcessingAsync(); | ||||||
await processor.CloseAsync(); | ||||||
if (errorSource != ServiceBusErrorSource.AcceptSession) | ||||||
{ | ||||||
Assert.AreEqual(1, messageCt); | ||||||
|
@@ -1707,5 +1703,44 @@ async Task ProcessMessage(ProcessMessageEventArgs args) | |||||
Assert.IsNull(msg); | ||||||
} | ||||||
} | ||||||
|
||||||
[Test] | ||||||
public async Task AutoLockRenewalContinuesUntilProcessingCompletes() | ||||||
{ | ||||||
var lockDuration = TimeSpan.FromSeconds(10); | ||||||
await using (var scope = await ServiceBusScope.CreateWithQueue(enablePartitioning: false, enableSession: true, lockDuration: lockDuration)) | ||||||
{ | ||||||
await using var client = CreateClient(); | ||||||
var sender = client.CreateSender(scope.QueueName); | ||||||
int messageCount = 10; | ||||||
|
||||||
await sender.SendMessagesAsync(GetMessages(messageCount, "sessionId")); | ||||||
|
||||||
await using var processor = client.CreateSessionProcessor(scope.QueueName, new ServiceBusSessionProcessorOptions | ||||||
{ | ||||||
MaxConcurrentCallsPerSession = 10 | ||||||
}); | ||||||
|
||||||
int receivedCount = 0; | ||||||
var tcs = new TaskCompletionSource<bool>(); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
async Task ProcessMessage(ProcessSessionMessageEventArgs args) | ||||||
{ | ||||||
var ct = Interlocked.Increment(ref receivedCount); | ||||||
if (ct == messageCount) | ||||||
{ | ||||||
tcs.SetResult(true); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
} | ||||||
|
||||||
await Task.Delay(lockDuration.Add(lockDuration)); | ||||||
} | ||||||
processor.ProcessMessageAsync += ProcessMessage; | ||||||
processor.ProcessErrorAsync += ExceptionHandler; | ||||||
|
||||||
await processor.StartProcessingAsync(); | ||||||
await tcs.Task; | ||||||
await processor.StopProcessingAsync(); | ||||||
} | ||||||
} | ||||||
} | ||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I had auto-merge enabled, but I don't think this will be a huge impact being that this is a test rather than the produce code.