author | sl@SLION-WIN7.fritz.box |
Fri, 15 Jun 2012 03:10:57 +0200 | |
changeset 0 | bde4ae8d615e |
permissions | -rw-r--r-- |
sl@0 | 1 |
# 2005 October 3 |
sl@0 | 2 |
# |
sl@0 | 3 |
# The author disclaims copyright to this source code. In place of |
sl@0 | 4 |
# a legal notice, here is a blessing: |
sl@0 | 5 |
# |
sl@0 | 6 |
# May you do good and not evil. |
sl@0 | 7 |
# May you find forgiveness for yourself and forgive others. |
sl@0 | 8 |
# May you share freely, never taking more than you give. |
sl@0 | 9 |
# |
sl@0 | 10 |
#*********************************************************************** |
sl@0 | 11 |
# This file implements regression tests for SQLite library. |
sl@0 | 12 |
# |
sl@0 | 13 |
# This file implements tests the ability of the library to open |
sl@0 | 14 |
# many different databases at the same time without leaking memory. |
sl@0 | 15 |
# |
sl@0 | 16 |
# $Id: manydb.test,v 1.3 2006/01/11 01:08:34 drh Exp $ |
sl@0 | 17 |
|
sl@0 | 18 |
set testdir [file dirname $argv0] |
sl@0 | 19 |
source $testdir/tester.tcl |
sl@0 | 20 |
|
sl@0 | 21 |
set N 300 |
sl@0 | 22 |
|
sl@0 | 23 |
# First test how many file descriptors are available for use. To open a |
sl@0 | 24 |
# database for writing SQLite requires 3 file descriptors (the database, the |
sl@0 | 25 |
# journal and the directory). |
sl@0 | 26 |
set filehandles {} |
sl@0 | 27 |
catch { |
sl@0 | 28 |
for {set i 0} {$i<($N * 3)} {incr i} { |
sl@0 | 29 |
lappend filehandles [open testfile.1 w] |
sl@0 | 30 |
} |
sl@0 | 31 |
} |
sl@0 | 32 |
foreach fd $filehandles { |
sl@0 | 33 |
close $fd |
sl@0 | 34 |
} |
sl@0 | 35 |
catch { |
sl@0 | 36 |
file delete -force testfile.1 |
sl@0 | 37 |
} |
sl@0 | 38 |
set N [expr $i / 3] |
sl@0 | 39 |
|
sl@0 | 40 |
# Create a bunch of random database names |
sl@0 | 41 |
# |
sl@0 | 42 |
unset -nocomplain dbname |
sl@0 | 43 |
unset -nocomplain used |
sl@0 | 44 |
for {set i 0} {$i<$N} {incr i} { |
sl@0 | 45 |
while 1 { |
sl@0 | 46 |
set name test-[format %08x [expr {int(rand()*0x7fffffff)}]].db |
sl@0 | 47 |
if {[info exists used($name)]} continue |
sl@0 | 48 |
set dbname($i) $name |
sl@0 | 49 |
set used($name) $i |
sl@0 | 50 |
break |
sl@0 | 51 |
} |
sl@0 | 52 |
} |
sl@0 | 53 |
|
sl@0 | 54 |
# Create a bunch of databases |
sl@0 | 55 |
# |
sl@0 | 56 |
for {set i 0} {$i<$N} {incr i} { |
sl@0 | 57 |
do_test manydb-1.$i { |
sl@0 | 58 |
sqlite3 db$i $dbname($i) |
sl@0 | 59 |
execsql { |
sl@0 | 60 |
CREATE TABLE t1(a,b); |
sl@0 | 61 |
BEGIN; |
sl@0 | 62 |
INSERT INTO t1 VALUES(1,2); |
sl@0 | 63 |
} db$i |
sl@0 | 64 |
} {} |
sl@0 | 65 |
} |
sl@0 | 66 |
|
sl@0 | 67 |
# Finish the transactions |
sl@0 | 68 |
# |
sl@0 | 69 |
for {set i 0} {$i<$N} {incr i} { |
sl@0 | 70 |
do_test manydb-2.$i { |
sl@0 | 71 |
execsql { |
sl@0 | 72 |
COMMIT; |
sl@0 | 73 |
SELECT * FROM t1; |
sl@0 | 74 |
} db$i |
sl@0 | 75 |
} {1 2} |
sl@0 | 76 |
} |
sl@0 | 77 |
|
sl@0 | 78 |
|
sl@0 | 79 |
# Close the databases and erase the files. |
sl@0 | 80 |
# |
sl@0 | 81 |
for {set i 0} {$i<$N} {incr i} { |
sl@0 | 82 |
do_test manydb-3.$i { |
sl@0 | 83 |
db$i close |
sl@0 | 84 |
file delete -force $dbname($i) |
sl@0 | 85 |
} {} |
sl@0 | 86 |
} |
sl@0 | 87 |
|
sl@0 | 88 |
|
sl@0 | 89 |
|
sl@0 | 90 |
|
sl@0 | 91 |
finish_test |