Problem/Motivation

Split from #3412641: OpenTelemetryNodePagePerformanceTest::testNodePageHotCache() is not hot enough.

If you call $this->drupalGet('node/1') you get different behaviour when the tested site is in a subdirectory to when you do $this->drupalGet('/node/1').

See the last two commits on https://git.drupalcode.org/project/drupal/-/merge_requests/6047/commits for an attempt to fix this.

When the the path is node/1 this is resolved to subdir/en/recipes/deep-mediterranean-quiche when it is /node/1 this is resolved to subdir/en/node/1. Note that without the base directory both node/1 and /node/1 are resolved to subdir/en/recipes/deep-mediterranean-quiche.

Steps to reproduce

Proposed resolution

MR 7482 should be reviewed and merged

In core/tests/Drupal/Tests/UiHelperTrait.php strip any forward slash

Remaining tasks

Review
Commit

User interface changes

N/A

API changes

N/A

Data model changes

N/A

Release notes snippet

N/A

Issue fork drupal-3440424

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

catch created an issue. See original summary.

alexpott’s picture

Issue summary: View changes

Adding more info to the summary.

catch’s picture

Created an MR with the commit from https://git.drupalcode.org/project/drupal/-/merge_requests/6047/commits, which theoretically should have worked but didn't seem to.

catch’s picture

One thing I wonder here is:

Do we even want node/1 to be aliased when we pass it to ::drupalGet()? What if I really want to hit the unaliased path? Why not require people to generate the alias before passing it in if they want that behaviour?

alexpott’s picture

@catch - it's all a bit tricky but we rely on code in \Drupal\Tests\UiHelperTrait::buildUrl() to add the base directory and language... see:

      // Strip $base_path, if existent.
      $length = strlen($base_path);
      if (substr($path, 0, $length) === $base_path) {
        $path = substr($path, $length);
      }

      $force_internal = isset($options['external']) && $options['external'] == FALSE;
      if (!$force_internal && UrlHelper::isExternal($path)) {
        return Url::fromUri($path, $options)->toString();
      }
      else {
        $uri = $path === '<front>' ? 'base:/' : 'base:/' . $path;
        // Path processing is needed for language prefixing.  Skip it when a
        // path that may look like an external URL is being used as internal.
        $options['path_processing'] = !$force_internal;
        return Url::fromUri($uri, $options)
          ->setAbsolute()
          ->toString();

Changing this behaviour would be extremely tricky.

I think the current different behaviour for sites with and without a base directory is wrong and should be consistent but I think buildUrl should continue to:
1. Add the base directory
2. And do path processing.

I think we could improve things by making it only set the path_processing option if it is not set. Thereby allowing callers to take control of this.

alexpott’s picture

The thing I don't get is why adding

      if (strlen($path) > 1) {
        $path = ltrim($path, '/');
      }

didn't actually fix OpenTelemetryNodePagePerformanceTest::testNodePageHotCache() - v confused about that.

catch’s picture

Yes I'm also very confused about that. Maybe we should do some dump() debugging on gitlab to make sure it's really hitting the URLs we think it is with that change.

alexpott’s picture

Ah I see why it did not work. The code was added in the wrong place. Fixed on the MR attached here. Let's see if something else then fails... this will be interesting.

catch’s picture

Well, that would explain it.

There is a theoretical risk that tests which previously passed on gitlab ci (and hadn't been run locally for ages) could have started failing with this if they were relying on the non-aliased URL being hit, but since zero core tests are, this is probably fine.

I guess remaining question is whether we look at allowing non-aliased requests per #6 here or open another follow-up for that.

I would also revert the performance test changes here since they may as well be consistent even if we can make them pass without it.

alexpott’s picture

Status: Active » Needs review

Opened a new branch for a test-only change because all the changes are in the test system so the magic test-only job doesn't work.

alexpott’s picture

smustgrave’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community
Issue tags: +Needs Review Queue Initiative

Updated issue summary slightly to include solution and which MR should be committed

The change of stripping the forward slash seems straight forward.

Test-only MR shows coverage

  • catch committed 14557fc7 on 10.3.x
    Issue #3440424 by alexpott: Inconsistent behaviour with drupalGet() when...

  • catch committed 39d743b8 on 11.x
    Issue #3440424 by alexpott: Inconsistent behaviour with drupalGet() when...
catch’s picture

Status: Reviewed & tested by the community » Fixed

I didn't do anything useful here so I think I can commit it.

Committed/pushed to 11.x and cherry-picked to 10.3.x, thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.