Skip to content

Commit d8c473f

Browse files
NaluTripicianCopilotkirankumarkolli
authored
[FaultInjection] FaultInjection: Adds XML documentation, stylecop.json, and updates test packages (#5677)
## Summary This PR adds missing XML documentation, the stylecop.json configuration file, and updates test framework packages. ### Changes **1. Add XML documentation to undocumented public members (#5661)** - `FaultInjector` class-level summary - `FaultInjector.GetFaultInjectionClientOptions()` - `FaultInjector.GetApplicationContext()` - `FaultInjectionServerErrorResultBuilder.WithSuppressServiceRequest()` - `FaultInjectionServerErrorResultBuilder.WithInjectionRate()` - `FaultInjectionApplicationContext` class-level summary - `FaultInjectionApplicationContext.GetAllRuleExecutionsByRuleId()` - `FaultInjectionApplicationContext.GetAllRuleExecutionsByActivityId()` - `FaultInjectionApplicationContext.TryGetRuleExecutionsByRuleId()` **2. Add missing `stylecop.json` (#5662)** - Created `stylecop.json` in `FaultInjection/src/` matching the main SDK's configuration. - The csproj already referenced this file via `<AdditionalFiles>` but it didn't exist. **3. Update test framework packages (#5668)** - `Microsoft.NET.Test.Sdk`: 17.1.0 → 17.12.0 - `MSTest.TestAdapter`: 2.2.8 → 3.7.3 - `MSTest.TestFramework`: 2.2.8 → 3.7.3 - `coverlet.collector`: 3.1.2 → 6.0.4 ### Testing - Build verified locally with `dotnet build` Parent tracking issue: #5652 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: Kiran Kumar Kolli <kirankk@microsoft.com>
1 parent 7952123 commit d8c473f

5 files changed

Lines changed: 66 additions & 5 deletions

File tree

Microsoft.Azure.Cosmos/FaultInjection/src/FaultInjectionServerErrorResultBuilder.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,23 @@ public FaultInjectionServerErrorResultBuilder WithDelay(TimeSpan delay)
6262
return this;
6363
}
6464

65+
/// <summary>
66+
/// Sets whether to suppress the service request when the fault is injected.
67+
/// </summary>
68+
/// <param name="suppressServiceRequest">If true, the service request will be suppressed.</param>
69+
/// <returns>The current <see cref="FaultInjectionServerErrorResultBuilder"/>.</returns>
6570
public FaultInjectionServerErrorResultBuilder WithSuppressServiceRequest(bool suppressServiceRequest)
6671
{
6772
this.suppressServiceRequest = suppressServiceRequest;
6873
return this;
6974
}
7075

