Skip to content

Commit 87c457a

Browse files
author
Clément Le Provost
committed
Merge branch 'master' into v3
2 parents a3073f4 + ec4811f commit 87c457a

File tree

5 files changed

+58
-2
lines changed

5 files changed

+58
-2
lines changed

AlgoliaSearch-Client-Swift.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Pod::Spec.new do |s|
22
s.name = 'AlgoliaSearch-Client-Swift'
33
s.module_name = 'AlgoliaSearch'
4-
s.version = '2.2.1'
4+
s.version = '2.3'
55
s.license = 'MIT'
66
s.summary = 'Algolia Search API Client for iOS & OS X written in Swift.'
77
s.homepage = 'https://github.com/algolia/algoliasearch-client-swift'

AlgoliaSearch.xcodeproj/project.pbxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,7 @@
677677
buildSettings = {
678678
CLANG_ENABLE_MODULES = YES;
679679
CODE_SIGN_IDENTITY = "iPhone Developer";
680+
FRAMEWORK_SEARCH_PATHS = "$(inherited)";
680681
GCC_PREPROCESSOR_DEFINITIONS = (
681682
"DEBUG=1",
682683
"$(inherited)",
@@ -695,6 +696,7 @@
695696
buildSettings = {
696697
CLANG_ENABLE_MODULES = YES;
697698
CODE_SIGN_IDENTITY = "iPhone Developer";
699+
FRAMEWORK_SEARCH_PATHS = "$(inherited)";
698700
INFOPLIST_FILE = Tests/Info.plist;
699701
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
700702
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";

Source/Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<key>CFBundlePackageType</key>
1616
<string>FMWK</string>
1717
<key>CFBundleShortVersionString</key>
18-
<string>2.2.1</string>
18+
<string>2.3</string>
1919
<key>CFBundleSignature</key>
2020
<string>????</string>
2121
<key>CFBundleVersion</key>

Tests/ClientTests.swift

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,56 @@ class ClientTests: XCTestCase {
5858
waitForExpectationsWithTimeout(expectationTimeout, handler: nil)
5959
}
6060

61+
func testKeepAlive() {
62+
// Setup index
63+
let expectationAdd = expectationWithDescription("testAdd")
64+
let object = ["city": "San Francisco"]
65+
index.addObject(object, completionHandler: { (content, error) -> Void in
66+
XCTAssertNil(error, "Error during addObject: \(error?.description)")
67+
if content != nil {
68+
self.index.waitTask(content!["taskID"] as! Int) {
69+
(content, error) -> Void in
70+
if let error = error {
71+
XCTFail("Error during waitTask: \(error)")
72+
} else {
73+
XCTAssertEqual((content!["status"] as! String), "published", "Wait task failed")
74+
}
75+
expectationAdd.fulfill()
76+
}
77+
}
78+
})
79+
waitForExpectationsWithTimeout(expectationTimeout, handler: nil)
80+
81+
// Reset client to avoid reuse of connection (Keep-Alive)
82+
let appID = NSProcessInfo.processInfo().environment["ALGOLIA_APPLICATION_ID"] ?? APP_ID
83+
let apiKey = NSProcessInfo.processInfo().environment["ALGOLIA_API_KEY"] ?? API_KEY
84+
let testClient = AlgoliaSearch.Client(appID: appID, apiKey: apiKey)
85+
let testIndex = testClient.getIndex(safeIndexName("algol?à-swift"))
86+
87+
let bench = 10
88+
var mesuredTime = [Double]()
89+
mesuredTime.reserveCapacity(bench)
90+
91+
for _ in 1...bench {
92+
let expectation = expectationWithDescription("testKeepAlive")
93+
94+
let startTime = CACurrentMediaTime()
95+
testIndex.search(Query(query: ""), completionHandler: { (content, error) -> Void in
96+
XCTAssertNil(error, "Error during search: \(error?.description)")
97+
expectation.fulfill()
98+
})
99+
waitForExpectationsWithTimeout(expectationTimeout, handler: nil)
100+
mesuredTime.append(CACurrentMediaTime() - startTime)
101+
}
102+
103+
let avgTime = average(Array(mesuredTime.dropFirst()))
104+
let ratio = (mesuredTime[0] - avgTime) / max(mesuredTime[0], avgTime)
105+
106+
if ratio < 0.5 {
107+
XCTFail("Maybe keep-alive doesn't work")
108+
}
109+
}
110+
61111
func testListIndexes() {
62112
let expectation = expectationWithDescription("testListIndexes")
63113
let object = ["city": "San Francisco", "objectID": "a/go/?à"]

Tests/Helpers.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,7 @@ func safeIndexName(name: String) -> String {
3636
return name
3737
}
3838
}
39+
40+
func average(values: [Double]) -> Double {
41+
return values.reduce(0, combine: +) / Double(values.count)
42+
}

0 commit comments

Comments
 (0)