|
3 | 3 |
|
4 | 4 | using System.Collections.Generic; |
5 | 5 | using System.Linq; |
| 6 | +using System.Threading; |
| 7 | +using System.Threading.Tasks; |
6 | 8 | using Microsoft.Identity.Abstractions; |
7 | 9 | using Xunit; |
8 | 10 |
|
@@ -313,5 +315,39 @@ public void PrepareAuthorityInstanceForMsal_LeavesNullPreparedInstance_WhenNoCon |
313 | 315 | Assert.Null(options.Authority); |
314 | 316 | Assert.Null(options.PreparedInstance); |
315 | 317 | } |
| 318 | + |
| 319 | + [Fact] |
| 320 | + public async Task ConfidentialClientApplicationOptions_IsThreadSafe() |
| 321 | + { |
| 322 | + // Arrange |
| 323 | + var mergedOptions = new MergedOptions |
| 324 | + { |
| 325 | + ClientId = "test-client-id", |
| 326 | + ClientSecret = "test-client-secret", |
| 327 | + Instance = "https://login.microsoftonline.com/", |
| 328 | + TenantId = "test-tenant-id", |
| 329 | + }; |
| 330 | + |
| 331 | + const int threadCount = 50; |
| 332 | + var barrier = new Barrier(threadCount); |
| 333 | + var results = new Microsoft.Identity.Client.ConfidentialClientApplicationOptions[threadCount]; |
| 334 | + |
| 335 | + // Act |
| 336 | + var tasks = Enumerable.Range(0, threadCount).Select(i => Task.Run(() => |
| 337 | + { |
| 338 | + barrier.SignalAndWait(); |
| 339 | + results[i] = mergedOptions.ConfidentialClientApplicationOptions; |
| 340 | + })).ToArray(); |
| 341 | + await Task.WhenAll(tasks); |
| 342 | + |
| 343 | + // Assert |
| 344 | + for (int i = 0; i < threadCount; i++) |
| 345 | + { |
| 346 | + Assert.NotNull(results[i]); |
| 347 | + Assert.Equal("test-client-id", results[i].ClientId); |
| 348 | + Assert.Equal("test-client-secret", results[i].ClientSecret); |
| 349 | + Assert.Equal("test-tenant-id", results[i].TenantId); |
| 350 | + } |
| 351 | + } |
316 | 352 | } |
317 | 353 | } |
0 commit comments