Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cosmos DB RC #801

Merged
merged 5 commits into from
Oct 5, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,8 @@ private async Task ProcessChangesAsync(ChangeFeedProcessorContext context, IRead
{
this._healthMonitor.OnChangesDelivered(context);
FunctionResult result = await this._executor.TryExecuteAsync(new TriggeredFunctionData() { TriggerValue = docs }, cancellationToken);
if (!result.Succeeded
if (result != null // TryExecuteAsync when using RetryPolicies can return null
&& !result.Succeeded
&& result.Exception != null)
{
ChangeFeedProcessorUserException userException = new ChangeFeedProcessorUserException(result.Exception, context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</PropertyGroup>
<Import Project="..\..\build\common.props" />
<PropertyGroup>
<Version>$(CosmosDBVersion)</Version>
<Version>$(CosmosDBVersion)-rc</Version>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
Expand All @@ -19,7 +19,7 @@
<WarningsAsErrors />
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Azure.Cosmos" Version="3.25.0" />
<PackageReference Include="Microsoft.Azure.Cosmos" Version="3.31.0" />
<PackageReference Include="Microsoft.Azure.WebJobs" Version="3.0.32" />
<PackageReference Include="Microsoft.CSharp" Version="4.5.0" />
<PackageReference Include="Microsoft.Extensions.Azure" Version="1.1.0" />
Expand Down
64 changes: 10 additions & 54 deletions test/WebJobs.Extensions.CosmosDB.Tests/CosmosDBEndToEndTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,11 @@ public async Task CosmosDBEndToEnd()

await TestHelpers.Await(() =>
{
return _loggerProvider.GetAllLogMessages().Count(p => p.FormattedMessage != null && p.FormattedMessage.Contains("Trigger called!")) == 4
&& _loggerProvider.GetAllLogMessages().Count(p => p.FormattedMessage != null && p.FormattedMessage.Contains("Trigger with string called!")) == 4;
var logMessages = _loggerProvider.GetAllLogMessages();
return logMessages.Count(p => p.FormattedMessage != null && p.FormattedMessage.Contains("Trigger called!")) == 4
&& logMessages.Count(p => p.FormattedMessage != null && p.FormattedMessage.Contains("Trigger with string called!")) == 4
&& logMessages.Count(p => p.FormattedMessage != null && p.FormattedMessage.Contains("Trigger with retry called!")) == 8
&& logMessages.Count(p => p.Exception != null && p.Exception.InnerException.Message.Contains("Test exception") && !p.Category.StartsWith("Host.Results")) > 0;
});

// Make sure the Options were logged. Just check a few values.
Expand All @@ -72,38 +75,6 @@ await TestHelpers.Await(() =>
}
}

[Fact]
public async Task CosmosDBEndToEnd_WithRetry()
{
using (var host = await StartHostAsync(typeof(EndToEndTestClass_Retry)))
{
var client = await InitializeDocumentClientAsync(host.Services.GetRequiredService<IConfiguration>());

// Call the outputs function directly, which will write out 3 documents
// using with the 'input' property set to the value we provide.
var input = Guid.NewGuid().ToString();
var parameter = new Dictionary<string, object>();
parameter["input"] = input;

await host.GetJobHost().CallAsync(nameof(EndToEndTestClass_Retry.Outputs), parameter);

await TestHelpers.Await(() =>
{
var logMessages = _loggerProvider.GetAllLogMessages();
foreach (LogMessage logMsg in logMessages)
{
if (logMsg.Exception != null)
{
Console.WriteLine(logMsg.Exception.InnerException.Message);
}
}

return logMessages.Count(p => p.FormattedMessage != null && p.FormattedMessage.Contains("Trigger called!")) == 6
&& logMessages.Count(p => p.Exception != null && p.Exception.InnerException.Message.Contains("Test exception") && !p.Category.StartsWith("Host.Results")) == 1;
});
}
}

private async Task<CosmosClient> InitializeDocumentClientAsync(IConfiguration configuration)
{
var client = new CosmosClient(configuration.GetConnectionStringOrSetting(Constants.DefaultConnectionStringName).Value);
Expand Down Expand Up @@ -161,6 +132,8 @@ public class QueueItem

private static class EndToEndTestClass
{
private static bool shouldThrow = true;

[NoAutomaticTrigger]
public static async Task Outputs(
string input,
Expand Down Expand Up @@ -203,32 +176,15 @@ public static void TriggerWithString(
log.LogInformation("Trigger with string called!");
}
}
}

private static class EndToEndTestClass_Retry
{
private static bool shouldThrow = true;

[NoAutomaticTrigger]
public static async Task Outputs(
string input,
[CosmosDB(DatabaseName, CollectionName, CreateIfNotExists = true)] IAsyncCollector<object> collector,
ILogger log)
{
for (int i = 0; i < 3; i++)
{
await collector.AddAsync(new { input = input, id = Guid.NewGuid().ToString() });
}
}

[FixedDelayRetry(5, "00:00:01")]
public static void Trigger(
[CosmosDBTrigger(DatabaseName, CollectionName, CreateLeaseContainerIfNotExists = true)] IReadOnlyList<Item> documents,
public static void TriggerWithRetry(
[CosmosDBTrigger(DatabaseName, CollectionName, CreateLeaseContainerIfNotExists = true, LeaseContainerPrefix = "retry")] IReadOnlyList<Item> documents,
ILogger log)
{
foreach (var document in documents)
{
log.LogInformation($"Trigger called!");
log.LogInformation($"Trigger with retry called!");
}

if (shouldThrow)
Expand Down