Skip to content

Commit 14bfdcc

Browse files
committed
Implement retry logic for integration tests to avoid flakiness
1 parent e50f31f commit 14bfdcc

18 files changed

+135
-28
lines changed

Tests/AlgoliaSearchClientTests/Integration/APIKeysIntegrationTests.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,12 @@ class APIKeysIntegrationTests: OnlineTestCase {
1717

1818
var keyToDelete: APIKey?
1919

20-
func testAPIKeys() throws {
20+
override var retryableTests: [() throws -> Void] {
21+
[apiKeys]
22+
}
23+
24+
25+
func apiKeys() throws {
2126

2227
let parameters = APIKeyParameters(ACLs: [.search])
2328
.set(\.description, to: "A description")

Tests/AlgoliaSearchClientTests/Integration/AnalyticsIntegrationsTests.swift

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,20 @@ import XCTest
1111

1212
class AnalyticsIntegrationTests: OnlineTestCase {
1313

14-
func testBrowsing() throws {
14+
override var retryableTests: [() throws -> Void] {
15+
[
16+
browsing,
17+
abTesting,
18+
aaTesting
19+
]
20+
}
21+
22+
func browsing() throws {
1523
let analyticsClient = AnalyticsClient(appID: client.applicationID, apiKey: client.apiKey)
1624
let _ = try analyticsClient.browseAllABTests(hitsPerPage: 3)
1725
}
1826

19-
func testABTesting() throws {
27+
func abTesting() throws {
2028

2129
let analyticsClient = AnalyticsClient(appID: client.applicationID, apiKey: client.apiKey)
2230

@@ -60,7 +68,7 @@ class AnalyticsIntegrationTests: OnlineTestCase {
6068
try AssertThrowsHTTPError(try analyticsClient.getABTest(withID: creation.wrapped.abTestID), statusCode: 404)
6169
}
6270

63-
func testAATesting() throws {
71+
func aaTesting() throws {
6472

6573
let analyticsClient = AnalyticsClient(appID: client.applicationID, apiKey: client.apiKey)
6674
let index = client.index(withName: "aa_testing")

Tests/AlgoliaSearchClientTests/Integration/BatchingIntegrationsTests.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ class BatchingIntegrationTests: OnlineTestCase {
1515
return "index_batching"
1616
}
1717

18-
func testBatching() throws {
18+
override var retryableTests: [() throws -> Void] {
19+
[batching]
20+
}
21+
22+
func batching() throws {
1923

2024
let records: [JSON] = [
2125
["objectID":"one", "key": "value"],

Tests/AlgoliaSearchClientTests/Integration/BrowseIntegrationTests.swift

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,15 @@ class BrowseIntegrationTests: OnlineTestCase {
2121
return "index_browse"
2222
}
2323

24-
func testBrowseObjects() throws {
24+
override var retryableTests: [() throws -> Void] {
25+
[
26+
browseObjects,
27+
browseRules,
28+
browseSynonyms
29+
]
30+
}
31+
32+
func browseObjects() throws {
2533

2634
struct Record: Codable {
2735
let objectID: String
@@ -46,7 +54,7 @@ class BrowseIntegrationTests: OnlineTestCase {
4654

4755
}
4856

49-
func testBrowseRules() throws {
57+
func browseRules() throws {
5058

5159
let rules: [Rule] = (0...50).map { _ in
5260
return Rule(objectID: .random)
@@ -64,7 +72,7 @@ class BrowseIntegrationTests: OnlineTestCase {
6472

6573
}
6674

67-
func testBrowseSynonyms() throws {
75+
func browseSynonyms() throws {
6876

6977
let synonyms: [Synonym] = (0...50).map { _ in
7078
switch Int.random(in: 0...3) {

Tests/AlgoliaSearchClientTests/Integration/CopyIndexIntegrationTests.swift

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,15 @@ class CopyIndexIntergrationTests: OnlineTestCase {
1515
return index!
1616
}
1717

18+
override var retryableTests: [() throws -> Void] {
19+
[
20+
copySettings,
21+
copyRules,
22+
copySynonyms,
23+
fullCopy
24+
]
25+
}
26+
1827
let records: [JSON] = [
1928
["objectID": "one", "company": "apple"],
2029
["objectID": "two", "company": "algolia"]
@@ -26,7 +35,7 @@ class CopyIndexIntergrationTests: OnlineTestCase {
2635
.set(\.consequence, to: Rule.Consequence().set(\.automaticFacetFilters, to: [Rule.AutomaticFacetFilters(attribute: "company")]))
2736
let synonym = Synonym.placeholder(objectID: "google_placeholder", placeholder: "<GOOG>", replacements: ["Google", "GOOG"])
2837

29-
func testCopySettings() throws {
38+
func copySettings() throws {
3039

3140
let targetIndex = client.index(withName: "copy_index_settings")
3241

@@ -43,7 +52,7 @@ class CopyIndexIntergrationTests: OnlineTestCase {
4352

4453
}
4554

46-
func testCopyRules() throws {
55+
func copyRules() throws {
4756

4857
let targetIndex = client.index(withName: "copy_index_rules")
4958

@@ -61,7 +70,7 @@ class CopyIndexIntergrationTests: OnlineTestCase {
6170

6271
}
6372

64-
func testCopySynonyms() throws {
73+
func copySynonyms() throws {
6574

6675
let targetIndex = client.index(withName: "copy_index_synonyms")
6776

@@ -78,7 +87,7 @@ class CopyIndexIntergrationTests: OnlineTestCase {
7887

7988
}
8089

81-
func testFullCopy() throws {
90+
func fullCopy() throws {
8291

8392
let targetIndex = client.index(withName: "copy_index_full_copy")
8493

Tests/AlgoliaSearchClientTests/Integration/ExistsIntegrationTests.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ class ExistsIntegrationTests: OnlineTestCase {
1515
return "exists"
1616
}
1717

18-
func testExists() throws {
18+
override var retryableTests: [() throws -> Void] {
19+
[exists]
20+
}
21+
22+
func exists() throws {
1923
XCTAssertFalse(try index.exists())
2024
try index.saveObject(TestRecord(), autoGeneratingObjectID: true).wait()
2125
XCTAssertTrue(try index.exists())

Tests/AlgoliaSearchClientTests/Integration/IndexingIntegrationTests.swift

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,15 @@ class IndexingIntegrationTests: OnlineTestCase {
1515
return "indexing"
1616
}
1717

18-
func testIndexing() throws {
18+
override var retryableTests: [() throws -> Void] {
19+
[
20+
indexing,
21+
saveGetObject,
22+
saveGetObjectCallback
23+
]
24+
}
25+
26+
func indexing() throws {
1927

2028
let objectID = ObjectID(rawValue: .init(randomWithLength: 10))
2129
let object = TestRecord(objectID: objectID)
@@ -107,7 +115,7 @@ class IndexingIntegrationTests: OnlineTestCase {
107115

108116
}
109117

110-
func testSaveGetObject() throws {
118+
func saveGetObject() throws {
111119

112120
let object: JSON = [
113121
"testField1": "testValue1",
@@ -122,7 +130,7 @@ class IndexingIntegrationTests: OnlineTestCase {
122130
XCTAssertEqual(fetchedObject["testField3"], true)
123131
}
124132

125-
func testSaveGetObjectCallback() throws {
133+
func saveGetObjectCallback() throws {
126134

127135
let object: JSON = [
128136
"testField1": "testValue1",

Tests/AlgoliaSearchClientTests/Integration/InsightsIntegrationTests.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ class InsightsIntegrationTests: OnlineTestCase {
1515
return "sending_events"
1616
}
1717

18-
func testInsights() throws {
18+
override var retryableTests: [() throws -> Void] {
19+
[insights]
20+
}
21+
22+
func insights() throws {
1923

2024
let insightsClient = InsightsClient(appID: client.applicationID, apiKey: client.apiKey)
2125

Tests/AlgoliaSearchClientTests/Integration/LogsIntergrationTests.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,12 @@ class LogsIntergrationTests: OnlineTestCase {
1414
override var indexNameSuffix: String? {
1515
"logs"
1616
}
17+
18+
override var retryableTests: [() throws -> Void] {
19+
[getLogs]
20+
}
1721

18-
func testGetLogs() throws {
22+
func getLogs() throws {
1923
try client.listIndices()
2024
try client.listIndices()
2125
let logs = try client.getLogs(offset: 0, length: 2, type: .all).logs

Tests/AlgoliaSearchClientTests/Integration/MultiClusterIntegrationTests.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,15 @@ class MultipleClusterIntegrationTests: OnlineTestCase {
5656

5757
let date: Date = .init()
5858

59+
override var retryableTests: [() throws -> Void] {
60+
[multiCluster]
61+
}
62+
5963
func userID(_ id: String) -> UserID {
6064
return UserID(rawValue: TestIdentifier(date: date, suffix: id).rawValue)
6165
}
6266

63-
func testMultiCluster() throws {
67+
func multiCluster() throws {
6468

6569
let userID0 = userID("0")
6670
let userID1 = userID("1")

0 commit comments

Comments
 (0)