@@ -30,22 +30,22 @@ public function __construct()
30
30
*
31
31
* @param array $suiteConfiguration
32
32
* @param array $testNameToSize
33
- * @param integer $lines
33
+ * @param integer $time
34
34
* @return array
35
35
* @throws TestFrameworkException
36
36
*/
37
- public function getTestsGroupedBySize ($ suiteConfiguration , $ testNameToSize , $ lines )
37
+ public function getTestsGroupedBySize ($ suiteConfiguration , $ testNameToSize , $ time )
38
38
{
39
39
// we must have the lines argument in order to create the test groups
40
- if ($ lines == 0 ) {
40
+ if ($ time == 0 ) {
41
41
throw new TestFrameworkException (
42
- "Please provide the argument '--lines ' to the robo command in order to " .
42
+ "Please provide the argument '--time ' to the robo command in order to " .
43
43
" generate grouped tests manifests for a parallel execution "
44
44
);
45
45
}
46
46
47
47
$ testGroups = [];
48
- $ splitSuiteNamesToTests = $ this ->createGroupsWithinSuites ($ suiteConfiguration , $ lines );
48
+ $ splitSuiteNamesToTests = $ this ->createGroupsWithinSuites ($ suiteConfiguration , $ time );
49
49
$ splitSuiteNamesToSize = $ this ->getSuiteToSize ($ splitSuiteNamesToTests );
50
50
$ entriesForGeneration = array_merge ($ testNameToSize , $ splitSuiteNamesToSize );
51
51
arsort ($ entriesForGeneration );
@@ -58,7 +58,7 @@ public function getTestsGroupedBySize($suiteConfiguration, $testNameToSize, $lin
58
58
continue ;
59
59
}
60
60
61
- $ testGroup = $ this ->createTestGroup ($ lines , $ testName , $ testSize , $ testNameToSizeForUse );
61
+ $ testGroup = $ this ->createTestGroup ($ time , $ testName , $ testSize , $ testNameToSizeForUse );
62
62
$ testGroups [$ nodeNumber ] = $ testGroup ;
63
63
64
64
// unset the test which have been used.
@@ -88,26 +88,29 @@ public function getResultingSuiteConfig()
88
88
* a test to be used as a starting point, the size of a starting test, an array of tests available to be added to
89
89
* the group.
90
90
*
91
- * @param integer $lineMaximum
91
+ * @param integer $timeMaximum
92
92
* @param string $testName
93
93
* @param integer $testSize
94
94
* @param array $testNameToSizeForUse
95
95
* @return array
96
96
*/
97
- private function createTestGroup ($ lineMaximum , $ testName , $ testSize , $ testNameToSizeForUse )
97
+ private function createTestGroup ($ timeMaximum , $ testName , $ testSize , $ testNameToSizeForUse )
98
98
{
99
99
$ group [$ testName ] = $ testSize ;
100
100
101
- if ($ testSize < $ lineMaximum ) {
102
- while (array_sum ($ group ) < $ lineMaximum && !empty ($ testNameToSizeForUse )) {
101
+ if ($ testSize < $ timeMaximum ) {
102
+ while (array_sum ($ group ) < $ timeMaximum && !empty ($ testNameToSizeForUse )) {
103
103
$ groupSize = array_sum ($ group );
104
- $ lineGoal = $ lineMaximum - $ groupSize ;
104
+ $ lineGoal = $ timeMaximum - $ groupSize ;
105
105
106
106
$ testNameForUse = $ this ->getClosestLineCount ($ testNameToSizeForUse , $ lineGoal );
107
- $ testSizeForUse = $ testNameToSizeForUse [$ testNameForUse ];
107
+ if ($ testNameToSizeForUse [$ testNameForUse ] < $ lineGoal ) {
108
+ $ testSizeForUse = $ testNameToSizeForUse [$ testNameForUse ];
109
+ $ group [$ testNameForUse ] = $ testSizeForUse ;
110
+ }
111
+
108
112
unset($ testNameToSizeForUse [$ testNameForUse ]);
109
113
110
- $ group [$ testNameForUse ] = $ testSizeForUse ;
111
114
}
112
115
}
113
116
@@ -127,8 +130,12 @@ private function getClosestLineCount($testGroup, $desiredValue)
127
130
$ winner = key ($ testGroup );
128
131
$ closestThreshold = $ desiredValue ;
129
132
foreach ($ testGroup as $ testName => $ testValue ) {
130
- $ testThreshold = abs ($ desiredValue - $ testValue );
131
- if ($ closestThreshold > $ testThreshold ) {
133
+ // find the difference between the desired value and test candidate for the group
134
+ $ testThreshold = $ desiredValue - $ testValue ;
135
+
136
+ // if we see that the gap between the desired value is non-negative and lower than the current closest make
137
+ // the test the winner.
138
+ if ($ closestThreshold > $ testThreshold && $ testThreshold > 0 ) {
132
139
$ closestThreshold = $ testThreshold ;
133
140
$ winner = $ testName ;
134
141
}
@@ -187,7 +194,7 @@ private function getSuiteNameToTestSize($suiteConfiguration)
187
194
foreach ($ test as $ testName ) {
188
195
$ suiteNameToTestSize [$ suite ][$ testName ] = TestObjectHandler::getInstance ()
189
196
->getObject ($ testName )
190
- ->getTestActionCount ();
197
+ ->getEstimatedDuration ();
191
198
}
192
199
}
193
200
@@ -224,30 +231,30 @@ private function getSuiteToSize($suiteNamesToTests)
224
231
*
225
232
* @param string $suiteName
226
233
* @param array $tests
227
- * @param integer $lineLimit
234
+ * @param integer $maxTime
228
235
* @return array
229
236
*/
230
- private function splitTestSuite ($ suiteName , $ tests , $ lineLimit )
237
+ private function splitTestSuite ($ suiteName , $ tests , $ maxTime )
231
238
{
232
239
arsort ($ tests );
233
- $ split_suites = [];
240
+ $ splitSuites = [];
234
241
$ availableTests = $ tests ;
235
- $ split_count = 0 ;
242
+ $ splitCount = 0 ;
236
243
237
244
foreach ($ tests as $ test => $ size ) {
238
245
if (!array_key_exists ($ test , $ availableTests )) {
239
246
continue ;
240
247
}
241
248
242
- $ group = $ this ->createTestGroup ($ lineLimit , $ test , $ size , $ availableTests );
243
- $ split_suites ["{$ suiteName }_ $ {split_count }" ] = $ group ;
244
- $ this ->addSuiteToConfig ($ suiteName , "{$ suiteName }_ $ {split_count }" , $ group );
249
+ $ group = $ this ->createTestGroup ($ maxTime , $ test , $ size , $ availableTests );
250
+ $ splitSuites ["{$ suiteName }_ $ {splitCount }" ] = $ group ;
251
+ $ this ->addSuiteToConfig ($ suiteName , "{$ suiteName }_ $ {splitCount }" , $ group );
245
252
246
253
$ availableTests = array_diff_key ($ availableTests , $ group );
247
- $ split_count ++;
254
+ $ splitCount ++;
248
255
}
249
256
250
- return $ split_suites ;
257
+ return $ splitSuites ;
251
258
}
252
259
253
260
/**
0 commit comments