Skip to content
This repository was archived by the owner on Oct 12, 2023. It is now read-only.

Commit 1e6544c

Browse files
authored
Release 3.0.1
Release 3.0.1
2 parents 09b5d5c + 867d014 commit 1e6544c

File tree

6 files changed

+76
-17
lines changed

6 files changed

+76
-17
lines changed

src/Microsoft.Azure.ServiceBus/Microsoft.Azure.ServiceBus.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<Description>This is the next generation Azure Service Bus .NET Standard client library that focuses on queues &amp; topics. For more information about Service Bus, see https://azure.microsoft.com/en-us/services/service-bus/</Description>
5-
<VersionPrefix>3.0.0</VersionPrefix>
5+
<Version>3.0.1</Version>
66
<Authors>Microsoft</Authors>
77
<TargetFramework>netstandard2.0</TargetFramework>
88
<AssemblyOriginatorKeyFile>../../build/keyfile.snk</AssemblyOriginatorKeyFile>
@@ -31,10 +31,10 @@
3131

3232
<ItemGroup>
3333
<PackageReference Include="Microsoft.Azure.Amqp" Version="[2.2.0, 3.0.0)" />
34-
<PackageReference Include="Microsoft.Azure.Services.AppAuthentication" Version="1.1.0-preview" />
34+
<PackageReference Include="Microsoft.Azure.Services.AppAuthentication" Version="[1.0.1, 2.0.0)" />
3535
<PackageReference Include="Microsoft.IdentityModel.Clients.ActiveDirectory" Version="[3.17.2, 4.0.0)" />
3636
<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="4.4.1" />
37-
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="5.2.0-preview2-41113220915" />
37+
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="[5.2.2, 6.0.0)" />
3838
<PackageReference Include="System.Runtime.Serialization.Xml" Version="4.3.0" />
3939
</ItemGroup>
4040

