From 11ff11135154e2b000000148313c95712af429bc Mon Sep 17 00:00:00 2001 From: Corey Baker Date: Mon, 2 Aug 2021 16:21:10 -0400 Subject: [PATCH 1/5] Remove LiveQuery flaky tests --- Tests/ParseSwiftTests/ParseLiveQueryTests.swift | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/Tests/ParseSwiftTests/ParseLiveQueryTests.swift b/Tests/ParseSwiftTests/ParseLiveQueryTests.swift index 253a9225e..6adbf73e7 100644 --- a/Tests/ParseSwiftTests/ParseLiveQueryTests.swift +++ b/Tests/ParseSwiftTests/ParseLiveQueryTests.swift @@ -524,18 +524,6 @@ class ParseLiveQueryTests: XCTestCase { XCTAssertNotNil(URLSession.liveQuery.delegates[client.task]) } - func testCloseAll() throws { - let client = try ParseLiveQuery() - XCTAssertTrue(client.task.state == .running) - client.closeAll() - let expectation1 = XCTestExpectation(description: "Close all") - client.synchronizationQueue.asyncAfter(deadline: .now() + 2) { - XCTAssertTrue(client.task.state == .suspended) - expectation1.fulfill() - } - wait(for: [expectation1], timeout: 20.0) - } - func testPingSocketNotEstablished() throws { guard let client = ParseLiveQuery.getDefault() else { XCTFail("Should be able to get client") From 7363cb9cc95b2d96c74ef31e027f9e8fbd21ee92 Mon Sep 17 00:00:00 2001 From: Corey Date: Tue, 3 Aug 2021 07:20:40 -0400 Subject: [PATCH 2/5] Bump SDK version --- Sources/ParseSwift/ParseConstants.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/ParseSwift/ParseConstants.swift b/Sources/ParseSwift/ParseConstants.swift index 461ba9060..023095809 100644 --- a/Sources/ParseSwift/ParseConstants.swift +++ b/Sources/ParseSwift/ParseConstants.swift @@ -10,7 +10,7 @@ import Foundation enum ParseConstants { static let sdk = "swift" - static let version = "1.9.2" + static let version = "1.9.3" static let fileManagementDirectory = "parse/" static let fileManagementPrivateDocumentsDirectory = "Private Documents/" static let fileManagementLibraryDirectory = "Library/" From f96d544ff1fd117453e2d2491e62aef4d961f4b1 Mon Sep 17 00:00:00 2001 From: Corey Date: Tue, 3 Aug 2021 07:31:04 -0400 Subject: [PATCH 3/5] Update CHANGELOG.md --- CHANGELOG.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 73a8f82ea..efa83065c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,9 +1,11 @@ # Parse-Swift Changelog ### main -[Full Changelog](https://github.com/parse-community/Parse-Swift/compare/1.9.2...main) +[Full Changelog](https://github.com/parse-community/Parse-Swift/compare/1.9.3...main) * _Contributing to this repo? Add info about your change here to be included in the next release_ +### 1.9.3 +[Full Changelog](https://github.com/parse-community/Parse-Swift/compare/1.9.2...1.9.3) __Improvements__ - Ensure delegate set before resuming a ParseLiveQuery task ([#209](https://github.com/parse-community/Parse-Swift/pull/209)), thanks to [Corey Baker](https://github.com/cbaker6). From 790acb3c0cff414bd0eba574a5e63acd3fe6631c Mon Sep 17 00:00:00 2001 From: Corey Baker Date: Tue, 3 Aug 2021 07:48:28 -0400 Subject: [PATCH 4/5] Add back closeAll after each test --- .../ParseSwiftTests/ParseLiveQueryTests.swift | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/Tests/ParseSwiftTests/ParseLiveQueryTests.swift b/Tests/ParseSwiftTests/ParseLiveQueryTests.swift index 6adbf73e7..c656b0d3c 100644 --- a/Tests/ParseSwiftTests/ParseLiveQueryTests.swift +++ b/Tests/ParseSwiftTests/ParseLiveQueryTests.swift @@ -68,6 +68,7 @@ class ParseLiveQueryTests: XCTestCase { try KeychainStore.shared.deleteAll() #endif try ParseStorage.shared.deleteAll() + URLSession.liveQuery.closeAll() } func testWebsocketURL() throws { @@ -524,6 +525,28 @@ class ParseLiveQueryTests: XCTestCase { XCTAssertNotNil(URLSession.liveQuery.delegates[client.task]) } + func testCloseAll() throws { + let client = try ParseLiveQuery() + guard let originalTask = client.task else { + XCTFail("Should not be nil") + return + } + XCTAssertTrue(client.task.state == .running) + client.isSocketEstablished = true + client.isConnected = true + client.closeAll() + let expectation1 = XCTestExpectation(description: "Close all") + client.synchronizationQueue.asyncAfter(deadline: .now() + 2) { + XCTAssertTrue(client.task.state == .suspended) + XCTAssertFalse(client.isSocketEstablished) + XCTAssertFalse(client.isConnected) + XCTAssertNil(URLSession.liveQuery.delegates[originalTask]) + XCTAssertNotNil(URLSession.liveQuery.delegates[client.task]) + expectation1.fulfill() + } + wait(for: [expectation1], timeout: 20.0) + } + func testPingSocketNotEstablished() throws { guard let client = ParseLiveQuery.getDefault() else { XCTFail("Should be able to get client") From bedb16b71cbebc5bec838307775c081f5f736377 Mon Sep 17 00:00:00 2001 From: Corey Baker Date: Tue, 3 Aug 2021 09:31:25 -0400 Subject: [PATCH 5/5] Check synch queue after some time --- .../ParseSwiftTests/ParseLiveQueryTests.swift | 47 ++----------------- 1 file changed, 5 insertions(+), 42 deletions(-) diff --git a/Tests/ParseSwiftTests/ParseLiveQueryTests.swift b/Tests/ParseSwiftTests/ParseLiveQueryTests.swift index c656b0d3c..b36b2179c 100644 --- a/Tests/ParseSwiftTests/ParseLiveQueryTests.swift +++ b/Tests/ParseSwiftTests/ParseLiveQueryTests.swift @@ -90,10 +90,9 @@ class ParseLiveQueryTests: XCTestCase { XCTAssertTrue(client.url.absoluteString.contains("ws")) let expectation1 = XCTestExpectation(description: "Socket delegate") - client.synchronizationQueue.async { + client.synchronizationQueue.asyncAfter(deadline: .now() + 2) { let socketDelegates = URLSession.liveQuery.delegates XCTAssertNotNil(socketDelegates[client.task]) - client.close() expectation1.fulfill() } wait(for: [expectation1], timeout: 20.0) @@ -119,10 +118,9 @@ class ParseLiveQueryTests: XCTestCase { XCTAssertTrue(client.url.absoluteString.contains("ws")) XCTAssertNotEqual(client, defaultClient) let expectation1 = XCTestExpectation(description: "Socket delegate") - client.synchronizationQueue.async { + client.synchronizationQueue.asyncAfter(deadline: .now() + 2) { let socketDelegates = URLSession.liveQuery.delegates XCTAssertNotNil(socketDelegates[client.task]) - client.close() expectation1.fulfill() } wait(for: [expectation1], timeout: 20.0) @@ -139,10 +137,9 @@ class ParseLiveQueryTests: XCTestCase { XCTAssertTrue(client.url.absoluteString.contains("ws")) XCTAssertEqual(client, defaultClient) let expectation1 = XCTestExpectation(description: "Socket delegate") - client.synchronizationQueue.async { + client.synchronizationQueue.asyncAfter(deadline: .now() + 2) { let socketDelegates = URLSession.liveQuery.delegates XCTAssertNotNil(socketDelegates[client.task]) - client.close() expectation1.fulfill() } wait(for: [expectation1], timeout: 20.0) @@ -163,10 +160,9 @@ class ParseLiveQueryTests: XCTestCase { client = nil XCTAssertNotNil(ParseLiveQuery.getDefault()) let expectation1 = XCTestExpectation(description: "Socket delegate") - defaultClient.synchronizationQueue.async { + defaultClient.synchronizationQueue.asyncAfter(deadline: .now() + 2) { let socketDelegates = URLSession.liveQuery.delegates XCTAssertNotNil(socketDelegates[defaultClient.task]) - defaultClient.close() expectation1.fulfill() } wait(for: [expectation1], timeout: 20.0) @@ -190,7 +186,6 @@ class ParseLiveQueryTests: XCTestCase { XCTAssertNotNil(URLSession.liveQuery.authenticationDelegate) client.authenticationDelegate = nil XCTAssertNil(URLSession.liveQuery.authenticationDelegate) - client.close() } func testStandardMessageEncoding() throws { @@ -325,7 +320,6 @@ class ParseLiveQueryTests: XCTestCase { client.isConnected = true XCTAssertEqual(client.isConnecting, false) XCTAssertEqual(client.isConnected, false) - client.close() } func testConnectedState() throws { @@ -357,7 +351,6 @@ class ParseLiveQueryTests: XCTestCase { XCTAssertEqual(client.isConnecting, false) XCTAssertEqual(client.clientId, "yolo") XCTAssertEqual(client.attempts, ParseLiveQueryConstants.maxConnectionAttempts + 1) - client.close() } func testDisconnectedState() throws { @@ -379,7 +372,6 @@ class ParseLiveQueryTests: XCTestCase { XCTAssertEqual(client.isConnected, false) XCTAssertEqual(client.isConnecting, false) XCTAssertNil(client.clientId) - client.close() } func testSocketDisconnectedState() throws { @@ -400,7 +392,6 @@ class ParseLiveQueryTests: XCTestCase { XCTAssertEqual(client.isConnected, false) XCTAssertEqual(client.isConnecting, false) XCTAssertNil(client.clientId) - client.close() } func testUserClosedConnectionState() throws { @@ -425,7 +416,6 @@ class ParseLiveQueryTests: XCTestCase { XCTAssertEqual(client.isConnecting, false) XCTAssertNil(client.clientId) XCTAssertEqual(client.isDisconnectedByUser, true) - client.close() } func testOpenSocket() throws { @@ -438,7 +428,6 @@ class ParseLiveQueryTests: XCTestCase { client.open(isUserWantsToConnect: true) { error in XCTAssertNotNil(error) //Should always fail since WS isn't intercepted. expectation1.fulfill() - client.close() } wait(for: [expectation1], timeout: 20.0) } @@ -458,7 +447,6 @@ class ParseLiveQueryTests: XCTestCase { XCTAssertEqual(delegate.code, .goingAway) XCTAssertNil(delegate.reason) XCTAssertTrue(client.task.state == .completed) - client.close() expectation1.fulfill() } wait(for: [expectation1], timeout: 20.0) @@ -563,7 +551,6 @@ class ParseLiveQueryTests: XCTestCase { } XCTAssertEqual(parseError.code, ParseError.Code.unknownError) XCTAssertTrue(parseError.message.contains("socket status")) - client.close() expectation1.fulfill() } wait(for: [expectation1], timeout: 20.0) @@ -583,7 +570,6 @@ class ParseLiveQueryTests: XCTestCase { client.sendPing { error in XCTAssertEqual(client.isSocketEstablished, true) XCTAssertNotNil(error) // Should have error because testcases don't intercept websocket - client.close() expectation1.fulfill() } wait(for: [expectation1], timeout: 20.0) @@ -600,7 +586,6 @@ class ParseLiveQueryTests: XCTestCase { XCTAssertGreaterThan(time, -1) client.attempts += index } - client.close() } func testRandomIdGenerator() throws { @@ -612,7 +597,6 @@ class ParseLiveQueryTests: XCTestCase { let idGenerated = client.requestIdGenerator() XCTAssertEqual(idGenerated.value, index) } - client.close() } func testSubscribeNotConnected() throws { @@ -632,7 +616,6 @@ class ParseLiveQueryTests: XCTestCase { XCTAssertEqual(client.pendingSubscriptions.count, 1) XCTAssertNoThrow(try client.removePendingSubscription(query)) XCTAssertEqual(client.pendingSubscriptions.count, 0) - client.close() } func pretendToBeConnected() throws { @@ -686,7 +669,6 @@ class ParseLiveQueryTests: XCTestCase { XCTAssertEqual(query, unsubscribed) XCTAssertNil(subscription.subscribed) XCTAssertNil(subscription.event) - client.close() expectation2.fulfill() } @@ -753,7 +735,6 @@ class ParseLiveQueryTests: XCTestCase { XCTAssertTrue(client.pendingSubscriptions.isEmpty) XCTAssertTrue(client.subscriptions.isEmpty) XCTAssertFalse(client.isSocketEstablished) - client.close() expectation2.fulfill() } XCTAssertNotNil(try? query.unsubscribe()) @@ -821,7 +802,6 @@ class ParseLiveQueryTests: XCTestCase { } else { XCTAssertNotNil(ParseLiveQuery.client?.task) XCTAssertFalse(originalTask == ParseLiveQuery.client?.task) - client.close() expectation2.fulfill() return } @@ -894,7 +874,6 @@ class ParseLiveQueryTests: XCTestCase { let encoded = try ParseCoding.jsonEncoder().encode(response) client.received(encoded) XCTAssertEqual(client.url, url) - client.close() } func testServerErrorResponse() throws { @@ -919,7 +898,6 @@ class ParseLiveQueryTests: XCTestCase { XCTAssertNotNil(delegate.error) XCTAssertEqual(delegate.error?.code, ParseError.Code.internalServer) XCTAssertTrue(delegate.error?.message.contains("message") != nil) - client.close() expectation1.fulfill() } wait(for: [expectation1], timeout: 20.0) @@ -950,11 +928,10 @@ class ParseLiveQueryTests: XCTestCase { expectation1.fulfill() } let expectation2 = XCTestExpectation(description: "Client closed") - client.synchronizationQueue.async { + client.synchronizationQueue.asyncAfter(deadline: .now() + 2) { XCTAssertTrue(client.isDisconnectedByUser) XCTAssertFalse(client.isConnected) XCTAssertFalse(client.isConnecting) - client.close() expectation2.fulfill() } wait(for: [expectation1, expectation2], timeout: 20.0) @@ -991,7 +968,6 @@ class ParseLiveQueryTests: XCTestCase { default: XCTFail("Should have receeived event") } - client.close() expectation1.fulfill() } @@ -1044,7 +1020,6 @@ class ParseLiveQueryTests: XCTestCase { default: XCTFail("Should have receeived event") } - client.close() expectation1.fulfill() } @@ -1097,7 +1072,6 @@ class ParseLiveQueryTests: XCTestCase { default: XCTFail("Should have receeived event") } - client.close() expectation1.fulfill() } @@ -1150,7 +1124,6 @@ class ParseLiveQueryTests: XCTestCase { default: XCTFail("Should have receeived event") } - client.close() expectation1.fulfill() } @@ -1203,7 +1176,6 @@ class ParseLiveQueryTests: XCTestCase { default: XCTFail("Should have receeived event") } - client.close() expectation1.fulfill() } @@ -1268,7 +1240,6 @@ class ParseLiveQueryTests: XCTestCase { XCTAssertFalse(subscribed.isNew) XCTAssertEqual(client.subscriptions.count, 1) XCTAssertEqual(client.pendingSubscriptions.count, 0) - client.close() expectation2.fulfill() return } @@ -1367,7 +1338,6 @@ class ParseLiveQueryTests: XCTestCase { XCTAssertNil(subscription.unsubscribed) XCTAssertEqual(client.subscriptions.count, 1) XCTAssertEqual(client.pendingSubscriptions.count, 0) - client.close() expectation2.fulfill() return } @@ -1425,7 +1395,6 @@ class ParseLiveQueryTests: XCTestCase { default: XCTFail("Should have receeived event") } - client.close() expectation1.fulfill() } @@ -1469,7 +1438,6 @@ class ParseLiveQueryTests: XCTestCase { default: XCTFail("Should have receeived event") } - client.close() expectation1.fulfill() } @@ -1513,7 +1481,6 @@ class ParseLiveQueryTests: XCTestCase { default: XCTFail("Should have receeived event") } - client.close() expectation1.fulfill() } @@ -1557,7 +1524,6 @@ class ParseLiveQueryTests: XCTestCase { default: XCTFail("Should have receeived event") } - client.close() expectation1.fulfill() } @@ -1601,7 +1567,6 @@ class ParseLiveQueryTests: XCTestCase { default: XCTFail("Should have receeived event") } - client.close() expectation1.fulfill() } @@ -1646,7 +1611,6 @@ class ParseLiveQueryTests: XCTestCase { XCTAssertFalse(isNew) XCTAssertEqual(client.subscriptions.count, 1) XCTAssertEqual(client.pendingSubscriptions.count, 0) - client.close() expectation2.fulfill() return } @@ -1717,7 +1681,6 @@ class ParseLiveQueryTests: XCTestCase { XCTAssertTrue(isNew) XCTAssertEqual(client.subscriptions.count, 1) XCTAssertEqual(client.pendingSubscriptions.count, 0) - client.close() expectation2.fulfill() return }