-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make backgroundTask available for MacOS 10.15 (#299)
- Loading branch information
Showing
8 changed files
with
152 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
// The MIT License (MIT) | ||
// | ||
// Copyright (c) 2019 Lucas Nelaupe | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in all | ||
// copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
// SOFTWARE. | ||
|
||
import XCTest | ||
import Dispatch | ||
@testable import SwiftQueue | ||
|
||
@available(iOS 13.0, tvOS 13.0, macOS 10.15, *) | ||
class BackgroundTasksTest { | ||
|
||
let serializers: [JobInfoSerializer] = [ | ||
V1Serializer(), | ||
DecodableSerializer() | ||
] | ||
|
||
@available(iOS 13.0, tvOS 13.0, macOS 10.15, *) | ||
public func testBackgroundOperationShouldNotRun() { | ||
let (type, job) = (UUID().uuidString, TestJob()) | ||
|
||
let creator = TestCreator([type: job]) | ||
|
||
let manager = SwiftQueueManagerBuilder(creator: creator).set(persister: NoSerializer.shared).build() | ||
JobBuilder(type: type) | ||
.periodic(executor: .background) | ||
.internet(atLeast: .wifi) | ||
.priority(priority: .veryHigh) | ||
.service(quality: .background) | ||
.schedule(manager: manager) | ||
|
||
job.assertNoRun() | ||
} | ||
|
||
|
||
@available(iOS 13.0, tvOS 13.0, macOS 10.15, *) | ||
public func testBuilderPeriodicLimited() throws { | ||
for serializer in serializers { | ||
let type = UUID().uuidString | ||
let limited: Double = 123 | ||
let interval: Double = 12342 | ||
let executor = Executor.any | ||
|
||
let jobInfo = try toJobInfo(serializer, type: type, JobBuilder(type: type).periodic(limit: .limited(limited), interval: interval, executor: .any)) | ||
XCTAssertEqual(jobInfo?.maxRun, Limit.limited(limited)) | ||
XCTAssertEqual(jobInfo?.interval, interval) | ||
XCTAssertEqual(jobInfo?.executor, executor) | ||
} | ||
} | ||
|
||
@available(iOS 13.0, tvOS 13.0, macOS 10.15, *) | ||
public func testBuilderPeriodicBackground() throws { | ||
for serializer in serializers { | ||
let type = UUID().uuidString | ||
let limited: Double = 123 | ||
let interval: Double = 12342 | ||
let executor = Executor.background | ||
|
||
let jobInfo = try toJobInfo(serializer, type: type, JobBuilder(type: type).periodic(limit: .limited(limited), interval: interval, executor: .background)) | ||
XCTAssertEqual(jobInfo?.maxRun, Limit.limited(limited)) | ||
XCTAssertEqual(jobInfo?.interval, interval) | ||
XCTAssertEqual(jobInfo?.executor, executor) | ||
} | ||
} | ||
|
||
@available(iOS 13.0, tvOS 13.0, macOS 10.15, *) | ||
public func testGetAllAllowBackgroundOperation() { | ||
let (type, job) = (UUID().uuidString, TestJob()) | ||
|
||
let id = UUID().uuidString | ||
let id2 = UUID().uuidString | ||
|
||
let group = UUID().uuidString | ||
let group2 = UUID().uuidString | ||
|
||
let creator = TestCreator([type: job]) | ||
|
||
let persister = PersisterTracker(key: UUID().uuidString) | ||
|
||
let manager = SwiftQueueManagerBuilder(creator: creator).set(isSuspended: true).set(persister: persister).build() | ||
|
||
JobBuilder(type: type).periodic(executor: .foreground).parallel(queueName: group).schedule(manager: manager) | ||
JobBuilder(type: type).periodic(executor: .foreground).parallel(queueName: group2).schedule(manager: manager) | ||
|
||
JobBuilder(type: type).singleInstance(forId: id).periodic(executor: .background).parallel(queueName: group).schedule(manager: manager) | ||
JobBuilder(type: type).singleInstance(forId: id2).periodic(executor: .any).parallel(queueName: group2).schedule(manager: manager) | ||
|
||
let result = manager.getAllAllowBackgroundOperation() | ||
|
||
XCTAssertEqual(2, result.count) | ||
XCTAssertTrue([id, id2].contains(result[0].info.uuid)) | ||
XCTAssertTrue([id, id2].contains(result[1].info.uuid)) | ||
} | ||
|
||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters