forked from mirrors/gecko-dev
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:
parent
53feb735aa
commit
0d04df1c2a
1 changed files with 30 additions and 12 deletions
|
|
@ -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,26 +78,43 @@ class CachesDeleteCleanupAtShutdownTestCase(MarionetteTestCase):
|
||||||
script_args=(CACHE_ID,),
|
script_args=(CACHE_ID,),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# asynchronously iterating over body files could be challenging as firefox
|
||||||
|
# might be doing some cleanup while we are iterating over it's morgue dir.
|
||||||
|
# It's expected for this helper to throw FileNotFoundError exception in
|
||||||
|
# such cases.
|
||||||
|
def fallibleCountBodies(self, morgueDir):
|
||||||
|
bodyCount = 0
|
||||||
|
for elem in os.listdir(morgueDir):
|
||||||
|
absPathElem = os.path.join(morgueDir, elem)
|
||||||
|
|
||||||
|
if os.path.isdir(absPathElem):
|
||||||
|
bodyCount += sum(
|
||||||
|
1
|
||||||
|
for e in os.listdir(absPathElem)
|
||||||
|
if os.path.isfile(os.path.join(absPathElem, e))
|
||||||
|
)
|
||||||
|
return bodyCount
|
||||||
|
|
||||||
def countBodies(self):
|
def countBodies(self):
|
||||||
profile = self.marionette.instance.profile.profile
|
profile = self.marionette.instance.profile.profile
|
||||||
originDir = (
|
originDir = (
|
||||||
self.marionette.absolute_url("")[:-1].replace(":", "+").replace("/", "+")
|
self.marionette.absolute_url("")[:-1].replace(":", "+").replace("/", "+")
|
||||||
)
|
)
|
||||||
|
|
||||||
morgueDir = f"{profile}/storage/default/{originDir}/cache/morgue"
|
morgueDir = f"{profile}/storage/default/{originDir}/cache/morgue"
|
||||||
print("morgueDir path = ", morgueDir)
|
print("morgueDir path = ", morgueDir)
|
||||||
|
|
||||||
bodyCount = -1
|
if not os.path.exists(morgueDir):
|
||||||
if os.path.exists(morgueDir):
|
print("morgue directory does not exists.")
|
||||||
bodyCount = 0
|
return -1
|
||||||
for elem in os.listdir(morgueDir):
|
|
||||||
absPathElem = os.path.join(morgueDir, elem)
|
while True:
|
||||||
if os.path.isdir(absPathElem):
|
try:
|
||||||
bodyCount += sum(
|
return self.fallibleCountBodies(morgueDir)
|
||||||
1
|
except FileNotFoundError:
|
||||||
for e in os.listdir(absPathElem)
|
# we probably just got in the period when firefox was cleaning up.
|
||||||
if os.path.isfile(os.path.join(absPathElem, e))
|
# retry...
|
||||||
)
|
time.sleep(0.5)
|
||||||
return bodyCount
|
|
||||||
|
|
||||||
def ensureCleanDirectory(self):
|
def ensureCleanDirectory(self):
|
||||||
orphanedBodiesCount = self.countBodies()
|
orphanedBodiesCount = self.countBodies()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue