sl@0: # 2005 October 3 sl@0: # sl@0: # The author disclaims copyright to this source code. In place of sl@0: # a legal notice, here is a blessing: sl@0: # sl@0: # May you do good and not evil. sl@0: # May you find forgiveness for yourself and forgive others. sl@0: # May you share freely, never taking more than you give. sl@0: # sl@0: #*********************************************************************** sl@0: # This file implements regression tests for SQLite library. sl@0: # sl@0: # This file implements tests the ability of the library to open sl@0: # many different databases at the same time without leaking memory. sl@0: # sl@0: # $Id: manydb.test,v 1.3 2006/01/11 01:08:34 drh Exp $ sl@0: sl@0: set testdir [file dirname $argv0] sl@0: source $testdir/tester.tcl sl@0: sl@0: set N 300 sl@0: sl@0: # First test how many file descriptors are available for use. To open a sl@0: # database for writing SQLite requires 3 file descriptors (the database, the sl@0: # journal and the directory). sl@0: set filehandles {} sl@0: catch { sl@0: for {set i 0} {$i<($N * 3)} {incr i} { sl@0: lappend filehandles [open testfile.1 w] sl@0: } sl@0: } sl@0: foreach fd $filehandles { sl@0: close $fd sl@0: } sl@0: catch { sl@0: file delete -force testfile.1 sl@0: } sl@0: set N [expr $i / 3] sl@0: sl@0: # Create a bunch of random database names sl@0: # sl@0: unset -nocomplain dbname sl@0: unset -nocomplain used sl@0: for {set i 0} {$i<$N} {incr i} { sl@0: while 1 { sl@0: set name test-[format %08x [expr {int(rand()*0x7fffffff)}]].db sl@0: if {[info exists used($name)]} continue sl@0: set dbname($i) $name sl@0: set used($name) $i sl@0: break sl@0: } sl@0: } sl@0: sl@0: # Create a bunch of databases sl@0: # sl@0: for {set i 0} {$i<$N} {incr i} { sl@0: do_test manydb-1.$i { sl@0: sqlite3 db$i $dbname($i) sl@0: execsql { sl@0: CREATE TABLE t1(a,b); sl@0: BEGIN; sl@0: INSERT INTO t1 VALUES(1,2); sl@0: } db$i sl@0: } {} sl@0: } sl@0: sl@0: # Finish the transactions sl@0: # sl@0: for {set i 0} {$i<$N} {incr i} { sl@0: do_test manydb-2.$i { sl@0: execsql { sl@0: COMMIT; sl@0: SELECT * FROM t1; sl@0: } db$i sl@0: } {1 2} sl@0: } sl@0: sl@0: sl@0: # Close the databases and erase the files. sl@0: # sl@0: for {set i 0} {$i<$N} {incr i} { sl@0: do_test manydb-3.$i { sl@0: db$i close sl@0: file delete -force $dbname($i) sl@0: } {} sl@0: } sl@0: sl@0: sl@0: sl@0: sl@0: finish_test