Skip to content

Commit 26ccb7f

Browse files
authored
Less flaky test assertions (#5462)
1 parent 9a04224 commit 26ccb7f

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

tests/Tests/Search/Search/SearchApiTests.cs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -722,11 +722,22 @@ public SearchApiRuntimeFieldsTests(ReadOnlyCluster cluster, EndpointUsage usage)
722722
protected override void ExpectResponse(ISearchResponse<Project> response)
723723
{
724724
response.Hits.Count.Should().BeGreaterThan(0);
725-
response.Hits.First().Should().NotBeNull();
726-
response.Hits.First().Type.Should().NotBeNullOrWhiteSpace();
727-
response.Hits.First().Fields.ValueOf<ProjectRuntimeFields, string>(p => p.StartedOnDayOfWeek).Should().NotBeNullOrEmpty();
728-
response.Hits.First().Fields.ValueOf<ProjectRuntimeFields, string>(p => p.ThirtyDaysFromStarted).Should().NotBeNullOrEmpty();
729-
response.Hits.First().Fields[RuntimeFieldName].As<string[]>().FirstOrDefault().Should().NotBeNullOrEmpty();
725+
726+
foreach (var hit in response.Hits)
727+
{
728+
hit.Should().NotBeNull();
729+
730+
if (hit.Source.StartedOn != default)
731+
{
732+
hit.Fields.ValueOf<ProjectRuntimeFields, string>(p => p.StartedOnDayOfWeek).Should().NotBeNullOrEmpty();
733+
hit.Fields.ValueOf<ProjectRuntimeFields, string>(p => p.ThirtyDaysFromStarted).Should().NotBeNullOrEmpty();
734+
}
735+
736+
if (!string.IsNullOrEmpty(hit.Source.Type))
737+
{
738+
hit.Fields[RuntimeFieldName].As<string[]>().FirstOrDefault().Should().NotBeNullOrEmpty();
739+
}
740+
}
730741
}
731742
}
732743
}

0 commit comments

Comments
 (0)