From c718f276ff774d46416d6afea907cc6c9d5935ae Mon Sep 17 00:00:00 2001 From: Jun Pataleta Date: Thu, 3 Aug 2023 11:08:40 +0800 Subject: [PATCH] MDL-78498 mod_forum: Prevent race condition in forum recent activity * Using the generator to create the forum discussions, the timecreated of a discussion can be set before the user's last course access which will prevent forum_print_recent_activity() from including this generated discussion in the recent activity results. To work around this, generate the forum discussion 1 second after the current time to make sure that the user's last course access will always be before the discussion's creation time. * This patch also includes some optimisations by: - Removing the unnecessary @javascript tag for the `Time limit expires` scenario - Bringing the discussion generation to each scenario to allow each scenario to customise the data passed to the generator like for the `Time limit expires` scenario. - Navigating directly to the forum instance. --- .../tests/behat/edit_post_student.feature | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/mod/forum/tests/behat/edit_post_student.feature b/mod/forum/tests/behat/edit_post_student.feature index af0cdddb1e9..0a92b9f0318 100644 --- a/mod/forum/tests/behat/edit_post_student.feature +++ b/mod/forum/tests/behat/edit_post_student.feature @@ -17,14 +17,13 @@ Feature: Students can edit or delete their forum posts within a set time limit And the following "activities" exist: | activity | name | course | idnumber | | forum | Test forum name | C1 | forum | - And I am on the "Course 1" course page logged in as student1 - And the following "mod_forum > discussions" exist: - | user | forum | name | message | - | student1 | forum | Forum post subject | This is the body | - And I am on the "Test forum name" "forum activity" page Scenario: Edit forum post - Given I follow "Forum post subject" + Given the following "mod_forum > discussions" exist: + | user | forum | name | message | + | student1 | forum | Forum post subject | This is the body | + And I am on the "Test forum name" "forum activity" page logged in as "student1" + And I follow "Forum post subject" And I follow "Edit" When I set the following fields to these values: | Subject | Edited post subject | @@ -35,18 +34,25 @@ Feature: Students can edit or delete their forum posts within a set time limit And I should see "Edited post body" Scenario: Delete forum post - Given I follow "Forum post subject" + Given the following "mod_forum > discussions" exist: + | user | forum | name | message | + | student1 | forum | Forum post subject | This is the body | + And I am on the "Test forum name" "forum activity" page logged in as "student1" + And I follow "Forum post subject" When I follow "Delete" And I press "Continue" Then I should not see "Forum post subject" - @javascript @block_recent_activity + @block_recent_activity Scenario: Time limit expires Given the following "blocks" exist: | blockname | contextlevel | reference | pagetypepattern | defaultregion | | recent_activity | Course | C1 | course-view-* | side-pre | And the following config values are set as admin: | maxeditingtime | 1 | + And the following "mod_forum > discussions" exist: + | user | forum | name | message | timemodified | + | student1 | forum | Forum post subject | This is the body | ##now +1 second## | And I am on the "Course 1" course page logged in as student1 And I should see "New forum posts:" in the "Recent activity" "block" And I should see "Forum post subject" in the "Recent activity" "block"