1
1
package com.malinskiy.marathon.execution.strategy.impl.retry.fixedquota
2
2
3
+ import com.malinskiy.marathon.analytics.internal.pub.Track
4
+ import com.malinskiy.marathon.config.Configuration
5
+ import com.malinskiy.marathon.config.strategy.ExecutionMode
6
+ import com.malinskiy.marathon.config.strategy.ExecutionStrategyConfiguration
3
7
import com.malinskiy.marathon.config.strategy.RetryStrategyConfiguration
8
+ import com.malinskiy.marathon.config.vendor.VendorConfiguration
4
9
import com.malinskiy.marathon.device.DevicePoolId
10
+ import com.malinskiy.marathon.execution.TestResult
5
11
import com.malinskiy.marathon.execution.TestShard
12
+ import com.malinskiy.marathon.execution.progress.PoolProgressAccumulator
6
13
import com.malinskiy.marathon.extension.toRetryStrategy
7
14
import com.malinskiy.marathon.generateTestResults
8
15
import com.malinskiy.marathon.generateTests
16
+ import com.malinskiy.marathon.report.getDevice
9
17
import org.amshove.kluent.shouldBe
10
18
import org.junit.jupiter.api.Test
19
+ import org.mockito.kotlin.mock
20
+ import java.io.File
11
21
12
22
class FixedQuotaRetryStrategyTest {
23
+ private val anySuccessConfig = Configuration .Builder (
24
+ name = " " ,
25
+ outputDir = File (" " )
26
+ ).apply {
27
+ vendorConfiguration = VendorConfiguration .StubVendorConfiguration
28
+ debug = false
29
+ analyticsTracking = false
30
+ executionStrategy = ExecutionStrategyConfiguration (ExecutionMode .ANY_SUCCESS , fast = false )
31
+ }.build()
32
+
33
+ private val track = mock<Track >()
13
34
14
35
@Test
15
36
fun `total quota tests, total quota is 1` () {
16
37
val strategy = RetryStrategyConfiguration .FixedQuotaRetryStrategyConfiguration (totalAllowedRetryQuota = 1 ).toRetryStrategy()
17
38
val poolId = DevicePoolId (" DevicePoolId-1" )
18
39
val tests = generateTests(10 )
19
40
val testResults = generateTestResults(tests)
20
- strategy.process(poolId, testResults, TestShard (tests)).size shouldBe 1
41
+ val accumulator = PoolProgressAccumulator (
42
+ poolId,
43
+ TestShard (tests),
44
+ anySuccessConfig,
45
+ track
46
+ )
47
+
48
+ strategy.process(poolId, testResults, TestShard (tests), accumulator).size shouldBe 1
21
49
}
22
50
23
51
@Test
@@ -26,7 +54,13 @@ class FixedQuotaRetryStrategyTest {
26
54
val poolId = DevicePoolId (" DevicePoolId-1" )
27
55
val tests = generateTests(10 )
28
56
val testResults = generateTestResults(tests)
29
- strategy.process(poolId, testResults, TestShard (tests)).size shouldBe 10
57
+ val accumulator = PoolProgressAccumulator (
58
+ poolId,
59
+ TestShard (tests),
60
+ anySuccessConfig,
61
+ track
62
+ )
63
+ strategy.process(poolId, testResults, TestShard (tests), accumulator).size shouldBe 10
30
64
}
31
65
32
66
@Test
@@ -35,8 +69,14 @@ class FixedQuotaRetryStrategyTest {
35
69
val poolId = DevicePoolId (" DevicePoolId-1" )
36
70
val tests = generateTests(50 )
37
71
val testResults = generateTestResults(tests)
72
+ val accumulator = PoolProgressAccumulator (
73
+ poolId,
74
+ TestShard (tests),
75
+ anySuccessConfig,
76
+ track
77
+ )
38
78
39
- strategy.process(poolId, testResults, TestShard (tests)).size shouldBe 50
79
+ strategy.process(poolId, testResults, TestShard (tests), accumulator ).size shouldBe 50
40
80
}
41
81
42
82
@Test
@@ -45,11 +85,44 @@ class FixedQuotaRetryStrategyTest {
45
85
val poolId = DevicePoolId (" DevicePoolId-1" )
46
86
val tests = generateTests(50 )
47
87
val testResults = generateTestResults(tests)
88
+ val accumulator = PoolProgressAccumulator (
89
+ poolId,
90
+ TestShard (tests),
91
+ anySuccessConfig,
92
+ track
93
+ )
94
+
95
+ strategy.process(
96
+ poolId,
97
+ testResults,
98
+ TestShard (tests, flakyTests = tests + tests + tests),
99
+ accumulator
100
+ ).size shouldBe 0
101
+ }
102
+
103
+ @Test
104
+ fun `should return 0 tests if test reached terminal state` () {
105
+ val strategy = RetryStrategyConfiguration .FixedQuotaRetryStrategyConfiguration ().toRetryStrategy()
106
+ val poolId = DevicePoolId (" DevicePoolId-1" )
107
+ val tests = generateTests(1 )
108
+ val testResults = generateTestResults(tests)
109
+ val accumulator = PoolProgressAccumulator (
110
+ poolId,
111
+ TestShard (tests),
112
+ anySuccessConfig,
113
+ track
114
+ )
115
+ val deviceInfo = getDevice()
116
+
117
+ val test = tests.first()
118
+ accumulator.testStarted(deviceInfo, test)
119
+ accumulator.testEnded(deviceInfo, testResults.first())
48
120
49
121
strategy.process(
50
122
poolId,
51
123
testResults,
52
- TestShard (tests, flakyTests = tests + tests + tests)
124
+ TestShard (tests),
125
+ accumulator
53
126
).size shouldBe 0
54
127
}
55
128
}
0 commit comments