1
1
// Licensed to Elasticsearch B.V under one or more agreements.
2
2
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
3
3
// See the LICENSE file in the project root for more information
4
+
4
5
using System ;
5
6
using System . Linq ;
6
7
using Elastic . Clients . Elasticsearch ;
9
10
using Elastic . Transport ;
10
11
using Xunit ;
11
12
using Xunit . Abstractions ;
13
+ using static Elastic . Elasticsearch . Managed . DetectedProxySoftware ;
12
14
13
15
[ assembly: TestFramework ( "Elastic.Elasticsearch.Xunit.Sdk.ElasticTestFramework" , "Elastic.Elasticsearch.Xunit" ) ]
14
16
@@ -18,29 +20,47 @@ namespace Elastic.Ingest.Elasticsearch.IntegrationTests;
18
20
public class IngestionCluster : XunitClusterBase
19
21
{
20
22
protected static string Version = "8.7.0" ;
23
+
21
24
public IngestionCluster ( ) : this ( new XunitClusterConfiguration ( Version ) { StartingPortNumber = 9202 } ) { }
25
+
22
26
public IngestionCluster ( XunitClusterConfiguration xunitClusterConfiguration ) : base ( xunitClusterConfiguration ) { }
23
27
24
28
public ElasticsearchClient CreateClient ( ITestOutputHelper output ) =>
25
- this . GetOrAddClient ( _ =>
29
+ this . GetOrAddClient ( cluster =>
26
30
{
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 ( ) ;
31
33
var connectionPool = new StaticNodePool ( nodes ) ;
32
34
var settings = new ElasticsearchClientSettings ( connectionPool )
33
- . Proxy ( new Uri ( "http://ipv4.fiddler:8080" ) , null ! , null ! )
34
35
. RequestTimeout ( TimeSpan . FromSeconds ( 5 ) )
36
+ . ServerCertificateValidationCallback ( CertificateValidations . AllowAll )
35
37
. OnRequestCompleted ( d =>
36
38
{
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
+ }
38
50
catch
39
51
{
40
52
// ignored
41
53
}
42
54
} )
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
+
44
64
return new ElasticsearchClient ( settings ) ;
45
65
} ) ;
46
66
}
@@ -49,8 +69,6 @@ public class SecurityCluster : IngestionCluster
49
69
{
50
70
public SecurityCluster ( ) : base ( new XunitClusterConfiguration ( Version , ClusterFeatures . Security )
51
71
{
52
- StartingPortNumber = 9202 , TrialMode = XPackTrialMode . Trial
53
- ,
54
-
72
+ StartingPortNumber = 9202 , TrialMode = XPackTrialMode . Trial ,
55
73
} ) { }
56
74
}
0 commit comments