76+
/// <summary>
77+
/// Sets the injection rate, which determines the probability that the fault will be injected.
78+
/// Must be a value in the range (0, 1]. Default is 1 (100%).
79+
/// </summary>
80+
/// <param name="injectionRate">The injection rate, in the range (0, 1].</param>
81+
/// <returns>The current <see cref="FaultInjectionServerErrorResultBuilder"/>.</returns>
7182
public FaultInjectionServerErrorResultBuilder WithInjectionRate(double injectionRate)
7283
{
7384
if (injectionRate <= 0 || injectionRate > 1)

Microsoft.Azure.Cosmos/FaultInjection/src/FaultInjector.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ namespace Microsoft.Azure.Cosmos.FaultInjection
77
using System.Collections.Generic;
88
using Microsoft.Azure.Documents.FaultInjection;
99

10+
/// <summary>
11+
/// Manages fault injection rules and provides access to fault injection client options and diagnostics.
12+
/// </summary>
1013
public class FaultInjector : IFaultInjector
1114
{
1215
private readonly ChaosInterceptorFactory chaosInterceptorFactory;
@@ -16,6 +19,11 @@ public FaultInjector(List<FaultInjectionRule> rules)
1619
this.chaosInterceptorFactory = new ChaosInterceptorFactory(rules);
1720
}
1821

22+
/// <summary>
23+
/// Configures the provided <see cref="CosmosClientOptions"/> with the fault injection interceptor.
24+
/// </summary>
25+
/// <param name="clientOptions">The <see cref="CosmosClientOptions"/> to configure.</param>
26+
/// <returns>The configured <see cref="CosmosClientOptions"/>.</returns>
1927
public CosmosClientOptions GetFaultInjectionClientOptions(CosmosClientOptions clientOptions)
2028
{
2129
clientOptions.ChaosInterceptorFactory = this.chaosInterceptorFactory;
@@ -33,7 +41,10 @@ public CosmosClientOptions GetFaultInjectionClientOptions(CosmosClientOptions cl
3341
return this.chaosInterceptorFactory.ChaosInterceptor?.GetFaultInjectionRuleId(activityId);
3442
}
3543

36-
//Get Application Context
44+
/// <summary>
45+
/// Gets the <see cref="FaultInjectionApplicationContext"/> containing rule execution tracking data.
46+
/// </summary>
47+
/// <returns>The <see cref="FaultInjectionApplicationContext"/>, or null if not yet initialized.</returns>
3748
public FaultInjectionApplicationContext? GetApplicationContext()
3849
{
3950
return this.chaosInterceptorFactory.ChaosInterceptor?.GetApplicationContext();

Microsoft.Azure.Cosmos/FaultInjection/src/implementation/FaultInjectionApplicationContext.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ namespace Microsoft.Azure.Cosmos.FaultInjection
66
using System;
77
using System.Collections.Concurrent;
88

9+
/// <summary>
10+
/// Provides tracking and observability for fault injection rule executions,
11+
/// including lookups by rule ID and activity ID.
12+
/// </summary>
913
public class FaultInjectionApplicationContext
1014
{
1115

@@ -44,16 +48,30 @@ internal void AddRuleExecution(string ruleId, Guid activityId)
4448
return this.values;
4549
}
4650

51+
/// <summary>
52+
/// Gets all rule executions indexed by rule ID.
53+
/// </summary>
54+
/// <returns>A <see cref="ConcurrentDictionary{TKey, TValue}"/> mapping rule IDs to their executions.</returns>
4755
public ConcurrentDictionary<string, List<(DateTime, Guid)>> GetAllRuleExecutionsByRuleId()
4856
{
4957
return this.executionsByRuleId;
5058
}
5159

60+
/// <summary>
61+
/// Gets all rule executions indexed by activity ID.
62+
/// </summary>
63+
/// <returns>A <see cref="ConcurrentDictionary{TKey, TValue}"/> mapping activity IDs to their executions.</returns>
5264
public ConcurrentDictionary<Guid, List<(DateTime, string)>> GetAllRuleExecutionsByActivityId()
5365
{
5466
return this.executionsByActivityId;
5567
}
5668

69+
/// <summary>
70+
/// Tries to get rule executions for the given rule ID.
71+
/// </summary>
72+
/// <param name="ruleId">The rule ID to look up.</param>
73+
/// <param name="execution">The list of executions for the rule, or an empty list if not found.</param>
74+
/// <returns>True if executions were found, false otherwise.</returns>
5775
public bool TryGetRuleExecutionsByRuleId(string ruleId, out List<(DateTime, Guid)> execution)
5876
{
5977
if (this.executionsByRuleId.TryGetValue(ruleId, out List<(DateTime, Guid)>? ruleExecutions))
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"$schema": "https://raw.githubusercontent.com/DotNetAnalyzers/StyleCopAnalyzers/master/StyleCop.Analyzers/StyleCop.Analyzers/Settings/stylecop.schema.json",
3+
"settings": {
4+
"documentationRules": {
5+
"companyName": "Microsoft",
6+
"documentInternalElements": false,
7+
"documentInterfaces": false,
8+
"xmlHeader": false,
9+
"copyrightText": "{decoration}\r\nCopyright (c) Microsoft Corporation. All rights reserved.\r\n{decoration}",
10+
"variables": {
11+
"decoration": "------------------------------------------------------------"
12+
}
13+
},
14+
"readabilityRules": {
15+
"allowBuiltInTypeAliases": false
16+
},
17+
"orderingRules": {
18+
"systemUsingDirectivesFirst": true
19+
}
20+
}
21+
}

Microsoft.Azure.Cosmos/FaultInjection/tests/FaultInjectionTests.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@
2222
</ItemGroup>
2323

2424
<ItemGroup>
25-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
26-
<PackageReference Include="MSTest.TestAdapter" Version="2.2.8" />
27-
<PackageReference Include="MSTest.TestFramework" Version="2.2.8" />
28-
<PackageReference Include="coverlet.collector" Version="3.1.2" />
25+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
26+
<PackageReference Include="MSTest.TestAdapter" Version="3.7.3" />
27+
<PackageReference Include="MSTest.TestFramework" Version="3.7.3" />
28+
<PackageReference Include="coverlet.collector" Version="6.0.4" />
2929
</ItemGroup>
3030

3131
<ItemGroup>

0 commit comments

Comments
 (0)