Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(generate-matrix): load balancing input validation #635

Merged
merged 1 commit into from
Jul 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions dist/839.index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/839.index.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7,526 changes: 7,526 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

12 changes: 7 additions & 5 deletions src/helpers/generate-matrix.ts
Original file line number Diff line number Diff line change
@@ -36,15 +36,17 @@ export const generateMatrix = ({ paths, batches: _batches = '1', load_balancing_
let currentLoadSize = 0;
let currentBatch: string[] = [];
matrixValues.forEach((path, index) => {
if (!loadBalancingSizes[index]) throw new Error('load_balancing_sizes input must contain values');
const possibleLoadSize = currentLoadSize + loadBalancingSizes[index];
if (Math.abs(possibleLoadSize - targetLoadSize) <= Math.abs(loadBalancingSizes[index] - targetLoadSize)) {
currentLoadSize += loadBalancingSizes[index];
if (Number.isNaN(loadBalancingSizes[index])) throw new Error('load_balancing_sizes input must contain values');
// we've already validated that a value exists at this index above, but TS really _needs_ to see us validate it againgit
const loadAtIndex = (loadBalancingSizes[index] !== undefined ? loadBalancingSizes[index] : 0) as number;
const possibleLoadSize = currentLoadSize + loadAtIndex;
if (Math.abs(possibleLoadSize - targetLoadSize) <= Math.abs(loadAtIndex - targetLoadSize)) {
currentLoadSize += loadAtIndex;
currentBatch.push(path);
} else {
loadBalancedPaths.push(currentBatch.join(','));
currentBatch = [path];
currentLoadSize = loadBalancingSizes[index];
currentLoadSize = loadAtIndex;
}
if (currentLoadSize >= targetLoadSize) {
loadBalancedPaths.push(currentBatch.join(','));
2 changes: 1 addition & 1 deletion test/helpers/generate-matrix.test.ts
Original file line number Diff line number Diff line change
@@ -58,7 +58,7 @@ describe('generateMatrix', () => {
it('should generate matrix json with appropriate load balancing in medium case', () => {
const result = generateMatrix({
paths: 'path/1,path/2,path/3,path/4,path/5,path/6',
load_balancing_sizes: '2,4,1,12,6,2',
load_balancing_sizes: '2,4,0,12,6,2',
batches: '3'
});
expect(result).toEqual({