diff --git a/core/modules/comment/tests/src/Functional/Rest/CommentResourceTestBase.php b/core/modules/comment/tests/src/Functional/Rest/CommentResourceTestBase.php
index ac1a1b7ffb6b037a979674bb61b6aba464a2b48a..f404d0e49e603fda5f83f9dff16f9ec8405dbbc5 100644
--- a/core/modules/comment/tests/src/Functional/Rest/CommentResourceTestBase.php
+++ b/core/modules/comment/tests/src/Functional/Rest/CommentResourceTestBase.php
@@ -359,6 +359,9 @@ public function testPostSkipCommentApproval() {
     $this->assertResourceResponse(201, FALSE, $response);
     $this->assertFalse($unserialized->isPublished());
 
+    // Make sure the role save below properly invalidates cache tags.
+    $this->refreshVariables();
+
     // Grant anonymous permission to skip comment approval.
     $this->grantPermissionsToTestedRole(['skip comment approval']);
 
diff --git a/core/modules/media/tests/src/Functional/MediaOverviewPageTest.php b/core/modules/media/tests/src/Functional/MediaOverviewPageTest.php
index 1f272ee2392174e0537928a37210a3df4c29ff80..ac2bb016fa6a1940d84cfe230c778f4b3503ba4c 100644
--- a/core/modules/media/tests/src/Functional/MediaOverviewPageTest.php
+++ b/core/modules/media/tests/src/Functional/MediaOverviewPageTest.php
@@ -86,6 +86,9 @@ public function testMediaOverviewPage() {
     ]);
     $media3->save();
 
+    // Make sure the role save below properly invalidates cache tags.
+    $this->refreshVariables();
+
     // Verify the view is now correctly populated. The non-admin user can only
     // view published media.
     $this->grantPermissions($role, [
@@ -138,6 +141,9 @@ public function testMediaOverviewPage() {
     $assert_session->elementExists('css', 'td.views-field-operations li a:contains("Delete")', $row1);
     $assert_session->linkByHrefExists('/media/' . $media1->id() . '/delete');
 
+    // Make sure the role save below properly invalidates cache tags.
+    $this->refreshVariables();
+
     // Make the user the owner of the unpublished media item and assert the
     // media item is only visible with the 'view own unpublished media'
     // permission.
diff --git a/core/modules/media/tests/src/Functional/Rest/MediaResourceTestBase.php b/core/modules/media/tests/src/Functional/Rest/MediaResourceTestBase.php
index f34844aedd6c8574eff8f7887dfbb04d09a3c44b..b0d5c2087753c1783f122345b3414c90b9367bb3 100644
--- a/core/modules/media/tests/src/Functional/Rest/MediaResourceTestBase.php
+++ b/core/modules/media/tests/src/Functional/Rest/MediaResourceTestBase.php
@@ -375,6 +375,9 @@ protected function uploadFile() {
     static::recursiveKSort($actual);
     $this->assertSame($expected, $actual);
 
+    // Make sure the role save below properly invalidates cache tags.
+    $this->refreshVariables();
+
     // To still run the complete test coverage for POSTing a Media entity, we
     // must revoke the additional permissions that we granted.
     $role = Role::load(static::$auth ? RoleInterface::AUTHENTICATED_ID : RoleInterface::ANONYMOUS_ID);
diff --git a/core/modules/node/tests/src/Functional/Rest/NodeResourceTestBase.php b/core/modules/node/tests/src/Functional/Rest/NodeResourceTestBase.php
index 05ced94c98cd04cbe39ce95c5fda34d893440e9e..8f780ed07b439626f023deec663a9ee4137f8b15 100644
--- a/core/modules/node/tests/src/Functional/Rest/NodeResourceTestBase.php
+++ b/core/modules/node/tests/src/Functional/Rest/NodeResourceTestBase.php
@@ -255,6 +255,9 @@ public function testPatchPath() {
     $this->assertSame('/llama', $this->entityStorage->loadUnchanged($this->entity->id())->get('path')->alias);
     $this->assertResourceErrorResponse(403, "Access denied on updating field 'path'. " . static::$patchProtectedFieldNames['path'], $response);
 
+    // Make sure the role save below properly invalidates cache tags.
+    $this->refreshVariables();
+
     // Grant permission to create URL aliases.
     $this->grantPermissionsToTestedRole(['create url aliases']);