Skip to content

Commit 33b07be

Browse files
committed
itest: even out num of tests per tranche
Previous splitting logic simply put all the remainder in the last tranche, which could make the last tranche run significantly more test cases. We now change it so the remainder is evened out across tranches.
1 parent c536bc2 commit 33b07be

File tree

1 file changed

+27
-6
lines changed

1 file changed

+27
-6
lines changed

itest/lnd_test.go

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,30 @@ func maybeShuffleTestCases() {
174174
})
175175
}
176176

177+
// createIndices divides the number of test cases into pairs of indices that
178+
// specify the start and end of a tranche.
179+
func createIndices(numCases, numTranches uint) [][2]uint {
180+
// Calculate base value and remainder.
181+
base := numCases / numTranches
182+
remainder := numCases % numTranches
183+
184+
// Generate indices.
185+
indices := make([][2]uint, numTranches)
186+
start := uint(0)
187+
188+
for i := uint(0); i < numTranches; i++ {
189+
end := start + base
190+
if i < remainder {
191+
// Add one for the remainder.
192+
end++
193+
}
194+
indices[i] = [2]uint{start, end}
195+
start = end
196+
}
197+
198+
return indices
199+
}
200+
177201
// getTestCaseSplitTranche returns the sub slice of the test cases that should
178202
// be run as the current split tranche as well as the index and slice offset of
179203
// the tranche.
@@ -200,12 +224,9 @@ func getTestCaseSplitTranche() ([]*lntest.TestCase, uint, uint) {
200224
maybeShuffleTestCases()
201225

202226
numCases := uint(len(allTestCases))
203-
testsPerTranche := numCases / numTranches
204-
trancheOffset := runTranche * testsPerTranche
205-
trancheEnd := trancheOffset + testsPerTranche
206-
if trancheEnd > numCases || runTranche == numTranches-1 {
207-
trancheEnd = numCases
208-
}
227+
indices := createIndices(numCases, numTranches)
228+
index := indices[runTranche]
229+
trancheOffset, trancheEnd := index[0], index[1]
209230

210231
return allTestCases[trancheOffset:trancheEnd], threadID,
211232
trancheOffset

0 commit comments

Comments
 (0)