Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions test-outofproc/TriggerWithException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public static void Run(
throw new InvalidOperationException(ExceptionMessage);
}
logger.LogInformation("SQL Changes: " + Utils.JsonSerializeObject(changes));

}
}
}
10 changes: 6 additions & 4 deletions test/Integration/SqlTriggerBindingIntegrationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -578,11 +578,13 @@ public void UnsupportedDatabaseThrows(SupportedLanguages lang)
/// <summary>
/// Tests that when a user function throws an exception we'll retry executing that function once the lease timeout expires
/// </summary>
[Fact]
public async Task FunctionExceptionsCauseRetry()
[RetryTheory]
[SqlInlineData()]
[UnsupportedLanguages(SupportedLanguages.JavaScript, SupportedLanguages.Python, SupportedLanguages.PowerShell, SupportedLanguages.Csx, SupportedLanguages.Java)] // Keeping static state for threwException across calls is only valid for C# and Java.
public async Task FunctionExceptionsCauseRetry(SupportedLanguages lang)
{
this.SetChangeTrackingForTable("Products");
this.StartFunctionHost(nameof(TriggerWithException), SupportedLanguages.CSharp, true);
this.StartFunctionHost(nameof(TriggerWithException), lang, useTestFolder: true);
TaskCompletionSource taskCompletionSource = new();
void TestExceptionMessageSeen(object sender, DataReceivedEventArgs e)
{
Expand All @@ -605,7 +607,7 @@ void TestExceptionMessageSeen(object sender, DataReceivedEventArgs e)
(SqlTableChangeMonitor<object>.LeaseIntervalInSeconds * 1000) + batchProcessingTimeout);

// First wait for the exception message to show up
await taskCompletionSource.Task.TimeoutAfter(TimeSpan.FromMilliseconds(this.GetBatchProcessingTimeout(1, 30)), "Timed out waiting for exception message");
await taskCompletionSource.Task.TimeoutAfter(TimeSpan.FromMilliseconds(batchProcessingTimeout), "Timed out waiting for exception message");
// Now wait for the retry to occur and successfully pass
await changesTask;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for
* license information.
*/

package com.function;

import com.microsoft.azure.functions.ExecutionContext;
import com.microsoft.azure.functions.annotation.FunctionName;
import com.microsoft.azure.functions.sql.annotation.SQLTrigger;
import com.function.Common.SqlChangeProduct;
import com.google.gson.Gson;
import java.util.logging.Level;

public class TriggerWithException {
public final String ExceptionMessage = "TriggerWithException test exception";
private static Boolean threwException = false;

@FunctionName("TriggerWithException")
public void run(
@SQLTrigger(name = "changes", tableName = "[dbo].[Products]", connectionStringSetting = "SqlConnectionString") SqlChangeProduct[] changes,
ExecutionContext context) throws Exception {

if (!threwException) {
threwException = true;
throw new Exception(ExceptionMessage);
}
context.getLogger().log(Level.INFO, "SQL Changes: " + new Gson().toJson(changes));
}
}