Skip to content

Commit d758f12

Browse files
Fix Couchbase flaky tests (#6892)
## Summary of changes The CouchBase and CouchBase3 tests are failing rarely in the CI due to authentication errors. All of them seem to be due to Authorization issues, not related to our instrumentation. That's why it has been decided to skip these results when the flakiness occurs. In the case of the CouchBase tests, we are getting these stacktraces depending on the package version: ``` Unhandled exception. System.AggregateException: Could not bootstrap - check inner exceptions for details. (One or more errors occurred. (Authentication failed for bucket 'default')) (Cannot deserialize the current JSON array (e.g. [1,2,3]) into type 'Couchbase.Configuration.Server.Serialization.Settings' because the type requires a JSON object (e.g. {"name":"value"}) to deserialize correctly. To fix this error either change the JSON to a JSON object (e.g. {"name":"value"}) or change the deserialized type to an array or a type that implements a collection interface (e.g. ICollection, IList) like List<T> that can be deserialized from a JSON array. JsonArrayAttribute can also be added to the type to force it to deserialize from a JSON array. Path 'settings', line 1, position 88.) ``` or ``` Unhandled exception. Couchbase.Configuration.Server.Serialization.BootstrapException: Could not bootstrap - check inner exceptions for details. (Authentication failed for bucket 'default') (Could not bootstrap with CCCP. (Authentication failed for bucket 'default')) (Cannot deserialize the current JSON array (e.g. [1,2,3]) into type 'Couchbase.Configuration.Server.Serialization.Settings' because the type requires a JSON object (e.g. {"name":"value"}) to deserialize correctly. To fix this error either change the JSON to a JSON object (e.g. {"name":"value"}) or change the deserialized type to an array or a type that implements a collection interface (e.g. ICollection, IList) like List<T> that can be deserialized from a JSON array. JsonArrayAttribute can also be added to the type to force it to deserialize from a JSON array. Path 'settings', line 1, position 88.) ``` Couchbase.Configuration.Server.Serialization.BootstrapException inherits from System.AggregateException. In the case of Couuchbase3, we are getting this exception: ``` Unhandled exception. Couchbase.AuthenticationFailureException: Cannot authenticate the user. Reason: AuthenticationError at Couchbase.Core.IO.Authentication.SaslMechanismBase.SendAsync[T](IOperation`1 op, IConnection connection, CancellationToken cancellationToken) at Couchbase.Core.IO.Authentication.SaslMechanismBase.SaslStep(IConnection connection, String message, IRequestSpan span, CancellationToken token) at Couchbase.Core.IO.Authentication.ScramShaMechanism.AuthenticateAsync(IConnection connection, CancellationToken cancellationToken) at Couchbase.Core.ClusterNode.Couchbase.Core.IO.Connections.IConnectionInitializer.InitializeConnectionAsync(IConnection connection, CancellationToken cancellationToken) at Couchbase.Core.IO.Connections.ConnectionPoolBase.CreateConnectionAsync(CancellationToken cancellationToken) ``` By returning a 13 return code, we communicate the test framework that the text can be skipped. This code is processed in \tracer\test\Datadog.Trace.TestHelpers.AutoInstrumentation\ErrorHelpers.cs ## Reason for change ## Implementation details ## Test coverage ## Other details <!-- Fixes #{issue} --> <!-- ⚠️ Note: where possible, please obtain 2 approvals prior to merging. Unless CODEOWNERS specifies otherwise, for external teams it is typically best to have one review from a team member, and one review from apm-dotnet. Trivial changes do not require 2 reviews. -->
1 parent 7f2a30e commit d758f12

File tree

2 files changed

+39
-4
lines changed

2 files changed

+39
-4
lines changed

tracer/test/test-applications/integrations/Samples.Couchbase/Program.cs

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Security.Authentication;
34
using System.Threading.Tasks;
45
using Couchbase;
56
using Couchbase.Configuration.Client;
7+
using Couchbase.Configuration.Server.Serialization;
68
using Couchbase.Core;
79
using Couchbase.IO;
810

@@ -13,10 +15,29 @@ internal class Program
1315
ICluster _cluster;
1416
IBucket _bucket;
1517

16-
private static async Task Main()
18+
private static async Task<int> Main()
1719
{
1820
Program p = new Program();
19-
await p.RunAllExamples();
21+
22+
try
23+
{
24+
await p.RunAllExamples();
25+
}
26+
catch (AggregateException ex)
27+
{
28+
Console.WriteLine("Exception during execution " + ex);
29+
30+
foreach (var exception in ex.InnerExceptions)
31+
{
32+
if (exception is AuthenticationException)
33+
{
34+
Console.WriteLine("Exiting with skip code (13)");
35+
return 13;
36+
}
37+
}
38+
}
39+
40+
return 0;
2041
}
2142

2243
private async Task RunAllExamples()

tracer/test/test-applications/integrations/Samples.Couchbase3/Program.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,26 @@ namespace Samples.Couchbase3
88
{
99
internal class Program
1010
{
11-
private static async Task Main()
11+
private static async Task<int> Main()
1212
{
1313
var options = new ClusterOptions()
1414
.WithConnectionString("couchbase://" + Host())
1515
.WithCredentials(username: "default", password: "password")
1616
.WithBuckets("default");
1717

18-
var cluster = await Cluster.ConnectAsync(options);
18+
19+
ICluster cluster = null;
20+
21+
try
22+
{
23+
cluster = await Cluster.ConnectAsync(options);
24+
}
25+
catch(AuthenticationFailureException ex)
26+
{
27+
Console.WriteLine("Exception during execution " + ex);
28+
Console.WriteLine("Exiting with skip code (13)");
29+
return 13;
30+
}
1931

2032
// get a bucket reference
2133
var bucket = await cluster.BucketAsync("default");
@@ -54,6 +66,8 @@ private static async Task Main()
5466
{
5567
Console.WriteLine("Expected error removing non-existent key: " + ex);
5668
}
69+
70+
return 0;
5771
}
5872

5973
private static string Host()

0 commit comments

Comments
 (0)