Skip to content

Commit

Permalink
MDL-72921 generators: exported users now match the plan size definition
Browse files Browse the repository at this point in the history
Before this patch the exported users (to csv file that jmeter consumes)
were all the enrolled users in the test course. And that's ok when the
number of users enrolled match the number of concurrent threads planned
for a jmeter plan (each thread is a user).

But when both numbers don't match, that can lead to the jmeter plan
not behaving as expected, because it iterates over the excessive users
in the file, leading to some users having run 5 loops, others 4...

The only way to make results more consistent is to, always, ensure that
the number of users exported for the plan match the plan size and not
the site size.

And that's what this issue exactly does, restrict the export to the
number of threads that the plan will have. So every user always runs
the very same number of loops.
  • Loading branch information
stronk7 committed Oct 29, 2021
1 parent b16fc54 commit b5c6ce0
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
14 changes: 10 additions & 4 deletions admin/tool/generator/classes/testplan_backend.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,12 @@ public static function create_testplan_file($courseid, $size) {
*
* @param int $courseid The target course id
* @param bool $updateuserspassword Updates the course users password to $CFG->tool_generator_users_password
* @param int|null $size of the test plan. Used to limit the number of users exported
* to match the threads in the plan. For BC, defaults to null that means all enrolled users.
* @return stored_file
*/
public static function create_users_file($courseid, $updateuserspassword) {
$csvcontents = self::generate_users_file($courseid, $updateuserspassword);
public static function create_users_file($courseid, $updateuserspassword, ?int $size = null) {
$csvcontents = self::generate_users_file($courseid, $updateuserspassword, $size);

$fs = get_file_storage();
$filerecord = self::get_file_record('users', 'csv');
Expand Down Expand Up @@ -171,14 +173,18 @@ protected static function generate_test_plan($targetcourseid, $size) {
*
* @param int $targetcourseid
* @param bool $updateuserspassword Updates the course users password to $CFG->tool_generator_users_password
* @param int|null $size of the test plan. Used to limit the number of users exported
* to match the threads in the plan. For BC, defaults to null that means all enrolled users.
* @return string The users csv file contents.
*/
protected static function generate_users_file($targetcourseid, $updateuserspassword) {
protected static function generate_users_file($targetcourseid, $updateuserspassword, ?int $size = null) {
global $CFG;

$coursecontext = context_course::instance($targetcourseid);

$users = get_enrolled_users($coursecontext, '', 0, 'u.id, u.username, u.auth', 'u.username ASC');
// If requested, get the number of users (threads) to use in the plan. We only need those in the exported file.
$planusers = self::$users[$size] ?? 0;
$users = get_enrolled_users($coursecontext, '', 0, 'u.id, u.username, u.auth', 'u.username ASC', 0, $planusers);
if (!$users) {
print_error('coursewithoutusers', 'tool_generator');
}
Expand Down
2 changes: 1 addition & 1 deletion admin/tool/generator/cli/maketestplan.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@

// Create files.
$courseid = $DB->get_field('course', 'id', array('shortname' => $shortname));
$usersfile = tool_generator_testplan_backend::create_users_file($courseid, !empty($options['updateuserspassword']));
$usersfile = tool_generator_testplan_backend::create_users_file($courseid, !empty($options['updateuserspassword']), $size);
$testplanfile = tool_generator_testplan_backend::create_testplan_file($courseid, $size);

// One file path per line so other CLI scripts can easily parse the output.
Expand Down
2 changes: 1 addition & 1 deletion admin/tool/generator/maketestplan.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@

// Creating both test plan and users files.
$testplanfile = tool_generator_testplan_backend::create_testplan_file($data->courseid, $data->size);
$usersfile = tool_generator_testplan_backend::create_users_file($data->courseid, $data->updateuserspassword);
$usersfile = tool_generator_testplan_backend::create_users_file($data->courseid, $data->updateuserspassword, $data->size);

// Test plan link.
$testplanurl = moodle_url::make_pluginfile_url(
Expand Down
7 changes: 7 additions & 0 deletions admin/tool/generator/upgrade.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
This files describes API changes in core libraries and APIs,
information provided here is intended especially for developers.

=== 4.0 ===

* Function tool_generator_testplan_backend::create_users_file() now supports to pass the size of the testing plan,
that needs to be equal or smaller than the size of the generated site. That's used to effectively restrict the
exported number of users to the number of threads the jmeter plan will have (previously all the enrolled users
were being exported, with that leading to "false" loops (users not really looping X times).

=== 3.7 ===

* Function tool_generator_testplan_backend::get_course_options() is removed, the 'course' form element is used instead.

0 comments on commit b5c6ce0

Please sign in to comment.