Closed
Bug 892021
Opened 11 years ago
Closed 11 years ago
add a do_get_tempdir function to head.js
Categories
(Testing :: XPCShell Harness, defect)
Testing
XPCShell Harness
Tracking
(Not tracked)
RESOLVED
FIXED
mozilla25
People
(Reporter: mihneadb, Assigned: mihneadb)
References
Details
Attachments
(1 file, 10 obsolete files)
14.24 KB,
patch
|
mihneadb
:
review+
|
Details | Diff | Splinter Review |
Currently when an xpcshell test wants to use a temp dir, it uses the system global one (i.e. /tmp on UNIX). This is not desired when running the tests concurrently.
There should be a do_get_tempdir function in head.js that returns the path of the profile dir (since every test gets one), without actually setting up the profile.
Assignee | ||
Comment 1•11 years ago
|
||
Attachment #773459 -
Flags: review?(ted)
Assignee | ||
Updated•11 years ago
|
Assignee: nobody → mihneadb
Comment 2•11 years ago
|
||
Comment on attachment 773459 [details] [diff] [review]
add a do_get_tempdir function to head.js
Review of attachment 773459 [details] [diff] [review]:
-----------------------------------------------------------------
There are two use cases for retrieving a temp directory: 1) get the global temporary directory (as implemented) 2) get a new, empty temp directory on every call.
I think #2 is more useful and what tests would make better use of. Can we have the function maintain a counter and create and return a new directory on every invocation?
Comment 3•11 years ago
|
||
Note that this is not strictly global, this is the temp directory that the Python harness creates. This will be unique per-invocation of xpcshell. I don't think there's much value in making additional temp directories on top of that. Tests can create subdirs if need be.
Comment 4•11 years ago
|
||
why would you want a different temp dir at each invokation, most of the services won't need such thing, they will just use TmpD, that is one, and if they need a new temp folder they can just create new ones inside the dir they get from this method.
Assignee | ||
Comment 5•11 years ago
|
||
(In reply to Gregory Szorc [:gps] from comment #2)
> Comment on attachment 773459 [details] [diff] [review]
> add a do_get_tempdir function to head.js
>
> Review of attachment 773459 [details] [diff] [review]:
> -----------------------------------------------------------------
>
> There are two use cases for retrieving a temp directory: 1) get the global
> temporary directory (as implemented) 2) get a new, empty temp directory on
> every call.
>
> I think #2 is more useful and what tests would make better use of. Can we
> have the function maintain a counter and create and return a new directory
> on every invocation?
The problem that I see with #2 is that you might want to use that temp dir in multiple places - like set something up in the head file and then use that temp dir in a test. Sure, you could use a global var but from what I saw while fixing tests a global might not be enough.
Comment 6•11 years ago
|
||
You've all convinced me. Can we at least get a fresh temporary directory instead of sharing it with the profile root directory?
Comment 7•11 years ago
|
||
I actually suggested to create a uniquely named folder in TmpD, not to reuse the profile dir.
Comment 8•11 years ago
|
||
Alternate suggestion: we create /{profile,tmp} subdirs under the directory that Python creates, and hand one out from do_get_tmp and the other for do_get_profile?
Comment 9•11 years ago
|
||
whatever, I just thought was easy to use nsIFile.createUnique with a recognizable name like xpcshell-temp-dir or such. But I suppose having it in the python dir may end up into a faster cleanup of the trash put into it.
Comment 10•11 years ago
|
||
(In reply to Marco Bonardo [:mak] from comment #7)
> I actually suggested to create a uniquely named folder in TmpD, not to reuse
> the profile dir.
We want things under the temp directory created by Python so it will always be cleaned up. Otherwise, tests could modify the filesystem outside of the "sandbox" and those changes would linger forever.
Of course, tests could bypass this protection today if they wanted. We'd ideally execute things inside chroots or something. But that's for another bug.
Comment 11•11 years ago
|
||
it's a very good reason, go for it!
Assignee | ||
Comment 12•11 years ago
|
||
I'm not sure if I should handle cleaning the tempdir differently.
Attachment #773557 -
Flags: review?(ted)
Assignee | ||
Updated•11 years ago
|
Attachment #773459 -
Attachment is obsolete: true
Attachment #773459 -
Flags: review?(ted)
Comment 13•11 years ago
|
||
Comment on attachment 773557 [details] [diff] [review]
create the tempdir in the harness and use it from head.js
Review of attachment 773557 [details] [diff] [review]:
-----------------------------------------------------------------
::: testing/xpcshell/head.js
@@ +931,5 @@
> + let file = Components.classes["@mozilla.org/file/local;1"]
> + .createInstance(Components.interfaces.nsILocalFile);
> + file.initWithPath(profd);
> + return file;
> +}
Can you add a test for this somewhere in testing/xpcshell/example/unit? It can be simple, just do_get_tempdir and assert that it exists and that you can write a file under it.
::: testing/xpcshell/runxpcshelltests.py
@@ +316,5 @@
> + tempDir = mkdtemp()
> + self.env["XPCSHELL_TEST_TEMP_DIR"] = tempDir
> + if self.interactive:
> + self.log.info("TEST-INFO | temp dir is %s" % tempDir)
> + return tempDir
This is going to need an equivalent change in remotexpcshelltests.py so as not to break Android tests. You should be able to mostly just copy the setupProfileDir code there.
@@ +1046,5 @@
>
> + try:
> + self.removeDir(self.tempDir)
> + except Exception:
> + self.log.warning("TEST-INFO | %s | Failed to clean up the test temp directory (%s)." % (name, self.profileDir))
It might make sense to refactor the "try again if removing the directory fails" logic from above into a function so we can use it for both the profile dir and the temp dir, but we can punt that to the future if it becomes a problem.
Attachment #773557 -
Flags: review?(ted) → review+
Assignee | ||
Comment 14•11 years ago
|
||
Attachment #774162 -
Flags: review?(ted)
Assignee | ||
Comment 15•11 years ago
|
||
(In reply to Ted Mielczarek [:ted.mielczarek] from comment #13)
> Comment on attachment 773557 [details] [diff] [review]
> create the tempdir in the harness and use it from head.js
>
> ::: testing/xpcshell/runxpcshelltests.py
> @@ +316,5 @@
> > + tempDir = mkdtemp()
> > + self.env["XPCSHELL_TEST_TEMP_DIR"] = tempDir
> > + if self.interactive:
> > + self.log.info("TEST-INFO | temp dir is %s" % tempDir)
> > + return tempDir
>
> This is going to need an equivalent change in remotexpcshelltests.py so as
> not to break Android tests. You should be able to mostly just copy the
> setupProfileDir code there.
This is not trivial because we don't have an equivalent "mkdtemp" in devicemanager. We only have getTempDir which returns the equivalent of "/tmp" on the device.
A "good enough" (for now!) solution would be to assume that there's only one connection at a time to the device and use mkdtemp locally (on the PC) and push that dir (dir name) to the device's getTempDir() directory.
This will not work properly when multiple PCs will control the same devices, but for just one it should work just fine.
What do you think?
Flags: needinfo?(gbrown)
Assignee | ||
Comment 16•11 years ago
|
||
Refactored the try-delete logic in a function.
Attachment #774263 -
Flags: review?(ted)
Assignee | ||
Updated•11 years ago
|
Attachment #773557 -
Attachment is obsolete: true
Comment 17•11 years ago
|
||
remotexpcshelltests.py already has a notion of a simple temp dir: see references to TMPDIR and remoteTmpDir.
I would be tempted to simply override setupTempDir in remotexpcshelltests.py:
def setupTempDir(self):
self.env["XPCSHELL_TEST_TEMP_DIR"] = self.remoteTmpDir
return self.remoteTmpDir
That does not address any concurrency concerns of course. If we want/need multiple unique temp dirs on the device, I suspect there's no easy to do that.
Flags: needinfo?(gbrown)
Assignee | ||
Comment 18•11 years ago
|
||
Attachment #774714 -
Flags: review?(gbrown)
Comment 19•11 years ago
|
||
Comment on attachment 774162 [details] [diff] [review]
simple test file
Review of attachment 774162 [details] [diff] [review]:
-----------------------------------------------------------------
Thanks!
::: testing/xpcshell/example/unit/test_do_get_tempdir.js
@@ +1,5 @@
> +/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
> +/* vim:set ts=2 sw=2 sts=2 et: */
> +/* This Source Code Form is subject to the terms of the Mozilla Public
> + * License, v. 2.0. If a copy of the MPL was not distributed with this
> + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
Note that you can license test files as public domain if you so choose (I usually do):
http://www.mozilla.org/MPL/headers/
@@ +14,5 @@
> + tmpd.append("testfile");
> + tmpd.create(Ci.nsIFile.NORMAL_FILE_TYPE, 600);
> + do_check_true(tmpd.exists());
> + tmpd.remove(false);
> + do_check_false(tmpd.exists());
Remove these last two lines, the Python harness cleans up the temp directory, so there's no need for this test.
Attachment #774162 -
Flags: review?(ted) → review+
Comment 20•11 years ago
|
||
Comment on attachment 774263 [details] [diff] [review]
tempdir
Review of attachment 774263 [details] [diff] [review]:
-----------------------------------------------------------------
::: testing/xpcshell/head.js
@@ +918,5 @@
> }
>
> /**
> + * Returns the directory for a temp dir, which uses the path
> + * of the profile dir, since every test gets its own.
This comment is no longer correct, since you're creating a different temp dir.
@@ +926,5 @@
> +function do_get_tempdir() {
> + let env = Components.classes["@mozilla.org/process/environment;1"]
> + .getService(Components.interfaces.nsIEnvironment);
> + // the python harness sets this in the environment for us
> + let profd = env.get("XPCSHELL_TEST_TEMP_DIR");
It's a little odd to call this variable "profd" in this function.
Attachment #774263 -
Flags: review?(ted) → review-
Comment 21•11 years ago
|
||
It seems fine to not deal with concurrency in the remote harness for now, as long as we document that and enforce it in the code. If we change our minds in the future we can sort it out then.
Assignee | ||
Comment 22•11 years ago
|
||
Assignee | ||
Updated•11 years ago
|
Attachment #774162 -
Attachment is obsolete: true
Assignee | ||
Comment 23•11 years ago
|
||
Comment on attachment 774927 [details] [diff] [review]
simple test file
keeping r+
Attachment #774927 -
Flags: review+
Assignee | ||
Updated•11 years ago
|
Attachment #774263 -
Attachment is obsolete: true
Comment 25•11 years ago
|
||
Comment on attachment 774940 [details] [diff] [review]
tempdir
Review of attachment 774940 [details] [diff] [review]:
-----------------------------------------------------------------
::: testing/xpcshell/runxpcshelltests.py
@@ +853,5 @@
> + except Exception:
> + message = "TEST-UNEXPECTED-FAIL | %s | Failed to clean up directory: %s" % (name, sys.exc_info()[1])
> + self.log.error(message)
> + print_stdout(stdout)
> + print_stdout(traceback.format_exc())
This fails for me. I think you need self.print_stdout(...)
Assignee | ||
Comment 26•11 years ago
|
||
(In reply to Geoff Brown [:gbrown] from comment #25)
> Comment on attachment 774940 [details] [diff] [review]
> tempdir
>
> Review of attachment 774940 [details] [diff] [review]:
> -----------------------------------------------------------------
>
> ::: testing/xpcshell/runxpcshelltests.py
> @@ +853,5 @@
> > + except Exception:
> > + message = "TEST-UNEXPECTED-FAIL | %s | Failed to clean up directory: %s" % (name, sys.exc_info()[1])
> > + self.log.error(message)
> > + print_stdout(stdout)
> > + print_stdout(traceback.format_exc())
>
> This fails for me. I think you need self.print_stdout(...)
Whoops, absolutely! I didn't encounter a failing test while.. testing.
Assignee | ||
Comment 27•11 years ago
|
||
s/print_stdout/self.print_stdout
Attachment #774944 -
Flags: review?(ted)
Assignee | ||
Updated•11 years ago
|
Attachment #774940 -
Attachment is obsolete: true
Attachment #774940 -
Flags: review?(ted)
Updated•11 years ago
|
Attachment #774714 -
Flags: review?(gbrown) → review+
Updated•11 years ago
|
Attachment #774944 -
Flags: review?(ted) → review+
Assignee | ||
Comment 28•11 years ago
|
||
Assignee | ||
Comment 29•11 years ago
|
||
(In reply to Mihnea Dobrescu-Balaur (:mihneadb) from comment #28)
> try run: https://tbpl.mozilla.org/?tree=Try&rev=95bebff7fc58
I'm confused about the failure on Android. According to the docs on initWithFilePath, NS_ERROR_FILE_UNRECOGNIZED_PATH means that the given path is not absolute.
Could it be that the tmpDirPath is too long to fit in the env var or something like that? Although, this does not explain why it only happened once.
Flags: needinfo?(gbrown)
Assignee | ||
Comment 30•11 years ago
|
||
Via some debug print statements I found that after || let path = env.get("XPCSHELL_TEST_TEMP_DIR"); ||, path is the empty string. (Or undefined)
Comment 31•11 years ago
|
||
At issue is the timing of setting the env. The remote xpcshell picks up its environment from the "wrapper script", which is pushed once at setup time. This patch modifies the env after the wrapper script has been created and pushed to the device.
Simple fix: call setupTempDir from buildEnvironment, before the call to pushWrapper. (This can be in addition to the existing call of setupTempDir in runTest, if you wish.)
Flags: needinfo?(gbrown)
Assignee | ||
Comment 32•11 years ago
|
||
Calling setuptempdir() in buildenv now.
Attachment #775783 -
Flags: review?(gbrown)
Assignee | ||
Updated•11 years ago
|
Attachment #774714 -
Attachment is obsolete: true
Assignee | ||
Comment 33•11 years ago
|
||
https://tbpl.mozilla.org/?tree=Try&rev=ad1bbcc4b0b1
^ new try run.
Comment 34•11 years ago
|
||
This *looks* right but keeps failing. Is the per-test cleanup deleting the remote tmp dir? (I think the remote tmp dir is only created once.)
Assignee | ||
Comment 35•11 years ago
|
||
Yes, it does. Not sure how to address this.
Assignee | ||
Comment 36•11 years ago
|
||
Making sure the directory exists now.
Attachment #776022 -
Flags: review?(gbrown)
Assignee | ||
Updated•11 years ago
|
Attachment #775783 -
Attachment is obsolete: true
Attachment #775783 -
Flags: review?(gbrown)
Assignee | ||
Comment 37•11 years ago
|
||
Finally try is open, here's the new run - https://tbpl.mozilla.org/?tree=Try&rev=2c1e35691626
Updated•11 years ago
|
Attachment #776022 -
Flags: review?(gbrown) → review+
Assignee | ||
Updated•11 years ago
|
Keywords: checkin-needed
Comment 38•11 years ago
|
||
Can you fold all three of these patches together for landing? They should really land as one changeset.
Keywords: checkin-needed
Assignee | ||
Comment 39•11 years ago
|
||
Assignee | ||
Updated•11 years ago
|
Attachment #774944 -
Attachment is obsolete: true
Assignee | ||
Updated•11 years ago
|
Attachment #774927 -
Attachment is obsolete: true
Assignee | ||
Updated•11 years ago
|
Attachment #776022 -
Attachment is obsolete: true
Assignee | ||
Comment 40•11 years ago
|
||
Comment on attachment 776470 [details] [diff] [review]
squashed patch
squashing r+'s from :ted and :gbrown
Attachment #776470 -
Flags: review+
Assignee | ||
Updated•11 years ago
|
Keywords: checkin-needed
Comment 41•11 years ago
|
||
Flags: in-testsuite+
Keywords: checkin-needed
Status: NEW → RESOLVED
Closed: 11 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla25
You need to log in
before you can comment on or make changes to this bug.
Description
•