src/Microsoft.Azure.ServiceBus/ServiceBusDiagnosticsSource.cs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,7 @@ private Activity Start(string operationName, Func<object> getPayload, Action<Act
650650
private void Inject(IList<Message> messageList)
651651
{
652652
var currentActivity = Activity.Current;
653-
if (currentActivity != null)
653+
if (currentActivity != null && messageList != null)
654654
{
655655
var correlationContext = SerializeCorrelationContext(currentActivity.Baggage.ToList());
656656

@@ -672,7 +672,7 @@ private void Inject(Message message)
672672

673673
private void Inject(Message message, string id, string correlationContext)
674674
{
675-
if (!message.UserProperties.ContainsKey(ActivityIdPropertyName))
675+
if (message != null && !message.UserProperties.ContainsKey(ActivityIdPropertyName))
676676
{
677677
message.UserProperties[ActivityIdPropertyName] = id;
678678
if (correlationContext != null)
@@ -684,7 +684,7 @@ private void Inject(Message message, string id, string correlationContext)
684684

685685
private string SerializeCorrelationContext(IList<KeyValuePair<string,string>> baggage)
686686
{
687-
if (baggage.Any())
687+
if (baggage != null && baggage.Count > 0)
688688
{
689689
return string.Join(",", baggage.Select(kvp => kvp.Key + "=" + kvp.Value));
690690
}
@@ -716,7 +716,7 @@ private Activity ProcessStart(string operationName, Message message, Func<object
716716
Activity activity = null;
717717
string activityName = BaseActivityName + operationName;
718718

719-
if (DiagnosticListener.IsEnabled(activityName, entityPath))
719+
if (message != null && DiagnosticListener.IsEnabled(activityName, entityPath))
720720
{
721721
var tmpActivity = message.ExtractActivity(activityName);
722722
setTags?.Invoke(tmpActivity);
@@ -739,6 +739,11 @@ private Activity ProcessStart(string operationName, Message message, Func<object
739739

740740
private void SetTags(Activity activity, IList<Message> messageList)
741741
{
742+
if (messageList == null)
743+
{
744+
return;
745+
}
746+
742747
var messageIds = messageList.Where(m => m.MessageId != null).Select(m => m.MessageId).ToArray();
743748
if (messageIds.Any())
744749
{
@@ -754,6 +759,11 @@ private void SetTags(Activity activity, IList<Message> messageList)
754759

755760
private void SetTags(Activity activity, Message message)
756761
{
762+
if (message == null)
763+
{
764+
return;
765+
}
766+
757767
if (message.MessageId != null)
758768
{
759769
activity.AddTag(MessageIdTag, message.MessageId);

test/Microsoft.Azure.ServiceBus.UnitTests/Diagnostics/DiagnosticsTests.cs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ protected int AssertReceiveStop(string name, object payload, Activity activity,
265265
}
266266

267267
Assert.Equal(sentMessagesCount, GetPropertyValueFromAnonymousTypeInstance<int>(payload, "RequestedMessageCount"));
268-
var messages = GetPropertyValueFromAnonymousTypeInstance<IList<Message>>(payload, "Messages");
268+
var messages = GetPropertyValueFromAnonymousTypeInstance<IList<Message>>(payload, "Messages", true);
269269

270270
if (receivedMessagesCount != -1)
271271
{
@@ -278,7 +278,7 @@ protected int AssertReceiveStop(string name, object payload, Activity activity,
278278
}
279279

280280
AssertTags(messages, activity);
281-
return messages.Count;
281+
return messages?.Count ?? 0;
282282
}
283283

284284
#endregion
@@ -414,6 +414,11 @@ protected void AssertRenewLockStop(string name, object payload, Activity activit
414414

415415
protected void AssertTags(IList<Message> messageList, Activity activity)
416416
{
417+
if (messageList == null)
418+
{
419+
return;
420+
}
421+
417422
var messagesWithId = messageList.Where(m => m.MessageId != null).ToArray();
418423
if (messagesWithId.Any())
419424
{
@@ -441,13 +446,13 @@ protected void AssertTags(IList<Message> messageList, Activity activity)
441446

442447
protected void AssertTags(Message message, Activity activity)
443448
{
444-
if (message.MessageId != null)
449+
if (message?.MessageId != null)
445450
{
446451
Assert.Contains("MessageId", activity.Tags.Select(t => t.Key));
447452
Assert.Equal(message.MessageId, activity.Tags.Single(t => t.Key == "MessageId").Value);
448453
}
449454

450-
if (message.SessionId != null)
455+
if (message?.SessionId != null)
451456
{
452457
Assert.Contains("SessionId", activity.Tags.Select(t => t.Key));
453458
Assert.Equal(message.SessionId, activity.Tags.Single(t => t.Key == "SessionId").Value);
@@ -483,15 +488,22 @@ protected void AssertCommonStopPayloadProperties(object eventPayload)
483488
Assert.Equal(TaskStatus.RanToCompletion, status);
484489
}
485490

486-
protected T GetPropertyValueFromAnonymousTypeInstance<T>(object obj, string propertyName)
491+
protected T GetPropertyValueFromAnonymousTypeInstance<T>(object obj, string propertyName, bool canValueBeNull = false)
487492
{
488493
Type t = obj.GetType();
489494

490495
PropertyInfo p = t.GetRuntimeProperty(propertyName);
491496

492497
object propertyValue = p.GetValue(obj);
493-
Assert.NotNull(propertyValue);
494-
Assert.IsAssignableFrom<T>(propertyValue);
498+
if (!canValueBeNull)
499+
{
500+
Assert.NotNull(propertyValue);
501+
}
502+
503+
if (propertyValue != null)
504+
{
505+
Assert.IsAssignableFrom<T>(propertyValue);
506+
}
495507

496508
return (T)propertyValue;
497509
}

test/Microsoft.Azure.ServiceBus.UnitTests/Diagnostics/QueueClientDiagnosticsTests.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,32 @@ async Task AbandonCompleteFireEvents()
239239
Assert.True(this.events.IsEmpty);
240240
}
241241

242+
[Fact]
243+
[DisplayTestMethodName]
244+
async Task ReceiveNoMessageFireEvents()
245+
{
246+
this.queueClient = new QueueClient(TestUtility.NamespaceConnectionString, TestConstants.NonPartitionedQueueName,
247+
ReceiveMode.ReceiveAndDelete);
248+
249+
this.listener.Enable((name, queuName, arg) => name.Contains("Send") || name.Contains("Receive"));
250+
var messages = await this.queueClient.InnerReceiver.ReceiveAsync(2, TimeSpan.FromSeconds(5));
251+
252+
int receivedStopCount = 0;
253+
Assert.Equal(2, this.events.Count);
254+
while (this.events.TryDequeue(out var receiveStart))
255+
{
256+
var startCount = AssertReceiveStart(receiveStart.eventName, receiveStart.payload, receiveStart.activity,
257+
-1);
258+
259+
Assert.True(this.events.TryDequeue(out var receiveStop));
260+
receivedStopCount += AssertReceiveStop(receiveStop.eventName, receiveStop.payload, receiveStop.activity,
261+
receiveStart.activity, null, startCount, -1);
262+
}
263+
264+
Assert.Equal(0, receivedStopCount);
265+
Assert.True(this.events.IsEmpty);
266+
}
267+
242268
[Fact]
243269
[DisplayTestMethodName]
244270
async Task BatchSendReceiveFireEvents()

test/Microsoft.Azure.ServiceBus.UnitTests/Microsoft.Azure.ServiceBus.UnitTests.csproj

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,16 @@
2424
<compile Remove="..\..\test\Microsoft.Azure.ServiceBus.UnitTests\RetryTests.cs" />
2525
<compile Remove="..\..\test\Microsoft.Azure.ServiceBus.UnitTests\SubscriptionClientTests.cs" />
2626
<compile Remove="..\..\test\Microsoft.Azure.ServiceBus.UnitTests\Diagnostics\ExtractActivityTests.cs" />
27-
<compile Remove="..\..\test\Microsoft.Azure.ServiceBus.UnitTests\Diagnostics\QueueClientDiagnosticsTests.cs" />
28-
<compile Remove="..\..\test\Microsoft.Azure.ServiceBus.UnitTests\Diagnostics\SubscriptionClientDiagnosticsTests.cs" />
2927
<compile Remove="..\..\test\Microsoft.Azure.ServiceBus.UnitTests\Diagnostics\SessionDiagnosticsTests.cs" />
28+
<compile Remove="..\..\test\Microsoft.Azure.ServiceBus.UnitTests\Diagnostics\QueueClientDiagnosticsTests.cs" />
29+
<compile Remove="..\..\test\Microsoft.Azure.ServiceBus.UnitTests\API\APIApprovals.cs" />
3030
</ItemGroup>
3131

3232
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp2.0'">
3333
<compile Remove="..\..\test\Microsoft.Azure.ServiceBus.UnitTests\OnMessageTopicSubscriptionTests.cs" />
3434
<compile Remove="..\..\test\Microsoft.Azure.ServiceBus.UnitTests\TopicClientTests.cs" />
35-
<compile Remove="..\..\test\Microsoft.Azure.ServiceBus.UnitTests\OnSessionTopicSubscriptionTests.cs" />
35+
<compile Remove="..\..\test\Microsoft.Azure.ServiceBus.UnitTests\OnSessionTopicSubscriptionTests.cs" />
36+
<compile Remove="..\..\test\Microsoft.Azure.ServiceBus.UnitTests\Diagnostics\SubscriptionClientDiagnosticsTests.cs" />
3637
</ItemGroup>
3738

3839
<ItemGroup>

test/Microsoft.Azure.ServiceBus.UnitTests/TransactionTests.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,10 @@ public async Task TransactionalCompleteCommitTest(string queueName)
111111
ts.Complete();
112112
}
113113

114+
// Adding delay since transaction Commit/Rollback is an asynchronous operation.
115+
// Operating on the same message should not be done.
116+
await Task.Delay(TimeSpan.FromSeconds(2));
117+
114118
await Assert.ThrowsAsync<MessageLockLostException>(async () => await receiver.CompleteAsync(receivedMessage.SystemProperties.LockToken));
115119
}
116120
finally
@@ -183,12 +187,18 @@ public async Task TransactionalSessionDispositionTest(string queueName)
183187
ts.Dispose();
184188
}
185189

190+
// Adding delay since transaction Commit/Rollback is an asynchronous operation.
191+
// Operating on the same message should not be done.
192+
await Task.Delay(TimeSpan.FromSeconds(2));
193+
186194
using (var ts = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
187195
{
188196
await receiver.CompleteAsync(receivedMessage.SystemProperties.LockToken);
189197
ts.Complete();
190198
}
191199

200+
await Task.Delay(TimeSpan.FromSeconds(2));
201+
192202
await Assert.ThrowsAsync<SessionLockLostException>(async () => await receiver.CompleteAsync(receivedMessage.SystemProperties.LockToken));
193203
}
194204
finally

0 commit comments

Comments
 (0)