Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-58888

choice_get_my_response() does not return deterministic list of answers

    XMLWordPrintable

    Details

      Description

      While running lots of behat tests, randomly I was getting some failures, once with postgres and lots of times with oracle, about multiple options not being returned in the expected order.

      Example:

      --name 'Teacher can delete answers in the multiple answer choice'
       
      Moodle 3.3rc2 (Build: 20170509), 1296da97af434226cc08a72f49e1ae05ac8a8fb4
      Php: 5.6.30, oci: 11.2.0.2.0, OS: Darwin 16.5.0 x86_64
      Server OS "Darwin", Browser: "firefox"
      Started at 11-05-2017, 01:57
      .............................F-
       
      --- Pasos fallidos:
       
      001 Scenario: Teacher can delete answers in the multiple answer choice # mod/choice/tests/behat/modify_choice.feature:70
            And I should see "Your selection: Option 1; Option 3"            # /Users/stronk7/git_moodle/testing/mod/choice/tests/behat/modify_choice.feature:96
              "Your selection: Option 1; Option 3" text was not found in the page (Behat\Mink\Exception\ExpectationException)
       
      1 escenario (1 fallaron)
      31 pasos (29 pasaron, 1 fallaron, 1 saltadas)
      1m8.12s (98.50Mb)
      

      And, on the browser, I was getting "Your selection: Option 3; Option 1" instead.

      So this is about ONE OF:

      1) Or we make choice_get_my_response() return information in a fixed way:

      index f09321a5d0..ee9a3a7a5d 100644
      --- a/mod/choice/lib.php
      +++ b/mod/choice/lib.php
      @@ -1005,7 +1005,7 @@ function choice_print_overview($courses, &$htmlarray) {
        */
       function choice_get_my_response($choice) {
           global $DB, $USER;
      -    return $DB->get_records('choice_answers', array('choiceid' => $choice->id, 'userid' => $USER->id));
      +    return $DB->get_records('choice_answers', array('choiceid' => $choice->id, 'userid' => $USER->id), 'optionid');
       }
      

      2) Or we change the multiple tests to verify that all values have been selected, but separately. Sort of (in a lot of places):

      --- a/mod/choice/tests/behat/modify_choice.feature
      +++ b/mod/choice/tests/behat/modify_choice.feature
      @@ -93,7 +93,8 @@ Feature: Teacher can modify choices of the students
           And I log in as "student1"
           And I am on "Course 1" course homepage
           And I follow "Choice name"
      -    And I should see "Your selection: Option 1; Option 3"
      +    And I should see " Option 1"
      +    And I should see " Option 3"
           And I log out
       

      Only reproduced under 3.3 and postgres and oracle databases on windows... but it may affect other databases and branches.

        Attachments

          Activity

            People

            • Assignee:
              jpataleta Jun Pataleta
              Reporter:
              stronk7 Eloy Lafuente (stronk7)
              Peer reviewer:
              Jake Dallimore
              Integrator:
              Eloy Lafuente (stronk7)
              Tester:
              CiBoT
              Participants:
              Component watchers:
              Andrew Nicols, Mathew May, Michael Hawkins, Shamim Rezaie, Simey Lameze, Dan Marsden, Jake Dallimore, Jun Pataleta, Ryan Wyllie
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Fix Release Date:
                15/Jan/18