Closed Bug 1745427 Opened 3 years ago Closed 3 years ago

Investigate why `PathUtils.getTempDir()` can fail in tests

Categories

(Toolkit Graveyard :: OS.File, defect, P2)

Tracking

(firefox98 fixed)

RESOLVED FIXED
98 Branch
Tracking Status
firefox98 --- fixed

People

(Reporter: standard8, Assigned: beth)

References

Details

Attachments

(1 file)

In working on bug 1733540, we initially tried using await PathUtils.getTempDir() for getting the temp directory:

https://phabricator.services.mozilla.com/D128168#inline-710625

That failed in test_system_update_custom.js with the call being rejected with NS_ERROR_FAILURE.

Using Services.dirsvc.get("TmpD", Ci.nsIFile).path the test worked fine.

PathUtils.getTempDir can fail in tests only if there is no profile directory. When we ask for the temp dir, PathUtils will eagerly fetch TmpD, ProfD, and ProfLD from the directory service. If any of the fetches fail, we end up returning an error.

Assignee: nobody → brennie
Blocks: 1746675

It is also failing because getTempDir() returns NS_APP_CONTENT_PROCESS_TEMP_DIR, which will be "ContentTmpD" instead of "TmpD" in tests.

Type: task → defect
See Also: → 1733540

The severity field is not set for this bug.
:barret, could you have a look please?

For more information, please visit auto_nag documentation.

Flags: needinfo?(brennie)
Severity: -- → S3
Flags: needinfo?(brennie)
Priority: -- → P2

PathUtils.getTempDir() was failing in xpcshell tests for two reasons:

  1. It was requesting NS_APP_CONTENT_PROCESS_TEMP_DIR, which resolves to
    ContentTmpD, which the directory provider did not have an entry for.
  2. By default, XPC shell tests do not have a profile set up, so when we request
    the temporary directory and eagerly fetch the profile directory, we would fail.

We now only fetch the entry for the single directory that is requested to work
around these edge cases in tests and getTempDir() resolves to TmpD instead.

We now provide a getContentTempDir() method on PathUtils for consumers that
want the old behaviour.

To accomplish this, we now have PathUtils.dirs.h, which defines the various
directory entries that we want to cache and PathUtils now generates code via
macros to implement the relevant methods. This allows us to add additional
directories to PathUtils by adding an entry to PathUtils.dirs.h and a
matching method in PathUtils.webidl.

No longer blocks: 1746675
Pushed by brennie@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/9743e5209921 Do not eagerly fetch non-requested directories in PathUtils r=nika

Backed out changeset 9743e5209921 (bug 1745427) for causing mochitest failures in dom/system/tests/test_pathutils.html

Backout link: https://hg.mozilla.org/integration/autoland/rev/1533aeb19090150db14738d3eae2d9adb06a287b

Push with failures

Failure log

TEST-UNEXPECTED-FAIL | dom/system/tests/test_pathutils.html | [Exception... "Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [nsIProperties.get]"  nsresult: "0x80004005 (NS_ERROR_FAILURE)"  location: "JS frame :: chrome://mochitests/content/chrome/dom/system/tests/test_pathutils.html :: test_getDirectories :: line 414"  data: no] - Should not throw any errors
[task 2022-01-22T01:53:48.805Z] 01:53:48 test_getDirectories@chrome://mochitests/content/chrome/dom/system/tests/test_pathutils.html:414:23
Flags: needinfo?(brennie)
Flags: needinfo?(brennie)
Pushed by brennie@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/c1b506c204a4 Do not eagerly fetch non-requested directories in PathUtils r=nika
Status: NEW → RESOLVED
Closed: 3 years ago
Resolution: --- → FIXED
Target Milestone: --- → 98 Branch
Blocks: 1746667
Product: Toolkit → Toolkit Graveyard
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: