Skip to content

Commit 72c63bd

Browse files
committed
Add ApolloClient execution tests for callback queue
1 parent 3225406 commit 72c63bd

2 files changed

Lines changed: 63 additions & 6 deletions

File tree

Apollo.xcodeproj/project.pbxproj

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@
240240
DED46035261CEA660086EF63 /* ApolloTestSupport.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9F8A95781EC0FC1200304A2D /* ApolloTestSupport.framework */; };
241241
DED46042261CEA8A0086EF63 /* TestServerURLs.swift in Sources */ = {isa = PBXBuildFile; fileRef = DED45C172615308E0086EF63 /* TestServerURLs.swift */; };
242242
DED46051261CEAD20086EF63 /* StarWarsAPI.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9FCE2CFA1E6C213D00E34457 /* StarWarsAPI.framework */; };
243+
E616B6D126C3335600DB049E /* ExecutionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = E616B6D026C3335600DB049E /* ExecutionTests.swift */; };
243244
E86D8E05214B32FD0028EFE1 /* JSONTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = E86D8E03214B32DA0028EFE1 /* JSONTests.swift */; };
244245
F16D083C21EF6F7300C458B8 /* QueryFromJSONBuildingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = F16D083B21EF6F7300C458B8 /* QueryFromJSONBuildingTests.swift */; };
245246
F82E62E122BCD223000C311B /* AutomaticPersistedQueriesTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = F82E62E022BCD223000C311B /* AutomaticPersistedQueriesTests.swift */; };
@@ -795,6 +796,7 @@
795796
DED45FB1261CDE7D0086EF63 /* Apollo-PerformanceTestPlan.xctestplan */ = {isa = PBXFileReference; lastKnownFileType = text; path = "Apollo-PerformanceTestPlan.xctestplan"; sourceTree = "<group>"; };
796797
DED45FB2261CDE980086EF63 /* Apollo-CITestPlan.xctestplan */ = {isa = PBXFileReference; lastKnownFileType = text; path = "Apollo-CITestPlan.xctestplan"; sourceTree = "<group>"; };
797798
DED45FB3261CDEC60086EF63 /* Apollo-CodegenTestPlan.xctestplan */ = {isa = PBXFileReference; lastKnownFileType = text; path = "Apollo-CodegenTestPlan.xctestplan"; sourceTree = "<group>"; };
799+
E616B6D026C3335600DB049E /* ExecutionTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ExecutionTests.swift; sourceTree = "<group>"; };
798800
E86D8E03214B32DA0028EFE1 /* JSONTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JSONTests.swift; sourceTree = "<group>"; };
799801
F16D083B21EF6F7300C458B8 /* QueryFromJSONBuildingTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = QueryFromJSONBuildingTests.swift; sourceTree = "<group>"; };
800802
F82E62E022BCD223000C311B /* AutomaticPersistedQueriesTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AutomaticPersistedQueriesTests.swift; sourceTree = "<group>"; };
@@ -1455,32 +1457,33 @@
14551457
9FC750521D2A532D00458D91 /* ApolloTests */ = {
14561458
isa = PBXGroup;
14571459
children = (
1458-
DED45E9B261BA0CA0086EF63 /* WebSocket */,
14591460
DED45DE8261B969F0086EF63 /* Cache */,
14601461
9B0417812390320A00C9EC4E /* TestHelpers */,
1461-
9FC750551D2A532D00458D91 /* Info.plist */,
1462+
DED45E9B261BA0CA0086EF63 /* WebSocket */,
14621463
D87AC09E2564D60B0079FAA5 /* ApolloClientOperationTests.swift */,
14631464
F82E62E022BCD223000C311B /* AutomaticPersistedQueriesTests.swift */,
14641465
9F438D0B1E6C494C007BDC1A /* BatchedLoadTests.swift */,
14651466
9FC9A9C71E2EFE6E0023C4D5 /* CacheKeyForFieldTests.swift */,
14661467
9FADC8531E6B86D900C677E6 /* DataLoaderTests.swift */,
1468+
DED45C292615319E0086EF63 /* DefaultInterceptorProviderTests.swift */,
14671469
9B78C71B2326E859000C8C32 /* ErrorGenerationTests.swift */,
1470+
E616B6D026C3335600DB049E /* ExecutionTests.swift */,
14681471
9F8622F91EC2117C00C38162 /* FragmentConstructionAndConversionTests.swift */,
14691472
9B95EDBF22CAA0AF00702BB2 /* GETTransformerTests.swift */,
14701473
9B21FD742422C29D00998B5C /* GraphQLFileTests.swift */,
1471-
9BC139A224EDCA4400876D29 /* InterceptorTests.swift */,
14721474
9FF90A6A1DDDEB420034C3B6 /* GraphQLMapEncodingTests.swift */,
1475+
9FC750551D2A532D00458D91 /* Info.plist */,
1476+
9BC139A224EDCA4400876D29 /* InterceptorTests.swift */,
14731477
E86D8E03214B32DA0028EFE1 /* JSONTests.swift */,
1474-
9F91CF8E1F6C0DB2008DD0BE /* MutatingResultsTests.swift */,
14751478
9BF6C95225194EA5000D5B93 /* MultipartFormDataTests.swift */,
1479+
9F91CF8E1F6C0DB2008DD0BE /* MutatingResultsTests.swift */,
14761480
9F295E301E27534800A24949 /* NormalizeQueryResults.swift */,
14771481
9FF90A6C1DDDEB420034C3B6 /* ParseQueryResponseTests.swift */,
14781482
9F21735A2568F3E200566121 /* PossiblyDeferredTests.swift */,
14791483
F16D083B21EF6F7300C458B8 /* QueryFromJSONBuildingTests.swift */,
14801484
9FF90A6B1DDDEB420034C3B6 /* ReadFieldValueTests.swift */,
1481-
9B96500824BE6201003C29C0 /* RequestChainTests.swift */,
1482-
DED45C292615319E0086EF63 /* DefaultInterceptorProviderTests.swift */,
14831485
C338DF1622DD9DE9006AF33E /* RequestBodyCreatorTests.swift */,
1486+
9B96500824BE6201003C29C0 /* RequestChainTests.swift */,
14841487
9B9BBB1A24DB75E60021C30F /* UploadRequestTests.swift */,
14851488
5BB2C0222380836100774170 /* VersionNumberTests.swift */,
14861489
);
@@ -2596,6 +2599,7 @@
25962599
9BF6C99C25195019000D5B93 /* String+IncludesForTesting.swift in Sources */,
25972600
DED45DEF261B96B70086EF63 /* ReadWriteFromStoreTests.swift in Sources */,
25982601
9F91CF8F1F6C0DB2008DD0BE /* MutatingResultsTests.swift in Sources */,
2602+
E616B6D126C3335600DB049E /* ExecutionTests.swift in Sources */,
25992603
9B9BBB1C24DB760B0021C30F /* UploadRequestTests.swift in Sources */,
26002604
9BC139A424EDCA6C00876D29 /* InterceptorTests.swift in Sources */,
26012605
F82E62E122BCD223000C311B /* AutomaticPersistedQueriesTests.swift in Sources */,
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import XCTest
2+
@testable import Apollo
3+
import ApolloTestSupport
4+
5+
class ExecutionTests: XCTestCase {
6+
static let defaultWaitTimeout = 0.5
7+
8+
var store: ApolloStore!
9+
var server: MockGraphQLServer!
10+
var transport: NetworkTransport!
11+
var client: ApolloClient!
12+
13+
override func setUp() {
14+
store = ApolloStore()
15+
server = MockGraphQLServer()
16+
transport = MockNetworkTransport(server: server, store: store)
17+
client = ApolloClient(networkTransport: transport, store: store)
18+
}
19+
20+
override func tearDown() {
21+
client = nil
22+
transport = nil
23+
server = nil
24+
store = nil
25+
}
26+
27+
func testClearCacheCompletion_givenNoCallbackQueue_shouldCallbackOnMainQueue() throws {
28+
let completionCallbackExpectation = expectation(description: "clearCache completion callback on main queue")
29+
client.clearCache() { result in
30+
XCTAssertTrue(Thread.isMainThread)
31+
32+
completionCallbackExpectation.fulfill()
33+
}
34+
35+
wait(for: [completionCallbackExpectation], timeout: Self.defaultWaitTimeout)
36+
}
37+
38+
func testCacheClearCompletion_givenCustomCallbackQueue_shouldCallbackOnCustomQueue() throws {
39+
let label = "CustomQueue"
40+
let queue = DispatchQueue(label: label)
41+
let key = DispatchSpecificKey<String>()
42+
queue.setSpecific(key: key, value: label)
43+
44+
let completionCallbackExpectation = expectation(description: "clearCache completion callback on custom queue")
45+
client.clearCache(callbackQueue: queue) { result in
46+
XCTAssertEqual(DispatchQueue.getSpecific(key: key), label)
47+
48+
completionCallbackExpectation.fulfill()
49+
}
50+
51+
wait(for: [completionCallbackExpectation], timeout: Self.defaultWaitTimeout)
52+
}
53+
}

0 commit comments

Comments
 (0)