public void CheckCallProgressHttpTriggerConcurrentRuns() { FunctionSettings functionSettings = FunctionSettings.Load(@".\functionSettings.json"); using (HttpClient httpClient = new HttpClient()) { string accessToken = AzureADHelper.GetAccessTokenAsync(functionSettings.Authority, functionSettings.ApplicationId, functionSettings.ClientSecret, functionSettings.ResourceId).Result; if (accessToken == null) { throw new Exception("Could not obtain access token!"); } httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken); Task[] threads = new Task[_concurrentConfig.NumberOfThreads]; for (int i = 0; i < _concurrentConfig.NumberOfThreads; i++) { threads[i] = Task.Run( new Action( () => CheckCallProgressRunnerAsync(httpClient, functionSettings, _concurrentConfig.TestConfigurationQueue).Wait())); } _log.LogInformation("Waiting on threads..."); Task.WaitAll(threads); _log.LogInformation("All threads completed..."); } _concurrentConfig.Save(GlobalTestConstants.ConcurrentTestConfigurationFilePath); }
/// <summary> /// Runner utility for testing CheckCallProgress. /// </summary> /// <param name="httpClient">The HttpClient instance to use.</param> /// <param name="functionSettings">Configuration information for calling the remote function.</param> /// <param name="queue">A queue of test to run.</param> /// <returns>An asynchronous task.</returns> public async Task CheckCallProgressRunnerAsync(HttpClient httpClient, FunctionSettings functionSettings, ConcurrentQueue <TestConfiguration> queue) { TestConfiguration nextTestConfiguration = null; while (!queue.IsEmpty) { if (queue.TryDequeue(out nextTestConfiguration)) { HttpContent requestContent = CreateHttpPostContent(nextTestConfiguration.CallSid); HttpResponseMessage httpResponse = await httpClient.PostAsync(functionSettings.CheckCallProgressUrl, requestContent); string responseContent = await httpResponse.Content.ReadAsStringAsync(); CheckCallProgressResponse response = JsonConvert.DeserializeObject <CheckCallProgressResponse>(responseContent); Assert.AreEqual(nextTestConfiguration.CallSid, response.CallSid); Assert.AreEqual((int)CommonStatusCode.Ok, response.StatusCode); Assert.AreEqual(Enum.GetName(typeof(CommonStatusCode), CommonStatusCode.Ok), response.StatusDesc); Assert.IsFalse(response.HasError); Assert.AreEqual(0, response.ErrorCode); Assert.IsNull(response.ErrorDetails); _log.LogInformation("Writing returned call status to test configuration..."); nextTestConfiguration.CallStatus = response.Status; } TH.Thread.Sleep(2000); } }
/// <summary> /// Runner for ensuring TranscribeCallHttpTrigger runs correctly for concurrent executions against a remote Azure Function. /// </summary> /// <param name="httpClient">The HttpClient instance to use.</param> /// <param name="functionSettings">Configuration information required to make calls to the Azure Function.</param> /// <param name="queue">The queue of tests to run.</param> /// <returns>An asynchronous task.</returns> public async Task TranscribeCallRunnerAsync(HttpClient httpClient, FunctionSettings functionSettings, ConcurrentQueue <TestConfiguration> queue) { TestConfiguration nextTestConfiguration = null; while (!queue.IsEmpty) { if (queue.TryDequeue(out nextTestConfiguration)) { HttpContent requestContent = CreateHttpPostContent(nextTestConfiguration.CallSid, nextTestConfiguration.RecordingUri); HttpResponseMessage httpResponse = await httpClient.PostAsync(functionSettings.TranscribeCallUrl, requestContent); string responseContent = await httpResponse.Content.ReadAsStringAsync(); TranscribeCallResponse response = JsonConvert.DeserializeObject <TranscribeCallResponse>(responseContent); Assert.AreEqual(nextTestConfiguration.CallSid, response.CallSid); Assert.IsFalse(string.IsNullOrWhiteSpace(response.Text)); Assert.AreEqual((int)CommonStatusCode.Ok, response.StatusCode); Assert.AreEqual(Enum.GetName(typeof(CommonStatusCode), CommonStatusCode.Ok), response.StatusDesc); Assert.IsFalse(response.HasError); Assert.AreEqual((int)CommonErrorCode.NoError, response.ErrorCode); Assert.IsNull(response.ErrorDetails); _log.LogInformation($"Transcription returned ({nextTestConfiguration.CallSid}):"); _log.LogInformation(response.Text); nextTestConfiguration.Transcript = response.Text; } TH.Thread.Sleep(2000); } }
public void TranscribeCallHttpTriggerOpenSpeechRepositoryConcurrentRuns() { ConcurrentTestConfiguration testConfiguration = ConcurrentTestConfiguration.Load(@".\TestConfigurations\TranscribeCall\multiThreaded\testconfig_test1.json"); FunctionSettings functionSettings = FunctionSettings.Load(@".\functionSettings.json"); using (HttpClient httpClient = new HttpClient()) { string accessToken = AzureADHelper.GetAccessTokenAsync(functionSettings.Authority, functionSettings.ApplicationId, functionSettings.ClientSecret, functionSettings.ResourceId).Result; if (accessToken == null) { throw new Exception("Could not obtain access token!"); } httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken); Task[] threads = new Task[testConfiguration.NumberOfThreads]; for (int i = 0; i < testConfiguration.NumberOfThreads; i++) { threads[i] = Task.Run( new Action( () => TranscribeCallRunnerAsync(httpClient, functionSettings, testConfiguration.TestConfigurationQueue).Wait())); } _log.LogInformation("Waiting on threads..."); Task.WaitAll(threads); _log.LogInformation("All threads completed..."); } }
/// <summary> /// Runner for ensure DeleteRecordingsHttpTrigger runs correctly against remote Azure Function. /// </summary> /// <param name="httpClient">The HttpClient instance to use.</param> /// <param name="functionSettings">Configuration information required to make calls to the Azure Functions.</param> /// <param name="queue">The queue of tests to run.</param> /// <returns>An asynchronous task.</returns> public async Task DeleteRecordingsRunnerAsync(HttpClient httpClient, FunctionSettings functionSettings, ConcurrentQueue <TestConfiguration> queue) { TestConfiguration nextTestConfiguration = null; while (!queue.IsEmpty) { if (queue.TryDequeue(out nextTestConfiguration)) { HttpContent requestContent = CreateHttpPostContent(nextTestConfiguration.CallSid); HttpResponseMessage httpResponse = await httpClient.PostAsync(functionSettings.DeleteRecordingsUrl, requestContent); string responseContent = await httpResponse.Content.ReadAsStringAsync(); DeleteRecordingsResponse response = JsonConvert.DeserializeObject <DeleteRecordingsResponse>(responseContent); Assert.AreEqual(nextTestConfiguration.CallSid, response.CallSid); Assert.IsTrue(response.AreAllRecordingsDeleted); Assert.AreEqual((int)CommonStatusCode.Ok, response.StatusCode); Assert.AreEqual(Enum.GetName(typeof(CommonStatusCode), CommonStatusCode.Ok), response.StatusDesc); Assert.IsFalse(response.HasError); Assert.AreEqual((int)CommonErrorCode.NoError, response.ErrorCode); Assert.IsNull(response.ErrorDetails); nextTestConfiguration.AllRecordingsDeleted = response.AreAllRecordingsDeleted; } TH.Thread.Sleep(2000); } }
/// <summary> /// Runner for ensuring ExtractInfoHttpTrigger runs correctly against a remote Azure Function. /// </summary> /// <param name="httpClient">The HttpClient instance to use.</param> /// <param name="functionSettings">Configuration information required for calling the Azure Function.</param> /// <param name="queue">The queue of tests to run.</param> /// <returns>An asynchronous task.</returns> public async Task ExtractInfoRunnerAsync(HttpClient httpClient, FunctionSettings functionSettings, ConcurrentQueue <TestConfiguration> queue) { TestConfiguration nextTestConfiguration = null; while (!queue.IsEmpty) { if (queue.TryDequeue(out nextTestConfiguration)) { HttpContent requestContent = CreateHttpPostContent(nextTestConfiguration.CallSid, nextTestConfiguration.Transcript); HttpResponseMessage httpResponse = await httpClient.PostAsync(functionSettings.ExtractInfoUrl, requestContent); string responseContent = await httpResponse.Content.ReadAsStringAsync(); ExtractInfoResponse response = JsonConvert.DeserializeObject <ExtractInfoResponse>(responseContent); Assert.AreEqual(nextTestConfiguration.CallSid, response.CallSid); Assert.IsNotNull(response.Data); _log.LogInformation("Writing extracted data to test configuration..."); nextTestConfiguration.Data = response.Data; } TH.Thread.Sleep(2000); } }
public void DeleteAccountRecordingsHttpTriggerRun() { FunctionSettings functionSettings = FunctionSettings.Load(@".\functionSettings.json"); using (HttpClient httpClient = new HttpClient()) { string accessToken = AzureADHelper.GetAccessTokenAsync(functionSettings.Authority, functionSettings.ApplicationId, functionSettings.ClientSecret, functionSettings.ResourceId).Result; if (accessToken == null) { throw new Exception("Could not obtain access token!"); } httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken); DeleteRecordingsRunner(httpClient, functionSettings); } }
/// <summary> /// Runner for ensuring calls to DeleteRecordingsHttpTrigger for a deployed Azure Function runs correctly. /// </summary> /// <param name="httpClient">The HttpClient instance to use.</param> /// <param name="functionSettings">Configuration information required to make calls to the deployed Azure Function.</param> public void DeleteRecordingsRunner(HttpClient httpClient, FunctionSettings functionSettings) { HttpContent requestContent = CreateHttpPostContent("Yes"); HttpResponseMessage httpResponse = httpClient.PostAsync(functionSettings.DeleteAccountRecordingsUrl, requestContent).Result; string responseContent = httpResponse.Content.ReadAsStringAsync().Result; DeleteAccountRecordingsResponse response = JsonConvert.DeserializeObject <DeleteAccountRecordingsResponse>(responseContent); Assert.IsTrue(response.AreAllRecordingsDeleted); Assert.AreEqual((int)CommonStatusCode.Ok, response.StatusCode); Assert.AreEqual(Enum.GetName(typeof(CommonStatusCode), CommonStatusCode.Ok), response.StatusDesc); Assert.IsFalse(response.HasError); Assert.AreEqual((int)CommonErrorCode.NoError, response.ErrorCode); Assert.IsNull(response.ErrorDetails); }
/// <summary> /// Runner to ensure PullRecordingHttpTrigger runs correctly for concurrent executions against a remote Azure Function. /// </summary> /// <param name="httpClient">The HttpClient instance to use.</param> /// <param name="functionSettings">Configuration information required to make calls to the Azure Function.</param> /// <param name="queue">The queue of tests to run.</param> /// <returns>An asynchronous task.</returns> public async Task PullRecordingRunnerAsync(HttpClient httpClient, FunctionSettings functionSettings, ConcurrentQueue <TestConfiguration> queue) { TestConfiguration nextTestConfiguration = null; while (!queue.IsEmpty) { if (queue.TryDequeue(out nextTestConfiguration)) { HttpContent requestContent = CreateHttpPostContent(nextTestConfiguration.InputId, nextTestConfiguration.CallSid); HttpResponseMessage httpResponse = await httpClient.PostAsync(functionSettings.PullRecordingUrl, requestContent); string responseContent = await httpResponse.Content.ReadAsStringAsync(); PullRecordingResponse response = JsonConvert.DeserializeObject <PullRecordingResponse>(responseContent); Assert.AreEqual(nextTestConfiguration.CallSid, response.CallSid); Assert.IsNotNull(response.RecordingUri); // Assert.IsTrue(response.RecordingLength > 600000); // Recording size should be ~800KB Assert.IsNotNull(response.FullRecordingUrl); Assert.AreEqual((int)CommonStatusCode.Ok, response.StatusCode); Assert.AreEqual(Enum.GetName(typeof(CommonStatusCode), CommonStatusCode.Ok), response.StatusDesc); Assert.IsFalse(response.HasError); Assert.AreEqual((int)CommonErrorCode.NoError, response.ErrorCode); Assert.IsNull(response.ErrorDetails); _log.LogInformation("Writing returned recording uri to test configuration..."); nextTestConfiguration.RecordingUri = response.RecordingUri; } TH.Thread.Sleep(2000); } }