Skip to content

Commit fb91357

Browse files
authored
Move tests (#322)
1 parent 6f874bb commit fb91357

13 files changed

+398
-206
lines changed

SwiftQueue.xcodeproj/project.pbxproj

Lines changed: 56 additions & 16 deletions
Large diffs are not rendered by default.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// The MIT License (MIT)
2+
//
3+
// Copyright (c) 2019 Lucas Nelaupe
4+
//
5+
// Permission is hereby granted, free of charge, to any person obtaining a copy
6+
// of this software and associated documentation files (the "Software"), to deal
7+
// in the Software without restriction, including without limitation the rights
8+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
// copies of the Software, and to permit persons to whom the Software is
10+
// furnished to do so, subject to the following conditions:
11+
//
12+
// The above copyright notice and this permission notice shall be included in all
13+
// copies or substantial portions of the Software.
14+
//
15+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
// SOFTWARE.
22+
23+
import Foundation
24+
import XCTest
25+
@testable import SwiftQueue
26+
27+
class ConstraintTestCharging: XCTestCase {
28+
29+
func testChargingConstraintShouldRunNow() {
30+
let (type, job) = (UUID().uuidString, TestJob())
31+
32+
let creator = TestCreator([type: job])
33+
34+
let manager = SwiftQueueManagerBuilder(creator: creator).set(persister: NoSerializer.shared).build()
35+
JobBuilder(type: type)
36+
.requireCharging()
37+
.schedule(manager: manager)
38+
39+
job.awaitForRemoval()
40+
job.assertSingleCompletion()
41+
}
42+
43+
}

Tests/SwiftQueueTests/ConstraintDeadlineTests.swift renamed to Tests/SwiftQueueTests/ConstraintTest+Deadline.swift

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import Foundation
2424
import XCTest
2525
@testable import SwiftQueue
2626

27-
class ConstraintDeadlineTests: XCTestCase {
27+
class ConstraintTestDeadline: XCTestCase {
2828

2929
func testDeadlineWhenSchedule() {
3030
let (type, job) = (UUID().uuidString, TestJob())
@@ -110,20 +110,6 @@ class ConstraintDeadlineTests: XCTestCase {
110110
job.assertRemovedBeforeRun(reason: .deadline)
111111
}
112112

113-
func testDelay() {
114-
let (type, job) = (UUID().uuidString, TestJob())
115-
116-
let creator = TestCreator([type: job])
117113

118-
let manager = SwiftQueueManagerBuilder(creator: creator).set(persister: NoSerializer.shared).build()
119-
JobBuilder(type: type)
120-
.delay(time: 0.1)
121-
.schedule(manager: manager)
122-
123-
manager.waitUntilAllOperationsAreFinished()
124-
125-
job.awaitForRemoval()
126-
job.assertSingleCompletion()
127-
}
128114

129-
}
115+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// The MIT License (MIT)
2+
//
3+
// Copyright (c) 2019 Lucas Nelaupe
4+
//
5+
// Permission is hereby granted, free of charge, to any person obtaining a copy
6+
// of this software and associated documentation files (the "Software"), to deal
7+
// in the Software without restriction, including without limitation the rights
8+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
// copies of the Software, and to permit persons to whom the Software is
10+
// furnished to do so, subject to the following conditions:
11+
//
12+
// The above copyright notice and this permission notice shall be included in all
13+
// copies or substantial portions of the Software.
14+
//
15+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
// SOFTWARE.
22+
23+
import Foundation
24+
import XCTest
25+
@testable import SwiftQueue
26+
27+
class ConstraintTestDelay: XCTestCase {
28+
29+
func testDelay() {
30+
let (type, job) = (UUID().uuidString, TestJob())
31+
32+
let creator = TestCreator([type: job])
33+
34+
let manager = SwiftQueueManagerBuilder(creator: creator).set(persister: NoSerializer.shared).build()
35+
JobBuilder(type: type)
36+
.delay(time: 0.1)
37+
.schedule(manager: manager)
38+
39+
manager.waitUntilAllOperationsAreFinished()
40+
41+
job.awaitForRemoval()
42+
job.assertSingleCompletion()
43+
}
44+
45+
46+
}

Tests/SwiftQueueTests/ConstraintNetworkTests.swift renamed to Tests/SwiftQueueTests/ConstraintTest+Network.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import Foundation
2424
import XCTest
2525
@testable import SwiftQueue
2626

27-
class ConstraintNetworkTests: XCTestCase {
27+
class ConstraintTestNetwork: XCTestCase {
2828

2929
func testNetworkConstraint() {
3030
let (type, job) = (UUID().uuidString, TestJob())
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
// The MIT License (MIT)
2+
//
3+
// Copyright (c) 2019 Lucas Nelaupe
4+
//
5+
// Permission is hereby granted, free of charge, to any person obtaining a copy
6+
// of this software and associated documentation files (the "Software"), to deal
7+
// in the Software without restriction, including without limitation the rights
8+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
// copies of the Software, and to permit persons to whom the Software is
10+
// furnished to do so, subject to the following conditions:
11+
//
12+
// The above copyright notice and this permission notice shall be included in all
13+
// copies or substantial portions of the Software.
14+
//
15+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
// SOFTWARE.
22+
23+
import Foundation
24+
import XCTest
25+
@testable import SwiftQueue
26+
27+
class ConstraintTestRepeat: XCTestCase {
28+
29+
func testPeriodicJob() {
30+
let (type, job) = (UUID().uuidString, TestJob())
31+
32+
let creator = TestCreator([type: job])
33+
34+
let manager = SwiftQueueManagerBuilder(creator: creator).set(persister: NoSerializer.shared).build()
35+
JobBuilder(type: type)
36+
.periodic(limit: .limited(5))
37+
.schedule(manager: manager)
38+
39+
job.awaitForRemoval()
40+
job.assertRunCount(expected: 5)
41+
job.assertCompletedCount(expected: 1)
42+
job.assertRetriedCount(expected: 0)
43+
job.assertCanceledCount(expected: 0)
44+
job.assertNoError()
45+
}
46+
47+
func testPeriodicJobUnlimited() {
48+
let runLimit = 100
49+
let type = UUID().uuidString
50+
51+
var runCount = 0
52+
53+
let job = TestJob(retry: .retry(delay: 0)) {
54+
runCount += 1
55+
if runCount == runLimit {
56+
$0.done(.fail(JobError()))
57+
} else {
58+
$0.done(.success)
59+
}
60+
}
61+
62+
let creator = TestCreator([type: job])
63+
64+
let manager = SwiftQueueManagerBuilder(creator: creator).set(persister: NoSerializer.shared).build()
65+
JobBuilder(type: type)
66+
.periodic(limit: .unlimited)
67+
.schedule(manager: manager)
68+
69+
job.awaitForRemoval()
70+
job.assertRunCount(expected: runLimit)
71+
job.assertCompletedCount(expected: 0)
72+
job.assertRetriedCount(expected: 0)
73+
job.assertCanceledCount(expected: 1)
74+
job.assertError()
75+
}
76+
77+
func testRepeatableJobWithDelay() {
78+
let (type, job) = (UUID().uuidString, TestJob())
79+
80+
let creator = TestCreator([type: job])
81+
82+
let manager = SwiftQueueManagerBuilder(creator: creator).set(persister: NoSerializer.shared).build()
83+
JobBuilder(type: type)
84+
.periodic(limit: .limited(2), interval: Double.leastNonzeroMagnitude)
85+
.schedule(manager: manager)
86+
87+
job.awaitForRemoval()
88+
job.assertRunCount(expected: 2)
89+
job.assertCompletedCount(expected: 1)
90+
job.assertRetriedCount(expected: 0)
91+
job.assertCanceledCount(expected: 0)
92+
job.assertNoError()
93+
}
94+
95+
}

0 commit comments

Comments
 (0)