From 18858e8f394b62e6a7a41773a38dbb5f865f4e98 Mon Sep 17 00:00:00 2001 From: williamzhao87 Date: Mon, 30 Oct 2023 13:47:20 -0400 Subject: [PATCH] Add test records --- .../Azure.Communication.JobRouter/assets.json | 2 +- .../Models/JobRouterAdministrationClient.cs | 64 +++++++------- .../src/Models/JobRouterClient.cs | 36 ++++---- .../src/Models/ReclassifyExceptionAction.cs | 5 +- .../src/Models/RouterChannel.cs | 2 + .../src/Models/RouterJob.cs | 4 +- .../src/Models/RouterJobNote.cs | 16 +++- .../src/Models/RouterWorker.cs | 3 + .../Infrastructure/RouterLiveTestBase.cs | 17 +++- .../ClassificationPolicyLiveTests.cs | 17 ++-- .../RouterClients/ExceptionPolicyLiveTests.cs | 1 - .../tests/RouterClients/RouterJobLiveTests.cs | 86 +++++++++++++++++-- .../RouterClients/RouterWorkerLiveTests.cs | 35 ++++---- .../tests/Scenarios/AssignmentScenario.cs | 9 ++ .../tests/Scenarios/CancellationScenario.cs | 1 - .../tests/Scenarios/QueueScenario.cs | 1 + .../tests/Scenarios/SchedulingScenario.cs | 2 +- 17 files changed, 209 insertions(+), 92 deletions(-) diff --git a/sdk/communication/Azure.Communication.JobRouter/assets.json b/sdk/communication/Azure.Communication.JobRouter/assets.json index 70009be9e6bad..ac2177e009113 100644 --- a/sdk/communication/Azure.Communication.JobRouter/assets.json +++ b/sdk/communication/Azure.Communication.JobRouter/assets.json @@ -2,5 +2,5 @@ "AssetsRepo": "Azure/azure-sdk-assets", "AssetsRepoPrefixPath": "net", "TagPrefix": "net/communication/Azure.Communication.JobRouter", - "Tag": "net/communication/Azure.Communication.JobRouter_33a06c6ea8" + "Tag": "net/communication/Azure.Communication.JobRouter_83ab5cb025" } diff --git a/sdk/communication/Azure.Communication.JobRouter/src/Models/JobRouterAdministrationClient.cs b/sdk/communication/Azure.Communication.JobRouter/src/Models/JobRouterAdministrationClient.cs index 0581047358eb0..26ff7ae046e04 100644 --- a/sdk/communication/Azure.Communication.JobRouter/src/Models/JobRouterAdministrationClient.cs +++ b/sdk/communication/Azure.Communication.JobRouter/src/Models/JobRouterAdministrationClient.cs @@ -115,7 +115,7 @@ public virtual async Task> CreateClassificationPo var result = await UpsertClassificationPolicyAsync( classificationPolicyId: options.ClassificationPolicyId, content: request.ToRequestContent(), - requestConditions: options.RequestConditions, + requestConditions: options.RequestConditions ?? new RequestConditions(), context: FromCancellationToken(cancellationToken)) .ConfigureAwait(false); @@ -153,7 +153,7 @@ public virtual Response CreateClassificationPolicy( var result = UpsertClassificationPolicy( classificationPolicyId: options.ClassificationPolicyId, content: request.ToRequestContent(), - requestConditions: options.RequestConditions, + requestConditions: options.RequestConditions ?? new RequestConditions(), context: FromCancellationToken(cancellationToken)); return Response.FromValue(ClassificationPolicy.FromResponse(result), result); @@ -181,7 +181,7 @@ public virtual async Task> UpdateClassificationPo var response = await UpsertClassificationPolicyAsync( classificationPolicyId: classificationPolicy.Id, content: classificationPolicy.ToRequestContent(), - requestConditions: requestConditions, + requestConditions: requestConditions ?? new RequestConditions(), context: FromCancellationToken(cancellationToken)) .ConfigureAwait(false); @@ -210,7 +210,7 @@ public virtual Response UpdateClassificationPolicy( var response = UpsertClassificationPolicy( classificationPolicyId: classificationPolicy.Id, content: classificationPolicy.ToRequestContent(), - requestConditions: requestConditions, + requestConditions: requestConditions ?? new RequestConditions(), context: FromCancellationToken(cancellationToken)); return Response.FromValue(ClassificationPolicy.FromResponse(response), response); @@ -245,8 +245,8 @@ public virtual async Task UpdateClassificationPolicyAsync(string class Argument.AssertNotNullOrEmpty(classificationPolicyId, nameof(classificationPolicyId)); Argument.AssertNotNull(content, nameof(content)); - Argument.AssertNull(requestConditions.IfNoneMatch, nameof(requestConditions), "Service does not support the If-None-Match header for this operation."); - Argument.AssertNull(requestConditions.IfModifiedSince, nameof(requestConditions), "Service does not support the If-Modified-Since header for this operation."); + Argument.AssertNull(requestConditions?.IfNoneMatch, nameof(requestConditions), "Service does not support the If-None-Match header for this operation."); + Argument.AssertNull(requestConditions?.IfModifiedSince, nameof(requestConditions), "Service does not support the If-Modified-Since header for this operation."); using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(JobRouterAdministrationClient)}.{nameof(UpdateClassificationPolicy)}"); scope.Start(); @@ -285,8 +285,8 @@ public virtual Response UpdateClassificationPolicy(string classificationPolicyId Argument.AssertNotNullOrEmpty(classificationPolicyId, nameof(classificationPolicyId)); Argument.AssertNotNull(content, nameof(content)); - Argument.AssertNull(requestConditions.IfNoneMatch, nameof(requestConditions), "Service does not support the If-None-Match header for this operation."); - Argument.AssertNull(requestConditions.IfModifiedSince, nameof(requestConditions), "Service does not support the If-Modified-Since header for this operation."); + Argument.AssertNull(requestConditions?.IfNoneMatch, nameof(requestConditions), "Service does not support the If-None-Match header for this operation."); + Argument.AssertNull(requestConditions?.IfModifiedSince, nameof(requestConditions), "Service does not support the If-Modified-Since header for this operation."); using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(JobRouterAdministrationClient)}.{nameof(UpdateClassificationPolicy)}"); scope.Start(); @@ -326,7 +326,7 @@ public virtual async Task> CreateDistributionPolicy var response = await UpsertDistributionPolicyAsync( distributionPolicyId: options.DistributionPolicyId, content: request.ToRequestContent(), - requestConditions: options.RequestConditions, + requestConditions: options.RequestConditions ?? new RequestConditions(), context: FromCancellationToken(cancellationToken)) .ConfigureAwait(false); @@ -359,7 +359,7 @@ public virtual Response CreateDistributionPolicy( var response = UpsertDistributionPolicy( distributionPolicyId: options.DistributionPolicyId, content: request.ToRequestContent(), - requestConditions: options.RequestConditions, + requestConditions: options.RequestConditions ?? new RequestConditions(), context: FromCancellationToken(cancellationToken)); return Response.FromValue(DistributionPolicy.FromResponse(response), response); @@ -387,7 +387,7 @@ public virtual async Task> UpdateDistributionPolicy var response = await UpsertDistributionPolicyAsync( distributionPolicyId: distributionPolicy.Id, content: distributionPolicy.ToRequestContent(), - requestConditions: requestConditions, + requestConditions: requestConditions ?? new RequestConditions(), context: FromCancellationToken(cancellationToken)) .ConfigureAwait(false); @@ -416,7 +416,7 @@ public virtual Response UpdateDistributionPolicy( var response = UpsertDistributionPolicy( distributionPolicyId: distributionPolicy.Id, content: distributionPolicy.ToRequestContent(), - requestConditions: requestConditions, + requestConditions: requestConditions ?? new RequestConditions(), context: FromCancellationToken(cancellationToken)); return Response.FromValue(DistributionPolicy.FromResponse(response), response); @@ -451,8 +451,8 @@ public virtual async Task UpdateDistributionPolicyAsync(string distrib Argument.AssertNotNullOrEmpty(distributionPolicyId, nameof(distributionPolicyId)); Argument.AssertNotNull(content, nameof(content)); - Argument.AssertNull(requestConditions.IfNoneMatch, nameof(requestConditions), "Service does not support the If-None-Match header for this operation."); - Argument.AssertNull(requestConditions.IfModifiedSince, nameof(requestConditions), "Service does not support the If-Modified-Since header for this operation."); + Argument.AssertNull(requestConditions?.IfNoneMatch, nameof(requestConditions), "Service does not support the If-None-Match header for this operation."); + Argument.AssertNull(requestConditions?.IfModifiedSince, nameof(requestConditions), "Service does not support the If-Modified-Since header for this operation."); using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(JobRouterAdministrationClient)}.{nameof(UpdateDistributionPolicy)}"); scope.Start(); @@ -491,8 +491,8 @@ public virtual Response UpdateDistributionPolicy(string distributionPolicyId, Re Argument.AssertNotNullOrEmpty(distributionPolicyId, nameof(distributionPolicyId)); Argument.AssertNotNull(content, nameof(content)); - Argument.AssertNull(requestConditions.IfNoneMatch, nameof(requestConditions), "Service does not support the If-None-Match header for this operation."); - Argument.AssertNull(requestConditions.IfModifiedSince, nameof(requestConditions), "Service does not support the If-Modified-Since header for this operation."); + Argument.AssertNull(requestConditions?.IfNoneMatch, nameof(requestConditions), "Service does not support the If-None-Match header for this operation."); + Argument.AssertNull(requestConditions?.IfModifiedSince, nameof(requestConditions), "Service does not support the If-Modified-Since header for this operation."); using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(JobRouterAdministrationClient)}.{nameof(UpdateDistributionPolicy)}"); scope.Start(); @@ -534,7 +534,7 @@ public virtual async Task> CreateExceptionPolicyAsync( var response = await UpsertExceptionPolicyAsync( exceptionPolicyId: options.ExceptionPolicyId, content: request.ToRequestContent(), - requestConditions: options.RequestConditions, + requestConditions: options.RequestConditions ?? new RequestConditions(), context: FromCancellationToken(cancellationToken)) .ConfigureAwait(false); @@ -569,7 +569,7 @@ public virtual Response CreateExceptionPolicy( var response = UpsertExceptionPolicy( exceptionPolicyId: options.ExceptionPolicyId, content: request.ToRequestContent(), - requestConditions: options.RequestConditions, + requestConditions: options.RequestConditions ?? new RequestConditions(), context: FromCancellationToken(cancellationToken)); return Response.FromValue(ExceptionPolicy.FromResponse(response), response); @@ -597,7 +597,7 @@ public virtual async Task> UpdateExceptionPolicyAsync( var response = await UpsertExceptionPolicyAsync( exceptionPolicyId: exceptionPolicy.Id, content: exceptionPolicy.ToRequestContent(), - requestConditions: requestConditions, + requestConditions: requestConditions ?? new RequestConditions(), context: FromCancellationToken(cancellationToken)) .ConfigureAwait(false); @@ -626,7 +626,7 @@ public virtual Response UpdateExceptionPolicy( var response = UpsertExceptionPolicy( exceptionPolicyId: exceptionPolicy.Id, content: exceptionPolicy.ToRequestContent(), - requestConditions: requestConditions, + requestConditions: requestConditions ?? new RequestConditions(), context: FromCancellationToken(cancellationToken)); return Response.FromValue(ExceptionPolicy.FromResponse(response), response); @@ -661,8 +661,8 @@ internal virtual async Task UpdateExceptionPolicyAsync(string exceptio Argument.AssertNotNullOrEmpty(exceptionPolicyId, nameof(exceptionPolicyId)); Argument.AssertNotNull(content, nameof(content)); - Argument.AssertNull(requestConditions.IfNoneMatch, nameof(requestConditions), "Service does not support the If-None-Match header for this operation."); - Argument.AssertNull(requestConditions.IfModifiedSince, nameof(requestConditions), "Service does not support the If-Modified-Since header for this operation."); + Argument.AssertNull(requestConditions?.IfNoneMatch, nameof(requestConditions), "Service does not support the If-None-Match header for this operation."); + Argument.AssertNull(requestConditions?.IfModifiedSince, nameof(requestConditions), "Service does not support the If-Modified-Since header for this operation."); using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(JobRouterAdministrationClient)}.{nameof(UpdateExceptionPolicy)}"); scope.Start(); @@ -701,8 +701,8 @@ internal virtual Response UpdateExceptionPolicy(string exceptionPolicyId, Reques Argument.AssertNotNullOrEmpty(exceptionPolicyId, nameof(exceptionPolicyId)); Argument.AssertNotNull(content, nameof(content)); - Argument.AssertNull(requestConditions.IfNoneMatch, nameof(requestConditions), "Service does not support the If-None-Match header for this operation."); - Argument.AssertNull(requestConditions.IfModifiedSince, nameof(requestConditions), "Service does not support the If-Modified-Since header for this operation."); + Argument.AssertNull(requestConditions?.IfNoneMatch, nameof(requestConditions), "Service does not support the If-None-Match header for this operation."); + Argument.AssertNull(requestConditions?.IfModifiedSince, nameof(requestConditions), "Service does not support the If-Modified-Since header for this operation."); using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(JobRouterAdministrationClient)}.{nameof(UpdateExceptionPolicy)}"); scope.Start(); @@ -749,7 +749,7 @@ public virtual async Task> CreateQueueAsync( var response = await UpsertQueueAsync( queueId: options.QueueId, content: request.ToRequestContent(), - requestConditions: options.RequestConditions, + requestConditions: options.RequestConditions ?? new RequestConditions(), context: FromCancellationToken(cancellationToken)) .ConfigureAwait(false); @@ -789,7 +789,7 @@ public virtual Response CreateQueue( var response = UpsertQueue( queueId: options.QueueId, content: request.ToRequestContent(), - requestConditions: options.RequestConditions, + requestConditions: options.RequestConditions ?? new RequestConditions(), context: FromCancellationToken(cancellationToken)); return Response.FromValue(RouterQueue.FromResponse(response), response); @@ -818,7 +818,7 @@ public virtual async Task> UpdateQueueAsync( var response = await UpsertQueueAsync( queueId: queue.Id, content: queue.ToRequestContent(), - requestConditions: requestConditions, + requestConditions: requestConditions ?? new RequestConditions(), context: FromCancellationToken(cancellationToken)) .ConfigureAwait(false); @@ -847,7 +847,7 @@ public virtual Response UpdateQueue( var response = UpsertQueue( queueId: queue.Id, content: queue.ToRequestContent(), - requestConditions: requestConditions, + requestConditions: requestConditions ?? new RequestConditions(), context: FromCancellationToken(cancellationToken)); return Response.FromValue(RouterQueue.FromResponse(response), response); @@ -882,8 +882,8 @@ public virtual async Task UpdateQueueAsync(string queueId, RequestCont Argument.AssertNotNullOrEmpty(queueId, nameof(queueId)); Argument.AssertNotNull(content, nameof(content)); - Argument.AssertNull(requestConditions.IfNoneMatch, nameof(requestConditions), "Service does not support the If-None-Match header for this operation."); - Argument.AssertNull(requestConditions.IfModifiedSince, nameof(requestConditions), "Service does not support the If-Modified-Since header for this operation."); + Argument.AssertNull(requestConditions?.IfNoneMatch, nameof(requestConditions), "Service does not support the If-None-Match header for this operation."); + Argument.AssertNull(requestConditions?.IfModifiedSince, nameof(requestConditions), "Service does not support the If-Modified-Since header for this operation."); using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(JobRouterAdministrationClient)}.{nameof(UpdateQueue)}"); scope.Start(); @@ -922,8 +922,8 @@ internal virtual Response UpdateQueue(string queueId, RequestContent content, Re Argument.AssertNotNullOrEmpty(queueId, nameof(queueId)); Argument.AssertNotNull(content, nameof(content)); - Argument.AssertNull(requestConditions.IfNoneMatch, nameof(requestConditions), "Service does not support the If-None-Match header for this operation."); - Argument.AssertNull(requestConditions.IfModifiedSince, nameof(requestConditions), "Service does not support the If-Modified-Since header for this operation."); + Argument.AssertNull(requestConditions?.IfNoneMatch, nameof(requestConditions), "Service does not support the If-None-Match header for this operation."); + Argument.AssertNull(requestConditions?.IfModifiedSince, nameof(requestConditions), "Service does not support the If-Modified-Since header for this operation."); using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(JobRouterAdministrationClient)}.{nameof(UpdateQueue)}"); scope.Start(); diff --git a/sdk/communication/Azure.Communication.JobRouter/src/Models/JobRouterClient.cs b/sdk/communication/Azure.Communication.JobRouter/src/Models/JobRouterClient.cs index 4b180823a5f1a..43ed7dade4286 100644 --- a/sdk/communication/Azure.Communication.JobRouter/src/Models/JobRouterClient.cs +++ b/sdk/communication/Azure.Communication.JobRouter/src/Models/JobRouterClient.cs @@ -152,7 +152,7 @@ public virtual async Task> CreateJobWithClassificationPolicy var response = await UpsertJobAsync( jobId: options.JobId, content: request.ToRequestContent(), - requestConditions: options.RequestConditions, + requestConditions: options.RequestConditions ?? new RequestConditions(), context: FromCancellationToken(cancellationToken)) .ConfigureAwait(false); @@ -210,7 +210,7 @@ public virtual Response CreateJobWithClassificationPolicy( var response = UpsertJob( jobId: options.JobId, content: request.ToRequestContent(), - requestConditions: options.RequestConditions, + requestConditions: options.RequestConditions ?? new RequestConditions(), context: FromCancellationToken(cancellationToken)); return Response.FromValue(RouterJob.FromResponse(response), response); @@ -270,7 +270,7 @@ public virtual async Task> CreateJobAsync( var response = await UpsertJobAsync( jobId: options.JobId, content: request.ToRequestContent(), - requestConditions: options.RequestConditions, + requestConditions: options.RequestConditions ?? new RequestConditions(), context: FromCancellationToken(cancellationToken)) .ConfigureAwait(false); @@ -327,7 +327,7 @@ public virtual Response CreateJob( var response = UpsertJob( jobId: options.JobId, content: request.ToRequestContent(), - requestConditions: options.RequestConditions, + requestConditions: options.RequestConditions ?? new RequestConditions(), context: FromCancellationToken(cancellationToken)); return Response.FromValue(RouterJob.FromResponse(response), response); @@ -357,7 +357,7 @@ public virtual async Task> UpdateJobAsync( var response = await UpsertJobAsync( jobId: job.Id, content: job.ToRequestContent(), - requestConditions: requestConditions, + requestConditions: requestConditions ?? new RequestConditions(), context: FromCancellationToken(cancellationToken)) .ConfigureAwait(false); @@ -386,7 +386,7 @@ public virtual Response UpdateJob( var response = UpsertJob( jobId: job.Id, content: job.ToRequestContent(), - requestConditions: requestConditions, + requestConditions: requestConditions ?? new RequestConditions(), context: FromCancellationToken(cancellationToken)); return Response.FromValue(RouterJob.FromResponse(response), response); @@ -421,8 +421,8 @@ public virtual async Task UpdateJobAsync(string jobId, RequestContent Argument.AssertNotNullOrEmpty(jobId, nameof(jobId)); Argument.AssertNotNull(content, nameof(content)); - Argument.AssertNull(requestConditions.IfNoneMatch, nameof(requestConditions), "Service does not support the If-None-Match header for this operation."); - Argument.AssertNull(requestConditions.IfModifiedSince, nameof(requestConditions), "Service does not support the If-Modified-Since header for this operation."); + Argument.AssertNull(requestConditions?.IfNoneMatch, nameof(requestConditions), "Service does not support the If-None-Match header for this operation."); + Argument.AssertNull(requestConditions?.IfModifiedSince, nameof(requestConditions), "Service does not support the If-Modified-Since header for this operation."); using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(JobRouterClient)}.{nameof(UpdateJob)}"); scope.Start(); @@ -461,8 +461,8 @@ public virtual Response UpdateJob(string jobId, RequestContent content, RequestC Argument.AssertNotNullOrEmpty(jobId, nameof(jobId)); Argument.AssertNotNull(content, nameof(content)); - Argument.AssertNull(requestConditions.IfNoneMatch, nameof(requestConditions), "Service does not support the If-None-Match header for this operation."); - Argument.AssertNull(requestConditions.IfModifiedSince, nameof(requestConditions), "Service does not support the If-Modified-Since header for this operation."); + Argument.AssertNull(requestConditions?.IfNoneMatch, nameof(requestConditions), "Service does not support the If-None-Match header for this operation."); + Argument.AssertNull(requestConditions?.IfModifiedSince, nameof(requestConditions), "Service does not support the If-Modified-Since header for this operation."); using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(JobRouterClient)}.{nameof(UpdateJob)}"); scope.Start(); @@ -566,7 +566,7 @@ public virtual async Task> CreateWorkerAsync( var response = await UpsertWorkerAsync( workerId: options.WorkerId, content: request.ToRequestContent(), - requestConditions: options.RequestConditions, + requestConditions: options.RequestConditions ?? new RequestConditions(), context: FromCancellationToken(cancellationToken)) .ConfigureAwait(false); @@ -613,7 +613,7 @@ public virtual Response CreateWorker( var response = UpsertWorker( workerId: options.WorkerId, content: request.ToRequestContent(), - requestConditions: options.RequestConditions, + requestConditions: options.RequestConditions ?? new RequestConditions(), context: FromCancellationToken(cancellationToken)); return Response.FromValue(RouterWorker.FromResponse(response), response); @@ -641,7 +641,7 @@ public virtual async Task> UpdateWorkerAsync( var response = await UpsertWorkerAsync( workerId: worker.Id, content: worker.ToRequestContent(), - requestConditions: requestConditions, + requestConditions: requestConditions ?? new RequestConditions(), context: FromCancellationToken(cancellationToken)) .ConfigureAwait(false); @@ -670,7 +670,7 @@ public virtual Response UpdateWorker( var response = UpsertWorker( workerId: worker.Id, content: worker.ToRequestContent(), - requestConditions: requestConditions, + requestConditions: requestConditions ?? new RequestConditions(), context: FromCancellationToken(cancellationToken)); return Response.FromValue(RouterWorker.FromResponse(response), response); @@ -705,8 +705,8 @@ public virtual async Task UpdateWorkerAsync(string workerId, RequestCo Argument.AssertNotNullOrEmpty(workerId, nameof(workerId)); Argument.AssertNotNull(content, nameof(content)); - Argument.AssertNull(requestConditions.IfNoneMatch, nameof(requestConditions), "Service does not support the If-None-Match header for this operation."); - Argument.AssertNull(requestConditions.IfModifiedSince, nameof(requestConditions), "Service does not support the If-Modified-Since header for this operation."); + Argument.AssertNull(requestConditions?.IfNoneMatch, nameof(requestConditions), "Service does not support the If-None-Match header for this operation."); + Argument.AssertNull(requestConditions?.IfModifiedSince, nameof(requestConditions), "Service does not support the If-Modified-Since header for this operation."); using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(JobRouterClient)}.{nameof(UpdateWorker)}"); scope.Start(); @@ -745,8 +745,8 @@ public virtual Response UpdateWorker(string workerId, RequestContent content, Re Argument.AssertNotNullOrEmpty(workerId, nameof(workerId)); Argument.AssertNotNull(content, nameof(content)); - Argument.AssertNull(requestConditions.IfNoneMatch, nameof(requestConditions), "Service does not support the If-None-Match header for this operation."); - Argument.AssertNull(requestConditions.IfModifiedSince, nameof(requestConditions), "Service does not support the If-Modified-Since header for this operation."); + Argument.AssertNull(requestConditions?.IfNoneMatch, nameof(requestConditions), "Service does not support the If-None-Match header for this operation."); + Argument.AssertNull(requestConditions?.IfModifiedSince, nameof(requestConditions), "Service does not support the If-Modified-Since header for this operation."); using DiagnosticScope scope = ClientDiagnostics.CreateScope($"{nameof(JobRouterClient)}.{nameof(UpdateWorker)}"); scope.Start(); diff --git a/sdk/communication/Azure.Communication.JobRouter/src/Models/ReclassifyExceptionAction.cs b/sdk/communication/Azure.Communication.JobRouter/src/Models/ReclassifyExceptionAction.cs index 989fac90ce9d3..15b5b701cd599 100644 --- a/sdk/communication/Azure.Communication.JobRouter/src/Models/ReclassifyExceptionAction.cs +++ b/sdk/communication/Azure.Communication.JobRouter/src/Models/ReclassifyExceptionAction.cs @@ -17,6 +17,7 @@ public partial class ReclassifyExceptionAction : IUtf8JsonSerializable public ReclassifyExceptionAction() { Kind = "reclassify"; + _labelsToUpsert = new ChangeTrackingDictionary(); } [CodeGenMember("LabelsToUpsert")] @@ -43,7 +44,7 @@ internal IDictionary _labelsToUpsert /// /// (optional) Dictionary containing the labels to update (or add if not existing) in key-value pairs /// - public IDictionary LabelsToUpsert { get; } + public IDictionary LabelsToUpsert { get; } = new Dictionary(); /// /// (optional) The new classification policy that will determine queue, priority @@ -76,7 +77,7 @@ void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) writer.WriteNullValue(); continue; } - writer.WriteObjectValue(item.Value); + writer.WriteObjectValue(item.Value.ToObjectFromJson()); } writer.WriteEndObject(); } diff --git a/sdk/communication/Azure.Communication.JobRouter/src/Models/RouterChannel.cs b/sdk/communication/Azure.Communication.JobRouter/src/Models/RouterChannel.cs index 2fe7c05cf04f3..4060ca64a3f1a 100644 --- a/sdk/communication/Azure.Communication.JobRouter/src/Models/RouterChannel.cs +++ b/sdk/communication/Azure.Communication.JobRouter/src/Models/RouterChannel.cs @@ -29,6 +29,8 @@ public RouterChannel(string channelId, int capacityCostPerJob) void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) { writer.WriteStartObject(); + writer.WritePropertyName("channelId"u8); + writer.WriteStringValue(ChannelId); writer.WritePropertyName("capacityCostPerJob"u8); writer.WriteNumberValue(CapacityCostPerJob); diff --git a/sdk/communication/Azure.Communication.JobRouter/src/Models/RouterJob.cs b/sdk/communication/Azure.Communication.JobRouter/src/Models/RouterJob.cs index 32202c76a9271..e4d8f9f6e8946 100644 --- a/sdk/communication/Azure.Communication.JobRouter/src/Models/RouterJob.cs +++ b/sdk/communication/Azure.Communication.JobRouter/src/Models/RouterJob.cs @@ -17,8 +17,10 @@ public partial class RouterJob : IUtf8JsonSerializable public RouterJob(string jobId) { Argument.AssertNotNullOrWhiteSpace(jobId, nameof(jobId)); - Id = jobId; + + _labels = new ChangeTrackingDictionary(); + _tags = new ChangeTrackingDictionary(); } /// diff --git a/sdk/communication/Azure.Communication.JobRouter/src/Models/RouterJobNote.cs b/sdk/communication/Azure.Communication.JobRouter/src/Models/RouterJobNote.cs index aff1b839b58b9..37ca39c8ad993 100644 --- a/sdk/communication/Azure.Communication.JobRouter/src/Models/RouterJobNote.cs +++ b/sdk/communication/Azure.Communication.JobRouter/src/Models/RouterJobNote.cs @@ -2,6 +2,7 @@ // Licensed under the MIT License. using System; +using System.Text.Json; using Azure.Core; namespace Azure.Communication.JobRouter @@ -9,7 +10,7 @@ namespace Azure.Communication.JobRouter /// /// A note attached to a job /// - public partial class RouterJobNote + public partial class RouterJobNote : IUtf8JsonSerializable { /// Initializes a new instance of RouterJobNote. /// The message contained in the note. @@ -25,5 +26,18 @@ public RouterJobNote(string message) /// The time at which the note was added in UTC. If not provided, will default to the current time. /// public DateTimeOffset? AddedAt { get; set; } + + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + { + writer.WriteStartObject(); + writer.WritePropertyName("message"u8); + writer.WriteStringValue(Message); + if (Optional.IsDefined(AddedAt)) + { + writer.WritePropertyName("addedAt"u8); + writer.WriteStringValue(AddedAt.Value, "O"); + } + writer.WriteEndObject(); + } } } diff --git a/sdk/communication/Azure.Communication.JobRouter/src/Models/RouterWorker.cs b/sdk/communication/Azure.Communication.JobRouter/src/Models/RouterWorker.cs index 96e0673eb12c0..3d5848bb3780e 100644 --- a/sdk/communication/Azure.Communication.JobRouter/src/Models/RouterWorker.cs +++ b/sdk/communication/Azure.Communication.JobRouter/src/Models/RouterWorker.cs @@ -19,6 +19,9 @@ public RouterWorker(string workerId) Argument.AssertNotNullOrWhiteSpace(workerId, nameof(workerId)); Id = workerId; + + _labels = new ChangeTrackingDictionary(); + _tags = new ChangeTrackingDictionary(); } /// diff --git a/sdk/communication/Azure.Communication.JobRouter/tests/Infrastructure/RouterLiveTestBase.cs b/sdk/communication/Azure.Communication.JobRouter/tests/Infrastructure/RouterLiveTestBase.cs index 30ff3e6b278ba..cb21fd0c9f3b3 100644 --- a/sdk/communication/Azure.Communication.JobRouter/tests/Infrastructure/RouterLiveTestBase.cs +++ b/sdk/communication/Azure.Communication.JobRouter/tests/Infrastructure/RouterLiveTestBase.cs @@ -20,7 +20,7 @@ public class RouterLiveTestBase : RecordedTestBase private ConcurrentDictionary> _testCleanupTasks; private const string URIDomainRegEx = @"https://([^/?]+)"; - public RouterLiveTestBase(bool isAsync, RecordedTestMode? mode = RecordedTestMode.Playback) : base(isAsync, RecordedTestMode.Record) + public RouterLiveTestBase(bool isAsync, RecordedTestMode? mode = RecordedTestMode.Playback) : base(isAsync, mode) { _testCleanupTasks = new ConcurrentDictionary>(); JsonPathSanitizers.Add("$..token"); @@ -43,6 +43,8 @@ public async Task CleanUp() var mode = TestEnvironment.Mode ?? Mode; if (mode != RecordedTestMode.Playback) { + await Task.Delay(TimeSpan.FromSeconds(3)); + var testName = TestContext.CurrentContext.Test.FullName; var popTestResources = _testCleanupTasks.TryRemove(testName, out var cleanupTasks); @@ -52,8 +54,19 @@ public async Task CleanUp() { while (cleanupTasks.Count > 0) { + await Task.Delay(TimeSpan.FromSeconds(1)); + var executableTask = cleanupTasks.Pop(); - await Task.Run(() => executableTask.Start()); + try + { + await Task.Run(() => executableTask.Start()); + } + catch (Exception) + { + // Retry after delay + await Task.Delay(TimeSpan.FromSeconds(3)); + await Task.Run(() => executableTask.Start()); + } } } } diff --git a/sdk/communication/Azure.Communication.JobRouter/tests/RouterClients/ClassificationPolicyLiveTests.cs b/sdk/communication/Azure.Communication.JobRouter/tests/RouterClients/ClassificationPolicyLiveTests.cs index b82edb785b75e..de6ce66b7affa 100644 --- a/sdk/communication/Azure.Communication.JobRouter/tests/RouterClients/ClassificationPolicyLiveTests.cs +++ b/sdk/communication/Azure.Communication.JobRouter/tests/RouterClients/ClassificationPolicyLiveTests.cs @@ -106,17 +106,18 @@ public async Task CreateClassificationPolicyTest() Assert.IsTrue(!string.IsNullOrWhiteSpace(createClassificationPolicy.FallbackQueueId) && createClassificationPolicy.FallbackQueueId == createQueueResponse.Value.Id); Assert.IsFalse(string.IsNullOrWhiteSpace(createClassificationPolicy.Name)); + updateClassificationPolicyResponse.Value.FallbackQueueId = null; + updateClassificationPolicyResponse.Value.PrioritizationRule = null; + updateClassificationPolicyResponse.Value.QueueSelectorAttachments.Clear(); + updateClassificationPolicyResponse.Value.WorkerSelectorAttachments.Clear(); + updateClassificationPolicyResponse.Value.Name = $"{classificationPolicyName}-updated"; + updateClassificationPolicyResponse = await routerClient.UpdateClassificationPolicyAsync( - new ClassificationPolicy(classificationPolicyId) - { - FallbackQueueId = null, - PrioritizationRule = null, - Name = $"{classificationPolicyName}-updated", - }); + updateClassificationPolicyResponse.Value); var updateClassificationPolicy = updateClassificationPolicyResponse.Value; - Assert.IsTrue(updateClassificationPolicy.QueueSelectorAttachments.Any()); - Assert.IsTrue(updateClassificationPolicy.WorkerSelectorAttachments.Any()); + Assert.IsFalse(updateClassificationPolicy.QueueSelectorAttachments.Any()); + Assert.IsFalse(updateClassificationPolicy.WorkerSelectorAttachments.Any()); Assert.AreEqual(updateClassificationPolicy.Name, $"{classificationPolicyName}-updated"); } diff --git a/sdk/communication/Azure.Communication.JobRouter/tests/RouterClients/ExceptionPolicyLiveTests.cs b/sdk/communication/Azure.Communication.JobRouter/tests/RouterClients/ExceptionPolicyLiveTests.cs index e1b40f8878b86..5b170287a9f91 100644 --- a/sdk/communication/Azure.Communication.JobRouter/tests/RouterClients/ExceptionPolicyLiveTests.cs +++ b/sdk/communication/Azure.Communication.JobRouter/tests/RouterClients/ExceptionPolicyLiveTests.cs @@ -130,7 +130,6 @@ public async Task CreateExceptionPolicyTest_WaitTime() var exceptionPolicy = createExceptionPolicyResponse.Value; - Assert.AreEqual(exceptionPolicyId, exceptionPolicy.Id); Assert.AreEqual(exceptionPolicyId, exceptionPolicy.Id); Assert.DoesNotThrow(() => { diff --git a/sdk/communication/Azure.Communication.JobRouter/tests/RouterClients/RouterJobLiveTests.cs b/sdk/communication/Azure.Communication.JobRouter/tests/RouterClients/RouterJobLiveTests.cs index 97b680762b36f..df985060d1285 100644 --- a/sdk/communication/Azure.Communication.JobRouter/tests/RouterClients/RouterJobLiveTests.cs +++ b/sdk/communication/Azure.Communication.JobRouter/tests/RouterClients/RouterJobLiveTests.cs @@ -67,6 +67,13 @@ public async Task UpdateJobWithNotesWorksCorrectly() Assert.IsNotEmpty(updatedJob1Response.Notes); Assert.IsTrue(updatedJob1Response.Notes.Count == 1); + + // in-test cleanup + if (Mode != RecordedTestMode.Playback) + { + await Task.Delay(TimeSpan.FromSeconds(3)); + } + await routerClient.CancelJobAsync(jobId1); // other wise queue deletion will throw error } [Test] @@ -88,7 +95,6 @@ public async Task GetJobsTest() Priority = 1, }); - AddForCleanup(new Task(async () => await routerClient.CancelJobAsync(jobId1))); AddForCleanup(new Task(async () => await routerClient.DeleteJobAsync(jobId1))); var createJob1 = createJob1Response.Value; @@ -109,7 +115,6 @@ public async Task GetJobsTest() { Priority = 1 }); - AddForCleanup(new Task(async () => await routerClient.CancelJobAsync(jobId2))); AddForCleanup(new Task(async () => await routerClient.DeleteJobAsync(jobId2))); var createJob2 = createJob2Response.Value; @@ -133,6 +138,10 @@ public async Task GetJobsTest() Assert.IsTrue(allJobs.Contains(createJob1.Id)); Assert.IsTrue(allJobs.Contains(createJob2.Id)); + + // in-test cleanup + await routerClient.CancelJobAsync(jobId1); // other wise queue deletion will throw error + await routerClient.CancelJobAsync(jobId2); // other wise queue deletion will throw error } [Test] @@ -156,7 +165,6 @@ public async Task GetJobsWithSchedulingFiltersTest() MatchingMode = new ScheduleAndSuspendMode(timeToEnqueueJob), }); - AddForCleanup(new Task(async () => await routerClient.CancelJobAsync(jobId1))); AddForCleanup(new Task(async () => await routerClient.DeleteJobAsync(jobId1))); var createJob1 = createJob1Response.Value; // test get jobs @@ -172,6 +180,13 @@ public async Task GetJobsWithSchedulingFiltersTest() } Assert.IsTrue(allJobs.Contains(createJob1.Id)); + + // in-test cleanup + if (Mode != RecordedTestMode.Playback) + { + await Task.Delay(TimeSpan.FromSeconds(3)); + } + await routerClient.CancelJobAsync(jobId1); // other wise queue deletion will throw error } [Test] @@ -215,7 +230,6 @@ public async Task CreateJobWithClassificationPolicy_w_StaticPriority() }); var createJob = createJobResponse.Value; - AddForCleanup(new Task(async () => await routerClient.CancelJobAsync(jobId))); AddForCleanup(new Task(async () => await routerClient.DeleteJobAsync(jobId))); var queuedJob = await Poll(async () => await routerClient.GetJobAsync(createJob.Id), @@ -225,6 +239,14 @@ public async Task CreateJobWithClassificationPolicy_w_StaticPriority() Assert.AreEqual(createJob.Id, queuedJob.Value.Id); Assert.AreEqual(10, queuedJob.Value.Priority); // from classification policy Assert.AreEqual(createQueue.Id, queuedJob.Value.QueueId); // from direct queue assignment + + // in-test cleanup + if (Mode != RecordedTestMode.Playback) + { + await Task.Delay(TimeSpan.FromSeconds(5)); + } + await routerClient.CancelJobAsync(createJob.Id); // other wise queue deletion will throw error + await routerAdministrationClient.DeleteClassificationPolicyAsync(classificationPolicyId); // other wise default queue deletion will throw error } [Test] @@ -260,7 +282,6 @@ public async Task CreateJobWithClassificationPolicy_w_StaticQueueSelector() { ChannelReference = "123" }); - AddForCleanup(new Task(async () => await routerClient.CancelJobAsync(jobId))); AddForCleanup(new Task(async () => await routerClient.DeleteJobAsync(jobId))); var createJob = createJobResponse.Value; @@ -273,6 +294,10 @@ public async Task CreateJobWithClassificationPolicy_w_StaticQueueSelector() Assert.AreEqual(createQueue2.Id, queuedJob.Value.QueueId); // from queue selector in classification policy // in-test cleanup + if (Mode != RecordedTestMode.Playback) + { + await Task.Delay(TimeSpan.FromSeconds(5)); + } await routerClient.CancelJobAsync(createJob.Id); // other wise queue deletion will throw error await routerAdministrationClient.DeleteClassificationPolicyAsync(classificationPolicyId); // other wise default queue deletion will throw error } @@ -311,7 +336,6 @@ public async Task CreateJobWithClassificationPolicy_w_FallbackQueue() ChannelReference = "123", QueueId = null }); - AddForCleanup(new Task(async () => await routerClient.CancelJobAsync(jobId))); AddForCleanup(new Task(async () => await routerClient.DeleteJobAsync(jobId))); var createJob = createJobResponse.Value; @@ -321,6 +345,10 @@ public async Task CreateJobWithClassificationPolicy_w_FallbackQueue() Assert.AreEqual(RouterJobStatus.Queued, queuedJob.Value.Status); Assert.AreEqual(1, queuedJob.Value.Priority); // default priority value Assert.AreEqual(createQueue2.Id, queuedJob.Value.QueueId); // from fallback queue of classification policy + + // in-test cleanup + await routerClient.CancelJobAsync(createJob.Id); // other wise queue deletion will throw error + await routerAdministrationClient.DeleteClassificationPolicyAsync(classificationPolicyId); // other wise default queue deletion will throw error } [Test] @@ -357,7 +385,6 @@ public async Task CreateJobWithQueue_And_ClassificationPolicy_w_FallbackQueue() QueueId = createQueue1.Id, }); var createJob = createJobResponse.Value; - AddForCleanup( new Task(async () => await routerClient.CancelJobAsync(createJob.Id))); AddForCleanup(new Task(async () => await routerClient.DeleteJobAsync(createJob.Id))); var queuedJob = await Poll(async () => await routerClient.GetJobAsync(createJob.Id), @@ -367,6 +394,10 @@ public async Task CreateJobWithQueue_And_ClassificationPolicy_w_FallbackQueue() Assert.AreEqual(createJob.Id, queuedJob.Value.Id); Assert.AreEqual(1, queuedJob.Value.Priority); // default value Assert.AreEqual(createQueue1.Id, queuedJob.Value.QueueId); // from queue selector in classification policy + + // in-test cleanup + await routerClient.CancelJobAsync(createJob.Id); // other wise queue deletion will throw error + await routerAdministrationClient.DeleteClassificationPolicyAsync(classificationPolicyId); // other wise default queue deletion will throw error } [Test] @@ -392,6 +423,16 @@ public async Task CreateJobWithQueueAndMatchMode() AddForCleanup(new Task(async () => await routerClient.DeleteJobAsync(createJob1.Id))); Assert.IsTrue(createJob1.MatchingMode.GetType() == typeof(QueueAndMatchMode)); + + var queuedJob = await Poll(async () => await routerClient.GetJobAsync(createJob1.Id), + job => job.Value.Status == RouterJobStatus.Queued, TimeSpan.FromSeconds(10)); + + // in-test cleanup + if (Mode != RecordedTestMode.Playback) + { + await Task.Delay(TimeSpan.FromSeconds(3)); + } + await routerClient.CancelJobAsync(createJob1.Id); // other wise queue deletion will throw error } [Test] @@ -417,6 +458,13 @@ public async Task CreateJobWithSuspendMode() AddForCleanup(new Task(async () => await routerClient.DeleteJobAsync(createJob1.Id))); Assert.IsTrue(createJob1.MatchingMode.GetType() == typeof(SuspendMode)); + + // in-test cleanup + if (Mode != RecordedTestMode.Playback) + { + await Task.Delay(TimeSpan.FromSeconds(3)); + } + await routerClient.CancelJobAsync(createJob1.Id); // other wise queue deletion will throw error } [Test] @@ -431,7 +479,7 @@ public async Task CreateJobWithScheduleAndSuspendMode() // Create 1 job var jobId1 = GenerateUniqueId($"{IdPrefix}{nameof(CreateJobWithScheduleAndSuspendMode)}1"); - var timeToEnqueueJob = GetOrSetScheduledTimeUtc(DateTimeOffset.UtcNow.AddSeconds(7)); + var timeToEnqueueJob = GetOrSetScheduledTimeUtc(new DateTimeOffset(2100, 1, 1, 1, 1, 1, TimeSpan.Zero)); var createJob1Response = await routerClient.CreateJobAsync( new CreateJobOptions(jobId1, channelId, createQueue.Id) { @@ -443,6 +491,12 @@ public async Task CreateJobWithScheduleAndSuspendMode() AddForCleanup(new Task(async () => await routerClient.DeleteJobAsync(createJob1.Id))); Assert.IsTrue(createJob1.MatchingMode.GetType() == typeof(ScheduleAndSuspendMode)); + + var queuedJob = await Poll(async () => await routerClient.GetJobAsync(createJob1.Id), + job => job.Value.Status == RouterJobStatus.Scheduled, TimeSpan.FromSeconds(10)); + + // in-test cleanup + await routerClient.CancelJobAsync(createJob1.Id); // other wise queue deletion will throw error } [Test] @@ -475,7 +529,6 @@ public async Task UpdateJobTest() createJobOptions.Tags.Append(tags); var createJobResponse = await routerClient.CreateJobAsync(createJobOptions); - AddForCleanup(new Task(async () => await routerClient.DeleteJobAsync(createJobResponse.Value.Id))); var updatedLabels = new Dictionary { @@ -508,6 +561,14 @@ public async Task UpdateJobTest() ["Tag_3"] = new LabelValue("Value_Updated_3"), ["Tag_4"] = new LabelValue("Value_4") }); + + // in-test cleanup + if (Mode != RecordedTestMode.Playback) + { + await Task.Delay(TimeSpan.FromSeconds(5)); + } + await routerClient.CancelJobAsync(jobId1); // other wise queue deletion will throw error + await routerClient.DeleteJobAsync(jobId1); // other wise queue deletion will throw error } [Test] @@ -546,6 +607,13 @@ public async Task ReclassifyJob() await routerClient.ReclassifyJobAsync(jobId1, CancellationToken.None); Assert.AreEqual(createJob1.QueueId, createQueue.Id); + + // in-test cleanup + if (Mode != RecordedTestMode.Playback) + { + await Task.Delay(TimeSpan.FromSeconds(3)); + } + await routerClient.CancelJobAsync(jobId1); // other wise queue deletion will throw error } #endregion Job Tests diff --git a/sdk/communication/Azure.Communication.JobRouter/tests/RouterClients/RouterWorkerLiveTests.cs b/sdk/communication/Azure.Communication.JobRouter/tests/RouterClients/RouterWorkerLiveTests.cs index cb9fbf466c488..81e172821dfac 100644 --- a/sdk/communication/Azure.Communication.JobRouter/tests/RouterClients/RouterWorkerLiveTests.cs +++ b/sdk/communication/Azure.Communication.JobRouter/tests/RouterClients/RouterWorkerLiveTests.cs @@ -6,6 +6,7 @@ using System.Linq; using System.Threading.Tasks; using Azure.Communication.JobRouter.Tests.Infrastructure; +using Azure.Core.TestFramework; using NUnit.Framework; namespace Azure.Communication.JobRouter.Tests.RouterClients @@ -57,6 +58,11 @@ public async Task CreateWorkerTest() Assert.NotNull(routerWorkerResponse.Value); AssertRegisteredWorkerIsValid(routerWorkerResponse, workerId, queues, capacity, workerLabels, channels); + + routerWorkerResponse.Value.AvailableForOffers = false; + routerWorkerResponse.Value.Queues.RemoveAt(0); + + await routerClient.UpdateWorkerAsync(routerWorkerResponse); } [Test] @@ -72,6 +78,9 @@ public async Task RegisterWorkerShouldNotThrowArgumentNullExceptionTest() AddForCleanup(new Task(async () => await routerClient.DeleteWorkerAsync(workerId))); Assert.NotNull(routerWorkerResponse.Value); + + routerWorkerResponse.Value.AvailableForOffers = false; + await routerClient.UpdateWorkerAsync(routerWorkerResponse); } /*[Test] @@ -288,29 +297,25 @@ public async Task UpdateWorkerTest() AssertRegisteredWorkerIsValid(routerWorkerResponse, workerId, queues, capacity, workerLabels, channels, workerTags); - // Remove queue assignment, channel configuration and label - queues.Remove(createQueueResponse.Value.Id); - channels.RemoveAt(0); - workerLabels[workerLabels.First().Key] = null; - workerTags[workerTags.First().Key] = null; - - var updatedWorker = new RouterWorker(workerId) - { - AvailableForOffers = false - }; - updatedWorker.Labels.Append(workerLabels); - updatedWorker.Channels.AddRange(channels); - updatedWorker.Queues.AddRange(queues); - updatedWorker.Tags.Append(workerTags); + var updatedWorker = routerWorkerResponse.Value; + updatedWorker.Labels[workerLabels.First().Key] = null; + updatedWorker.Tags[workerTags.First().Key] = null; + updatedWorker.Queues.Remove(createQueueResponse.Value.Id); + updatedWorker.Channels.RemoveAt(0); var updateWorkerResponse = await routerClient.UpdateWorkerAsync(updatedWorker); - updatedWorker.Channels.RemoveAt(0); + updatedWorker.Labels.Remove("Id"); updatedWorker.Labels.Remove(workerLabels.First().Key); updatedWorker.Tags.Remove(workerTags.First().Key); AssertRegisteredWorkerIsValid(updateWorkerResponse, workerId, new List(), capacity, updatedWorker.Labels, updatedWorker.Channels, updatedWorker.Tags); + + // in-test cleanup + updatedWorker.AvailableForOffers = false; + + await routerClient.UpdateWorkerAsync(updatedWorker); } #endregion Worker Tests diff --git a/sdk/communication/Azure.Communication.JobRouter/tests/Scenarios/AssignmentScenario.cs b/sdk/communication/Azure.Communication.JobRouter/tests/Scenarios/AssignmentScenario.cs index 084c2f84bf11f..5e7a6b6ff1395 100644 --- a/sdk/communication/Azure.Communication.JobRouter/tests/Scenarios/AssignmentScenario.cs +++ b/sdk/communication/Azure.Communication.JobRouter/tests/Scenarios/AssignmentScenario.cs @@ -5,6 +5,7 @@ using System.Linq; using System.Threading.Tasks; using Azure.Communication.JobRouter.Tests.Infrastructure; +using Azure.Core.TestFramework; using NUnit.Framework; namespace Azure.Communication.JobRouter.Tests.Scenarios @@ -94,6 +95,14 @@ public async Task Scenario() Assert.IsNotNull(finalJobState.Value.Assignments[accept.Value.AssignmentId].ClosedAt); Assert.IsNotEmpty(finalJobState.Value.Notes); Assert.IsTrue(finalJobState.Value.Notes.Count == 2); + + // in-test cleanup + worker.Value.AvailableForOffers = false; + await client.UpdateWorkerAsync(worker); + if (Mode != RecordedTestMode.Playback) + { + await Task.Delay(TimeSpan.FromSeconds(5)); + } } } } diff --git a/sdk/communication/Azure.Communication.JobRouter/tests/Scenarios/CancellationScenario.cs b/sdk/communication/Azure.Communication.JobRouter/tests/Scenarios/CancellationScenario.cs index 779a557d79c35..67c7dbadd167d 100644 --- a/sdk/communication/Azure.Communication.JobRouter/tests/Scenarios/CancellationScenario.cs +++ b/sdk/communication/Azure.Communication.JobRouter/tests/Scenarios/CancellationScenario.cs @@ -46,7 +46,6 @@ public async Task Scenario() { Priority = 1, }); - AddForCleanup(new Task(async () => await client.CancelJobAsync(jobId))); AddForCleanup(new Task(async () => await client.DeleteJobAsync(jobId))); var job = await Poll(async () => await client.GetJobAsync(createJob.Value.Id), diff --git a/sdk/communication/Azure.Communication.JobRouter/tests/Scenarios/QueueScenario.cs b/sdk/communication/Azure.Communication.JobRouter/tests/Scenarios/QueueScenario.cs index decdd401dda9b..5d2df383d0c54 100644 --- a/sdk/communication/Azure.Communication.JobRouter/tests/Scenarios/QueueScenario.cs +++ b/sdk/communication/Azure.Communication.JobRouter/tests/Scenarios/QueueScenario.cs @@ -165,6 +165,7 @@ public async Task QueueingWithClassificationPolicyWithConditionalLabelSelector() var job = await Poll(async () => await client.GetJobAsync(createJob.Value.Id), x => x.Value.Status == RouterJobStatus.Queued, TimeSpan.FromSeconds(10)); + Assert.AreEqual(RouterJobStatus.Queued, job.Value.Status); Assert.AreEqual(job.Value.QueueId, queueResponse.Value.Id); } diff --git a/sdk/communication/Azure.Communication.JobRouter/tests/Scenarios/SchedulingScenario.cs b/sdk/communication/Azure.Communication.JobRouter/tests/Scenarios/SchedulingScenario.cs index 1a22416b1ebe9..d4bdbf4116df1 100644 --- a/sdk/communication/Azure.Communication.JobRouter/tests/Scenarios/SchedulingScenario.cs +++ b/sdk/communication/Azure.Communication.JobRouter/tests/Scenarios/SchedulingScenario.cs @@ -47,7 +47,7 @@ public async Task SimpleSchedulingScenario() AddForCleanup(new Task(async () => await client.UpdateWorkerAsync(new RouterWorker(workerId1) { AvailableForOffers = false }))); AddForCleanup(new Task(async () => await client.DeleteWorkerAsync(workerId1))); - var jobId = GenerateUniqueId($"JobId-SQ-{ScenarioPrefix}"); + var jobId = GenerateUniqueId($"{IdPrefix}-JobId-SQ-{ScenarioPrefix}"); var timeToEnqueueJob = GetOrSetScheduledTimeUtc(DateTimeOffset.UtcNow.AddSeconds(10)); var createJob = await client.CreateJobAsync(