Fix problems with the nth_value() function.
[sqlite.git] / test / manydb.test
blob974a5b8ebe7b8faee295e41f71f678382e8c5d3c
1 # 2005 October 3
3 # The author disclaims copyright to this source code.  In place of
4 # a legal notice, here is a blessing:
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.
10 #***********************************************************************
11 # This file implements regression tests for SQLite library.
13 # This file implements tests the ability of the library to open
14 # many different databases at the same time without leaking memory.
16 # $Id: manydb.test,v 1.4 2008/11/21 00:10:35 aswift Exp $
18 set testdir [file dirname $argv0]
19 source $testdir/tester.tcl
21 set N 300
22 # if we're using proxy locks, we use 5 filedescriptors for a db
23 # that is open and in the middle of writing changes, normally
24 # sqlite uses 3 (proxy locking adds the conch and the local lock)
25 set using_proxy 0
26 foreach {name value} [array get env SQLITE_FORCE_PROXY_LOCKING] {
27   set using_proxy value
29 set num_fd_per_openwrite_db 3
30 if {$using_proxy>0} {
31   set num_fd_per_openwrite_db 5
32
34 # First test how many file descriptors are available for use. To open a
35 # database for writing SQLite requires 3 file descriptors (the database, the
36 # journal and the directory).
37 set filehandles {}
38 catch {
39   for {set i 0} {$i<($N * 3)} {incr i} {
40     lappend filehandles [open testfile.1 w]
41   }
43 foreach fd $filehandles {
44   close $fd
46 catch {
47   forcedelete testfile.1
49 set N [expr $i / $num_fd_per_openwrite_db]
51 # Create a bunch of random database names
53 unset -nocomplain dbname
54 unset -nocomplain used
55 for {set i 0} {$i<$N} {incr i} {
56   while 1 {
57     set name test-[format %08x [expr {int(rand()*0x7fffffff)}]].db
58     if {[info exists used($name)]} continue
59     set dbname($i) $name
60     set used($name) $i
61     break
62   }
65 # Create a bunch of databases
67 for {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$i
75   } {}
78 # Finish the transactions
80 for {set i 0} {$i<$N} {incr i} {
81   do_test manydb-2.$i {
82     execsql {
83        COMMIT;
84        SELECT * FROM t1;
85     } db$i
86   } {1 2}
90 # Close the databases and erase the files.
92 for {set i 0} {$i<$N} {incr i} {
93   do_test manydb-3.$i {
94     db$i close
95     forcedelete $dbname($i)
96   } {}
102 finish_test