AryaWu/sqlite
0
1# 2005 October 32#3# The author disclaims copyright to this source code. In place of4# a legal notice, here is a blessing:5#6# May you do good and not evil.7# May you find forgiveness for yourself and forgive others.8# May you share freely, never taking more than you give.9#10#***********************************************************************11# This file implements regression tests for SQLite library.12#13# This file implements tests the ability of the library to open14# many different databases at the same time without leaking memory.15#16# $Id: manydb.test,v 1.4 2008/11/21 00:10:35 aswift Exp $17 18set testdir [file dirname $argv0]19source $testdir/tester.tcl20 21set N 30022# if we're using proxy locks, we use 5 filedescriptors for a db23# that is open and in the middle of writing changes, normally24# sqlite uses 3 (proxy locking adds the conch and the local lock)25set using_proxy 026foreach {name value} [array get env SQLITE_FORCE_PROXY_LOCKING] {27 set using_proxy value28}29set num_fd_per_openwrite_db 330if {$using_proxy>0} {31 set num_fd_per_openwrite_db 532} 33 34# First test how many file descriptors are available for use. To open a35# database for writing SQLite requires 3 file descriptors (the database, the36# journal and the directory).37set filehandles {}38catch {39 for {set i 0} {$i<($N * 3)} {incr i} {40 lappend filehandles [open testfile.1 w]41 }42}43foreach fd $filehandles {44 close $fd45}46catch {47 forcedelete testfile.148}49set N [expr $i / $num_fd_per_openwrite_db]50 51# Create a bunch of random database names52#53unset -nocomplain dbname54unset -nocomplain used55for {set i 0} {$i<$N} {incr i} {56 while 1 {57 set name test-[format %08x [expr {int(rand()*0x7fffffff)}]].db58 if {[info exists used($name)]} continue59 set dbname($i) $name60 set used($name) $i61 break62 }63}64 65# Create a bunch of databases66#67for {set i 0} {$i<$N} {incr i} {68 do_test manydb-1.$i {69 sqlite3 db$i $dbname($i)70 execsql {71 CREATE TABLE t1(a,b);72 BEGIN;73 INSERT INTO t1 VALUES(1,2);74 } db$i75 } {}76}77 78# Finish the transactions79#80for {set i 0} {$i<$N} {incr i} {81 do_test manydb-2.$i {82 execsql {83 COMMIT;84 SELECT * FROM t1;85 } db$i86 } {1 2}87}88 89 90# Close the databases and erase the files.91#92for {set i 0} {$i<$N} {incr i} {93 do_test manydb-3.$i {94 db$i close95 forcedelete $dbname($i)96 } {}97}98 99 100 101 102finish_test103 