Creating temporary files in tests

1,261 views
Skip to first unread message

Chris Bentzel

unread,
Oct 21, 2010, 10:30:04 AM10/21/10
to chromium-dev
I'd like to create a temporary file for a unit test. It looks like I can use a combination of CreateAndOpenTemporaryFile, ScopedFILEClose, and Delete to create and clean up the file.

My concern is that if the test becomes flaky or early exits, then the system temp directory will get clogged with temporary files. Are there other tests which work around this?

[As background, I'm trying to make RedirectTest.ClientEmptyReferer work with a non-fixed-port TestServer. The test wants to validate that a redirect from a file:// URL does not add a Referer header. I can't think of a way to avoid the need for a file in this case.]

Thomas Van Lenten

unread,
Oct 21, 2010, 10:47:39 AM10/21/10
to cben...@chromium.org, chromium-dev
We added some code to the test runners that nukes the temp profiles, etc. that get created if a test crashes.  If you are getting things named in the same ways, they will get cleaned up.  Peek at the studio on some of the test on bots and you might find instances of it cleaning up.

TVL
 

--
Chromium Developers mailing list: chromi...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-dev

Paweł Hajdan, Jr.

unread,
Oct 21, 2010, 10:48:02 AM10/21/10
to cben...@chromium.org, chromium-dev
Just use ScopedTempDir. If there is a crash, you can't do much about it. However, "regular" test failures should be handled properly.

--
Reply all
Reply to author
Forward
0 new messages