public static GetFunctionLogsAsync ( string functionName, bool throwOnNoLogs = true ) : Task |
||
functionName | string | |
throwOnNoLogs | bool | |
Résultat | Task |
public async Task ManualTrigger_Invoke_SucceedsTest() { TestHelpers.ClearFunctionLogs("ManualTrigger"); string testData = Guid.NewGuid().ToString(); string inputName = "input"; if (Fixture.FixtureId == "powershell") { inputName = "triggerInput"; } Dictionary <string, object> arguments = new Dictionary <string, object> { { inputName, testData } }; await Fixture.Host.CallAsync("ManualTrigger", arguments); // make sure the input string made it all the way through var logs = await TestHelpers.GetFunctionLogsAsync("ManualTrigger"); Assert.True(logs.Any(p => p.Contains(testData))); }
protected async Task TableInputTest() { TestHelpers.ClearFunctionLogs("TableIn"); var args = new Dictionary <string, object>() { { "input", "{ \"Region\": \"West\" }" } }; await Fixture.Host.CallAsync("TableIn", args); var logs = await TestHelpers.GetFunctionLogsAsync("TableIn"); string result = logs.Where(p => p.Contains("Result:")).Single(); result = result.Substring(result.IndexOf('{')); // verify singleton binding JObject resultObject = JObject.Parse(result); JObject single = (JObject)resultObject["single"]; Assert.Equal("AAA", (string)single["PartitionKey"]); Assert.Equal("001", (string)single["RowKey"]); // verify partition binding JArray partition = (JArray)resultObject["partition"]; Assert.Equal(3, partition.Count); foreach (var entity in partition) { Assert.Equal("BBB", (string)entity["PartitionKey"]); } // verify query binding JArray query = (JArray)resultObject["query"]; Assert.Equal(2, query.Count); Assert.Equal("003", (string)query[0]["RowKey"]); Assert.Equal("004", (string)query[1]["RowKey"]); }
public async Task Scenario_DoneCalledMultipleTimes_ErrorIsLogged() { TestHelpers.ClearFunctionLogs("Scenarios"); Dictionary <string, object> arguments = new Dictionary <string, object> { { "input", "doubleDone" } }; await Fixture.Host.CallAsync("Scenarios", arguments); var logs = await TestHelpers.GetFunctionLogsAsync("Scenarios"); Assert.Equal(4, logs.Count); Assert.True(logs.Any(p => p.Contains("Function started"))); Assert.True(logs.Any(p => p.Contains("Running scenario 'doubleDone'"))); // verify an error was written Assert.True(logs.Any(p => p.Contains("Error: 'done' has already been called. Please check your script for extraneous calls to 'done'."))); // verify the function completed successfully Assert.True(logs.Any(p => p.Contains("Function completed (Success"))); }
public async Task HttpTriggerWithError_Get() { string functionName = "HttpTrigger-PowerShellWithError"; TestHelpers.ClearFunctionLogs(functionName); HttpRequestMessage request = new HttpRequestMessage { RequestUri = new Uri( "http://localhost/api/httptrigger-powershellwitherror?code=1388a6b0d05eca2237f10e4a4641260b0a08f3a5&name=testuser"), Method = HttpMethod.Get }; Dictionary <string, object> arguments = new Dictionary <string, object> { { "req", request } }; string innerException = "PowerShell script error"; string errorRecordMessage = "Test Error in Get-DateToday"; Exception ex = await Assert.ThrowsAsync <FunctionInvocationException>(async() => await Fixture.Host.CallAsync(functionName, arguments)); var runtimeException = (RuntimeException)ex.InnerException; Assert.Equal(innerException, runtimeException.Message); Assert.Equal(errorRecordMessage, runtimeException.InnerException.Message); var logs = await TestHelpers.GetFunctionLogsAsync(functionName); Assert.True(logs.Any(p => p.Contains("Function started"))); // verify an error was written Assert.True(logs.Any(p => p.Contains(errorRecordMessage))); // verify the function completed successfully Assert.True(logs.Any(p => p.Contains("Function completed (Failure"))); }
public async Task FileLogging_SucceedsTest() { string functionName = "Scenarios"; TestHelpers.ClearFunctionLogs(functionName); string guid1 = Guid.NewGuid().ToString(); string guid2 = Guid.NewGuid().ToString(); ScenarioInput input = new ScenarioInput { Scenario = "fileLogging", Container = "scenarios-output", Value = $"{guid1};{guid2}" }; Dictionary <string, object> arguments = new Dictionary <string, object> { { "input", JsonConvert.SerializeObject(input) } }; await Fixture.Host.CallAsync(functionName, arguments); // wait for logs to flush await Task.Delay(FileTraceWriter.LogFlushIntervalMs); IList <string> logs = null; await TestHelpers.Await(() => { logs = TestHelpers.GetFunctionLogsAsync(functionName, throwOnNoLogs: false).Result; return(logs.Count > 0); }); Assert.True(logs.Count == 4, string.Join(Environment.NewLine, logs)); // No need for assert; this will throw if there's not one and only one logs.Single(p => p.EndsWith($"From TraceWriter: {guid1}")); logs.Single(p => p.EndsWith($"From ILogger: {guid2}")); }
public async Task QueueTriggerPython_Succeeds() { TestHelpers.ClearFunctionLogs("QueueTrigger-Python"); // write the input message CloudQueue inputQueue = _fixture.QueueClient.GetQueueReference("samples-python"); inputQueue.CreateIfNotExists(); string id = Guid.NewGuid().ToString(); JObject jsonObject = new JObject { { "id", id } }; var message = new CloudQueueMessage(jsonObject.ToString(Formatting.None)); await inputQueue.AddMessageAsync(message); // wait for function to execute and produce its result blob CloudBlobContainer outputContainer = _fixture.BlobClient.GetContainerReference("samples-output"); CloudBlockBlob outputBlob = outputContainer.GetBlockBlobReference(id); string result = await TestHelpers.WaitForBlobAndGetStringAsync(outputBlob); jsonObject = JObject.Parse(result); Assert.Equal(id, (string)jsonObject["id"]); // verify the function output var logs = await TestHelpers.GetFunctionLogsAsync("QueueTrigger-Python"); int idx = logs.IndexOf("Read 5 Table entities"); for (int i = idx + 1; i < 5; i++) { string json = logs[i]; JObject entity = JObject.Parse(json); Assert.Equal("samples-python", entity["PartitionKey"]); Assert.Equal(0, (int)entity["Status"]); } }
public async Task ExecutionContext_IsProvided() { TestHelpers.ClearFunctionLogs("Scenarios"); JObject input = new JObject { { "scenario", "functionExecutionContext" } }; Task t = Fixture.Host.CallAsync("Scenarios", new Dictionary <string, object>() { { "input", input.ToString() } }); Task result = await Task.WhenAny(t, Task.Delay(5000)); var logs = await TestHelpers.GetFunctionLogsAsync("Scenarios"); Assert.Same(t, result); Assert.True(logs.Any(l => l.Contains("FunctionName:Scenarios"))); Assert.True(logs.Any(l => l.Contains($"FunctionDirectory:{Path.Combine(Fixture.Host.ScriptConfig.RootScriptPath, "Scenarios")}"))); }
public async Task TimerTrigger() { var logs = (await TestHelpers.GetFunctionLogsAsync("TimerTrigger")).ToArray(); Assert.True(logs[1].Contains("Timer function ran!")); }
protected async Task TableInputTest() { TestHelpers.ClearFunctionLogs("TableIn"); var input = new JObject { { "Region", "West" }, { "Status", 1 } }; var args = new Dictionary <string, object>() { { "input", input.ToString() } }; await Fixture.Host.CallAsync("TableIn", args); var logs = await TestHelpers.GetFunctionLogsAsync("TableIn"); string result = logs.Where(p => p.Contains("Result:")).Single(); result = result.Substring(result.IndexOf('{')); // verify singleton binding JObject resultObject = JObject.Parse(result); JObject single = (JObject)resultObject["single"]; Assert.Equal("AAA", (string)single["PartitionKey"]); Assert.Equal("001", (string)single["RowKey"]); // verify partition binding JArray partition = (JArray)resultObject["partition"]; Assert.Equal(3, partition.Count); foreach (var entity in partition) { Assert.Equal("BBB", (string)entity["PartitionKey"]); } // verify query binding JArray query = (JArray)resultObject["query"]; Assert.Equal(2, query.Count); Assert.Equal("003", (string)query[0]["RowKey"]); Assert.Equal("004", (string)query[1]["RowKey"]); // verify input validation input = new JObject { { "Region", "West" }, { "Status", "1 or Status neq 1" } }; args = new Dictionary <string, object>() { { "input", input.ToString() } }; var exception = await Assert.ThrowsAsync <FunctionInvocationException>(async() => { await Fixture.Host.CallAsync("TableIn", args); }); Assert.Equal("An invalid parameter value was specified for filter parameter 'Status'.", exception.InnerException.Message); }
public async Task TimerTrigger() { var logs = await TestHelpers.GetFunctionLogsAsync("TimerTrigger"); Assert.Contains(logs, log => log.Contains("Timer function ran!")); }