Skip to content

Commit 18a16a2

Browse files
enable test TriggerWithException (#801)
* enable the TriggerWithException test * update comment * remove logger delegate * fix error * add retry * remove Java test and try --------- Co-authored-by: Charles Gagnon <chgagnon@microsoft.com>
1 parent 552a0ed commit 18a16a2

File tree

3 files changed

+38
-4
lines changed

3 files changed

+38
-4
lines changed

test-outofproc/TriggerWithException.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public static void Run(
3232
throw new InvalidOperationException(ExceptionMessage);
3333
}
3434
logger.LogInformation("SQL Changes: " + Utils.JsonSerializeObject(changes));
35+
3536
}
3637
}
3738
}

test/Integration/SqlTriggerBindingIntegrationTests.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -578,11 +578,13 @@ public void UnsupportedDatabaseThrows(SupportedLanguages lang)
578578
/// <summary>
579579
/// Tests that when a user function throws an exception we'll retry executing that function once the lease timeout expires
580580
/// </summary>
581-
[Fact]
582-
public async Task FunctionExceptionsCauseRetry()
581+
[RetryTheory]
582+
[SqlInlineData()]
583+
[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.
584+
public async Task FunctionExceptionsCauseRetry(SupportedLanguages lang)
583585
{
584586
this.SetChangeTrackingForTable("Products");
585-
this.StartFunctionHost(nameof(TriggerWithException), SupportedLanguages.CSharp, true);
587+
this.StartFunctionHost(nameof(TriggerWithException), lang, useTestFolder: true);
586588
TaskCompletionSource taskCompletionSource = new();
587589
void TestExceptionMessageSeen(object sender, DataReceivedEventArgs e)
588590
{
@@ -605,7 +607,7 @@ void TestExceptionMessageSeen(object sender, DataReceivedEventArgs e)
605607
(SqlTableChangeMonitor<object>.LeaseIntervalInSeconds * 1000) + batchProcessingTimeout);
606608

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/**
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for
4+
* license information.
5+
*/
6+
7+
package com.function;
8+
9+
import com.microsoft.azure.functions.ExecutionContext;
10+
import com.microsoft.azure.functions.annotation.FunctionName;
11+
import com.microsoft.azure.functions.sql.annotation.SQLTrigger;
12+
import com.function.Common.SqlChangeProduct;
13+
import com.google.gson.Gson;
14+
import java.util.logging.Level;
15+
16+
public class TriggerWithException {
17+
public final String ExceptionMessage = "TriggerWithException test exception";
18+
private static Boolean threwException = false;
19+
20+
@FunctionName("TriggerWithException")
21+
public void run(
22+
@SQLTrigger(name = "changes", tableName = "[dbo].[Products]", connectionStringSetting = "SqlConnectionString") SqlChangeProduct[] changes,
23+
ExecutionContext context) throws Exception {
24+
25+
if (!threwException) {
26+
threwException = true;
27+
throw new Exception(ExceptionMessage);
28+
}
29+
context.getLogger().log(Level.INFO, "SQL Changes: " + new Gson().toJson(changes));
30+
}
31+
}

0 commit comments

Comments
 (0)