-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Simplifiy existing split of tests #1352
Simplifiy existing split of tests #1352
Conversation
Configure Renovate
########################################################################################################## | ||
########################################################################################################## | ||
|
||
per_instance=$((${NUMBER_OF_TESTS} / ${NUMBER_OF_JOBS})) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The easiest way to explain what this is doing is via an example. This piece of code acts as a "function", and each step of the matrix (32 instances) call this function.
As input to it, it provides:
CURRENT_INDEX
(number of the current instance of the matrix), this value is between 0 and 31, inclusiv.
As an output it will provide two things:
start_from
how_many
This part is easy to understand via an actual example.
Suppose we have such a config: there are a total of 347 tests to be run on 32 instances (matrix steps). We need to split these. If we had 320 tests, the distribution would have been easy:
320 / 32 = 10
, so each instance of the matrix would run 10 tests. In that case, let's suppose CURRENT_INDEX = 0
, as such:
start_from = 0
how_many = 10
that is, for the case when matrix step = 0 (current_index = 0
), we would need to start at the zero index of the entire list of tests and take 10 of them.
If current_index = 1, then start_from = 10
and how_many = 10
. If current_index = 2
, then start_from=20
and how_many = 10
, and so on.
To map current_index to it's actual start_from
and how_many
, I name them: start_from_${CURRENT_INDEX}
and how_many_${CURRENT_INDEX}
. For example:
current_index = 0 => `start_from_0 = 0, how_many_0 = 10`
current_index = 1 => `start_from_1 = 10, how_many_1 = 10`
current_index = 2 => `start_from_0 = 20, how_many_0 = 10`
These start_from_0 = 0, how_many_0 = 10
are set as environment variables, so that they could be referenced in the common code later.
For a distribution that is not perfect, 347 tests across 32 instances, the idea is simple also:
- first pretend there is a perfect distribution:
347 / 32 = 10
- then compute the reminder :
347 - 347/ 32 = 25
This means we are left with 25 tests that should go to "some" instances. And Ido this like this:
give each first "reminder of instances" (25), each one extra test. In numbers:
current_index = 0 => `start_from_0 = 0, how_many_0 = 10 + 1`
current_index = 1 => `start_from_0 = 11, how_many_0 = 10 + 1`
current_index = 2 => `start_from_0 = 22, how_many_0 = 10 + 1`
...
The rest of instances, that is 26-th, 27-th and so one will each run 10 tests.
I honestly hope this makes sense.
echo "total tests : $number_of_tests, jobs: $number_of_jobs, current index : $current_index. will run tests in range : [$left_bound..$right_bound]" | ||
fi | ||
|
||
start_from_name=start_from_${CURRENT_INDEX} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is the name of the env variable that we need:
start_from_name
would be something like start_from_0
or start_from_2
etc. Same for how_many_name
.
Once I know the name, I read its value: start_from=${!start_from_name}
and how_many=${!how_many_name}
This is later used to "slice" the array of all tests:
sliced_array=(${SORTED_TEST_CLASSNAMES[@]:$start_from:$how_many})
and these are the tests that a certain matrix step runs.
@ryanjbaxter final PR before I can focus on the balanced tests splits. thank you for looking into it |
No description provided.