Bug 1799717: Adding a try/catch block in the test to exempt some known possible failures.r=jari

Differential Revision: https://phabricator.services.mozilla.com/D210174
This commit is contained in:
Harveer Singh 2024-05-13 21:07:26 +00:00
parent 53feb735aa
commit 0d04df1c2a

View file

@ -3,6 +3,7 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/. # file, You can obtain one at http://mozilla.org/MPL/2.0/.
import os import os
import time
from marionette_driver import Wait from marionette_driver import Wait
from marionette_harness import MarionetteTestCase from marionette_harness import MarionetteTestCase
@ -77,19 +78,15 @@ class CachesDeleteCleanupAtShutdownTestCase(MarionetteTestCase):
script_args=(CACHE_ID,), script_args=(CACHE_ID,),
) )
def countBodies(self): # asynchronously iterating over body files could be challenging as firefox
profile = self.marionette.instance.profile.profile # might be doing some cleanup while we are iterating over it's morgue dir.
originDir = ( # It's expected for this helper to throw FileNotFoundError exception in
self.marionette.absolute_url("")[:-1].replace(":", "+").replace("/", "+") # such cases.
) def fallibleCountBodies(self, morgueDir):
morgueDir = f"{profile}/storage/default/{originDir}/cache/morgue"
print("morgueDir path = ", morgueDir)
bodyCount = -1
if os.path.exists(morgueDir):
bodyCount = 0 bodyCount = 0
for elem in os.listdir(morgueDir): for elem in os.listdir(morgueDir):
absPathElem = os.path.join(morgueDir, elem) absPathElem = os.path.join(morgueDir, elem)
if os.path.isdir(absPathElem): if os.path.isdir(absPathElem):
bodyCount += sum( bodyCount += sum(
1 1
@ -98,6 +95,27 @@ class CachesDeleteCleanupAtShutdownTestCase(MarionetteTestCase):
) )
return bodyCount return bodyCount
def countBodies(self):
profile = self.marionette.instance.profile.profile
originDir = (
self.marionette.absolute_url("")[:-1].replace(":", "+").replace("/", "+")
)
morgueDir = f"{profile}/storage/default/{originDir}/cache/morgue"
print("morgueDir path = ", morgueDir)
if not os.path.exists(morgueDir):
print("morgue directory does not exists.")
return -1
while True:
try:
return self.fallibleCountBodies(morgueDir)
except FileNotFoundError:
# we probably just got in the period when firefox was cleaning up.
# retry...
time.sleep(0.5)
def ensureCleanDirectory(self): def ensureCleanDirectory(self):
orphanedBodiesCount = self.countBodies() orphanedBodiesCount = self.countBodies()
return orphanedBodiesCount <= 0 return orphanedBodiesCount <= 0