Skip to content

Commit 80a7267

Browse files
committed
added SkipOnTeamCity attribute for cancel bulk all tests that suffer from timing issues on the build server
Conflicts: src/Tests/Framework/XUnitPlumbing/IntegrationTestDiscoverer.cs
1 parent 30be383 commit 80a7267

File tree

4 files changed

+33
-13
lines changed

4 files changed

+33
-13
lines changed

src/Tests/Document/Multiple/BulkAll/BulkAllApiTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public void ReturnsExpectedResponse()
7373
bulkObserver.TotalNumberOfRetries.Should().Be(0);
7474
}
7575

76-
[I]
76+
[I, SkipOnTeamCity("this test is extremely flakey on TC, but never fails localy")]
7777
public void DisposingObservableCancelsBulkAll()
7878
{
7979
var index = CreateIndexName();
@@ -116,7 +116,7 @@ public void DisposingObservableCancelsBulkAll()
116116
bulkObserver.TotalNumberOfRetries.Should().Be(0);
117117
}
118118

119-
[I]
119+
[I, SkipOnTeamCity("this test is extremely flakey on TC, but never fails localy")]
120120
public void CancelBulkAll()
121121
{
122122
var index = CreateIndexName();
Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections.Generic;
23
using System.Linq;
34
using System.Reflection;
45
using Xunit;
@@ -8,6 +9,8 @@ namespace Tests.Framework
89
{
910
public class IntegrationTestDiscoverer : NestTestDiscoverer
1011
{
12+
private bool RunningOnTeamCity { get; } = !string.IsNullOrEmpty(Environment.GetEnvironmentVariable("TEAMCITY_VERSION"));
13+
1114
public IntegrationTestDiscoverer(IMessageSink diagnosticMessageSink)
1215
: base(diagnosticMessageSink, TestClient.Configuration.RunIntegrationTests) { }
1316

@@ -19,9 +22,12 @@ protected override bool SkipMethod(ITestFrameworkDiscoveryOptions discoveryOptio
1922

2023
return SkipClassMarkedWithRequiresPluginFor2XSnapshotBuildTests(classOfMethod)
2124
|| TypeSkipVersionAttributeSatisfies(classOfMethod)
22-
|| MethodSkipVersionAttributeSatisfies(method);
25+
|| MethodSkipVersionAttributeSatisfies(method)
26+
|| SkipWhenRunOnTeamCity(classOfMethod, method);
27+
}
2328
}
2429

30+
2531
private static bool SkipClassMarkedWithRequiresPluginFor2XSnapshotBuildTests(Type classOfMethod)
2632
{
2733
var v = TestClient.Configuration.ElasticsearchVersion;
@@ -31,24 +37,27 @@ private static bool SkipClassMarkedWithRequiresPluginFor2XSnapshotBuildTests(Typ
3137
return attributes.Any();
3238
}
3339

34-
private static bool TypeSkipVersionAttributeSatisfies(Type classOfMethod)
35-
{
36-
var attributes = classOfMethod.GetAttributes<SkipVersionAttribute>();
37-
if (!attributes.Any()) return false;
40+
private bool SkipWhenRunOnTeamCity(Type classOfMethod, MethodInfo info) {
41+
if (!this.RunningOnTeamCity) return false;
3842

39-
return attributes
40-
.SelectMany(a => a.Ranges)
41-
.Any(range => TestClient.VersionUnderTestSatisfiedBy(range.ToString()));
43+
var attributes = classOfMethod.GetAttributes<SkipOnTeamCityAttribute>().Concat(info.GetAttributes<SkipOnTeamCityAttribute>());
44+
return attributes.Any();
4245
}
4346

44-
private static bool MethodSkipVersionAttributeSatisfies(MethodInfo methodInfo)
47+
private static bool TypeSkipVersionAttributeSatisfies(Type classOfMethod) =>
48+
VersionUnderTestMatchesAttribute(classOfMethod.GetAttributes<SkipVersionAttribute>());
49+
50+
private static bool MethodSkipVersionAttributeSatisfies(MethodInfo methodInfo) =>
51+
VersionUnderTestMatchesAttribute(methodInfo.GetAttributes<SkipVersionAttribute>());
52+
53+
private static bool VersionUnderTestMatchesAttribute(IEnumerable<SkipVersionAttribute> attributes)
4554
{
46-
var attributes = methodInfo.GetAttributes<SkipVersionAttribute>();
4755
if (!attributes.Any()) return false;
4856

4957
return attributes
5058
.SelectMany(a => a.Ranges)
5159
.Any(range => TestClient.VersionUnderTestSatisfiedBy(range.ToString()));
5260
}
61+
5362
}
5463
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System;
2+
3+
namespace Tests.Framework
4+
{
5+
public class SkipOnTeamCityAttribute : Attribute
6+
{
7+
public SkipOnTeamCityAttribute(string reason)
8+
{
9+
}
10+
}
11+
}

src/Tests/Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,4 @@
3939
<ItemGroup>
4040
<EmbeddedResource Include="Document\Single\Attachment\Attachment_Test_Document.pdf" />
4141
</ItemGroup>
42-
</Project>
42+
</Project>

0 commit comments

Comments
 (0)