Skip to content

Commit b8e092c

Browse files
committed
added SkipOnTeamCity attribute for cancel bulk all tests that suffer from timing issues on the build server
1 parent 103d9b2 commit b8e092c

File tree

4 files changed

+32
-14
lines changed

4 files changed

+32
-14
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ private static void OnError(ref Exception ex, Exception e, EventWaitHandle handl
113113
throw e;
114114
}
115115

116-
[I]
116+
[I, SkipOnTeamCity("this test is extremely flakey on TC, but never fails localy")]
117117
public void DisposingObservableCancelsBulkAll()
118118
{
119119
var index = CreateIndexName();
@@ -158,7 +158,7 @@ public void DisposingObservableCancelsBulkAll()
158158
bulkObserver.TotalNumberOfFailedBuffers.Should().Be(0);
159159
}
160160

161-
[I]
161+
[I, SkipOnTeamCity("this test is extremely flakey on TC, but never fails localy")]
162162
public void CancelBulkAll()
163163
{
164164
var index = CreateIndexName();
Lines changed: 18 additions & 11 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

@@ -17,29 +20,33 @@ protected override bool SkipMethod(ITestFrameworkDiscoveryOptions discoveryOptio
1720
var method = classOfMethod.GetMethod(testMethod.Method.Name, BindingFlags.FlattenHierarchy | BindingFlags.NonPublic | BindingFlags.Public)
1821
?? testMethod.Method.ToRuntimeMethod();
1922

20-
return TypeSkipVersionAttributeSatisfies(classOfMethod) ||
21-
MethodSkipVersionAttributeSatisfies(method);
23+
return TypeSkipVersionAttributeSatisfies(classOfMethod)
24+
|| MethodSkipVersionAttributeSatisfies(method)
25+
|| SkipWhenRunOnTeamCity(classOfMethod, method);
2226
}
2327

24-
25-
private static bool TypeSkipVersionAttributeSatisfies(Type classOfMethod)
28+
private bool SkipWhenRunOnTeamCity(Type classOfMethod, MethodInfo info)
2629
{
27-
var attributes = classOfMethod.GetAttributes<SkipVersionAttribute>();
28-
if (!attributes.Any()) return false;
30+
if (!this.RunningOnTeamCity) return false;
2931

30-
return attributes
31-
.SelectMany(a => a.Ranges)
32-
.Any(range => TestClient.VersionUnderTestSatisfiedBy(range.ToString()));
32+
var attributes = classOfMethod.GetAttributes<SkipOnTeamCityAttribute>().Concat(info.GetAttributes<SkipOnTeamCityAttribute>());
33+
return attributes.Any();
3334
}
3435

35-
private static bool MethodSkipVersionAttributeSatisfies(MethodInfo methodInfo)
36+
private static bool TypeSkipVersionAttributeSatisfies(Type classOfMethod) =>
37+
VersionUnderTestMatchesAttribute(classOfMethod.GetAttributes<SkipVersionAttribute>());
38+
39+
private static bool MethodSkipVersionAttributeSatisfies(MethodInfo methodInfo) =>
40+
VersionUnderTestMatchesAttribute(methodInfo.GetAttributes<SkipVersionAttribute>());
41+
42+
private static bool VersionUnderTestMatchesAttribute(IEnumerable<SkipVersionAttribute> attributes)
3643
{
37-
var attributes = methodInfo.GetAttributes<SkipVersionAttribute>();
3844
if (!attributes.Any()) return false;
3945

4046
return attributes
4147
.SelectMany(a => a.Ranges)
4248
.Any(range => TestClient.VersionUnderTestSatisfiedBy(range.ToString()));
4349
}
50+
4451
}
4552
}
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)