11// Licensed to Elasticsearch B.V under one or more agreements.
22// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
33// See the LICENSE file in the project root for more information
4+
45using System ;
56using System . Linq ;
67using Elastic . Clients . Elasticsearch ;
910using Elastic . Transport ;
1011using Xunit ;
1112using Xunit . Abstractions ;
13+ using static Elastic . Elasticsearch . Managed . DetectedProxySoftware ;
1214
1315[ assembly: TestFramework ( "Elastic.Elasticsearch.Xunit.Sdk.ElasticTestFramework" , "Elastic.Elasticsearch.Xunit" ) ]
1416
@@ -18,29 +20,47 @@ namespace Elastic.Ingest.Elasticsearch.IntegrationTests;
1820public class IngestionCluster : XunitClusterBase
1921{
2022 protected static string Version = "8.7.0" ;
23+
2124 public IngestionCluster ( ) : this ( new XunitClusterConfiguration ( Version ) { StartingPortNumber = 9202 } ) { }
25+
2226 public IngestionCluster ( XunitClusterConfiguration xunitClusterConfiguration ) : base ( xunitClusterConfiguration ) { }
2327
2428 public ElasticsearchClient CreateClient ( ITestOutputHelper output ) =>
25- this . GetOrAddClient ( _ =>
29+ this . GetOrAddClient ( cluster =>
2630 {
27- var hostName = ( System . Diagnostics . Process . GetProcessesByName ( "mitmproxy" ) . Any ( )
28- ? "ipv4.fiddler"
29- : "localhost" ) ;
30- var nodes = NodesUris ( hostName ) ;
31+ var isCi = ! string . IsNullOrEmpty ( Environment . GetEnvironmentVariable ( "CI" ) ) ;
32+ var nodes = NodesUris ( ) ;
3133 var connectionPool = new StaticNodePool ( nodes ) ;
3234 var settings = new ElasticsearchClientSettings ( connectionPool )
33- . Proxy ( new Uri ( "http://ipv4.fiddler:8080" ) , null ! , null ! )
3435 . RequestTimeout ( TimeSpan . FromSeconds ( 5 ) )
36+ . ServerCertificateValidationCallback ( CertificateValidations . AllowAll )
3537 . OnRequestCompleted ( d =>
3638 {
37- try { output . WriteLine ( d . DebugInformation ) ; }
39+ // ON CI only logged failed requests
40+ // Locally we just log everything for ease of development
41+ try
42+ {
43+ if ( isCi )
44+ {
45+ if ( ! d . HasSuccessfulStatusCode )
46+ output . WriteLine ( d . DebugInformation ) ;
47+ }
48+ else output . WriteLine ( d . DebugInformation ) ;
49+ }
3850 catch
3951 {
4052 // ignored
4153 }
4254 } )
43- . EnableDebugMode ( ) ;
55+ . EnableDebugMode ( )
56+ //do not request server stack traces on CI, too noisy
57+ . IncludeServerStackTraceOnError ( ! isCi ) ;
58+ if ( cluster . DetectedProxy != None )
59+ {
60+ var proxyUrl = cluster . DetectedProxy == Fiddler ? "ipv4.fiddler" : "localhost" ;
61+ settings = settings . Proxy ( new Uri ( $ "http://{ proxyUrl } :8080") , null ! , null ! ) ;
62+ }
63+
4464 return new ElasticsearchClient ( settings ) ;
4565 } ) ;
4666}
@@ -49,8 +69,6 @@ public class SecurityCluster : IngestionCluster
4969{
5070 public SecurityCluster ( ) : base ( new XunitClusterConfiguration ( Version , ClusterFeatures . Security )
5171 {
52- StartingPortNumber = 9202 , TrialMode = XPackTrialMode . Trial
53- ,
54-
72+ StartingPortNumber = 9202 , TrialMode = XPackTrialMode . Trial ,
5573 } ) { }
5674}
0 commit comments