Skip Menu |

This queue is for tickets about the Test-Database CPAN distribution.

Report information
The Basics
Id: 40104
Status: resolved
Priority: 0/
Queue: Test-Database

People
Owner: Nobody in particular
Requestors: MLAWREN [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in:
  • 0.01
  • 0.02
Fixed in: (no value)



Subject: Use of File::Temp for temporary files and directories
Hi, One of my packages once received a bug referring to the use of temporary files with predictable names. http://rt.cpan.org/Public/Bug/Display.html?id=30019 which can apparently be bad news, particularly if tests are run as root. The suggestion was made to use File::Temp for a) creating non-predictable file names; and b) removing tempory files/directories on cleanup Could the same concerns and solution apply here? A secondary issue is this: what happens when a user runs multiple Test::Database tests on the same system. Is there a chance for over-writing and race conditions for /tmp/Test-Database/user/? I would also find it somewhat cleaner if a temporary files were created underneath the t/ directory, but I have no logic for that other than personal preference. Regards, Mark. -- Mark Lawrence
RT-Send-CC: book [...] cpan.org
On Thu Oct 16 13:34:01 2008, MLAWREN wrote: Show quoted text
> > One of my packages once received a bug referring to the use of temporary > files with predictable names. > > http://rt.cpan.org/Public/Bug/Display.html?id=30019 > > which can apparently be bad news, particularly if tests are run as root. > > The suggestion was made to use File::Temp for > > a) creating non-predictable file names; and > b) removing tempory files/directories on cleanup > > Could the same concerns and solution apply here?
The same concerns definitely apply here. Non predictable file names will prevent Test::Database to find back the database information that is created, and meant to be passed between tests scripts. So using File::Temp is definitely not an option. We could make the directory name less predictable by adding some random information taken on the local system. But I still have to make sure that Test::Database->base_dir() will always return the same value on a given system. However, removing the temporary files can be done with a Test::Database->cleanup() in the last test script. Show quoted text
> A secondary issue is this: what happens when a user runs multiple > Test::Database tests on the same system. Is there a chance for > over-writing and race conditions for /tmp/Test-Database/user/?
Yes, there is. Again, if we want to take advantage of databases nicely provided by the host owner, I don't see many ways to avoid this. Adding a locking scheme will not help much, if a script that expects the database to be left in a certain state by the previous test script is started some other script that just happened to be run at that time. Show quoted text
> I would also find it somewhat cleaner if a temporary files were created > underneath the t/ directory, but I have no logic for that other than > personal preference.
Yes, I understand. I would say we have several distinct use cases: 1) using databases provided by the host system (by way of env vars, configuration) 2) fully setting up the database in a local directory In case 1), we can't avoid race conditions and test scripts stepping on each other's toes. The gain is that we get many more available databases systems (e.g., I doubt I'll ever write a Test::Database::Oracle, but a CPAN test could provide the connection information to one). In case 2), we can do whatever we want, including having base_dir() point inside of t/ and do its stuff there. I also see a case 1 1/2, where the database information we are given comes with full administrative rights on the database, which allows us to create and drop databases. In that case, we can effectively ensure we have our own private database, and that any new database that will be created will have a different name. What do you think? -- BooK
Subject: Re: [rt.cpan.org #40104] Use of File::Temp for temporary files and directories
Date: Sat, 18 Oct 2008 00:40:09 +0200
To: Philippe 'BooK' Bruhat via RT <bug-Test-Database [...] rt.cpan.org>
From: Mark Lawrence <nomad [...] null.net>
Show quoted text
> I would say we have several distinct use cases: > 1) using databases provided by the host system > (by way of env vars, configuration) > 2) fully setting up the database in a local directory > > In case 1), we can't avoid race conditions and test scripts stepping on > each other's toes. The gain is that we get many more available databases > systems (e.g., I doubt I'll ever write a Test::Database::Oracle, but a > CPAN test could provide the connection information to one).
That is something I think we could live with if it is documented. However, what is there to stop Test::Database from specifying an advisory lock in say /var/lock || /var/run || /tmp/test-database.lck? Show quoted text
> In case 2), we can do whatever we want, including having base_dir() > point inside of t/ and do its stuff there.
Agreed. Show quoted text
> I also see a case 1 1/2, where the database information we are given > comes with full administrative rights on the database, which allows us > to create and drop databases. In that case, we can effectively ensure > we have our own private database, and that any new database that will > be created will have a different name. > > What do you think?
I think case 1.5 is probably more trouble than it is worth. If the database is persistent between cleanup() calls, what is the use case for named databases? A module that needs to run tests against multiple databases (of the same type) simultaneously? Perhaps a method for dynamically defining test databases would work for file-based: use Test::Database; Test::Database->define( name => 'SQLite2', driver => 'SQLite', ); my $d1 = Test::Database->drivers('SQLite'); my $d2 = Test::Database->drivers('SQLite2'); Or here is another approach. The first call to drivers('SQLite') uses t/Test-Database/SQLite0/. The second uses t/Test-Database/SQLite1/ and so on... However I think it would get messy for the other types. Creating could require all kinds of external scripts and calling conventions. And then there is the cleanup factor to think about. When the tester removes the source directory his system is clean of file-based. However for modules where the author has gone and created all kinds of junk in someones database daemon, and not called cleanup()/dropdb() in the last test (maybe the tests die before they finish...) then that stuff will hang around forever. To be honest, I would not attempt to deal with multiple/named databases until someone steps forward who actually needs such functionality. Cheers, Mark. -- Mark Lawrence