blob: ce9b7efe001dd62050d95d034abe74071e45acac [file] [log] [blame]
drh762e5842005-10-03 15:11:08 +00001# 2005 October 3
2#
3# The author disclaims copyright to this source code. In place of
4# 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 open
14# many different databases at the same time without leaking memory.
15#
danielk1977aa2289f2005-11-25 10:55:57 +000016# $Id: manydb.test,v 1.2 2005/11/25 10:55:58 danielk1977 Exp $
drh762e5842005-10-03 15:11:08 +000017
18set testdir [file dirname $argv0]
19source $testdir/tester.tcl
20
21set N 300
22
danielk1977aa2289f2005-11-25 10:55:57 +000023# First test how many file descriptors are available for use. To open a
24# database for writing SQLite requires 3 file descriptors (the database, the
25# journal and the directory).
26catch {
27 for {set i 0} {$i<($N * 3)} {incr i} {
28 lappend filehandles [open testfile.1 w]
29 }
30}
31foreach fd $filehandles {
32 close $fd
33}
34catch {
35 file delete -force testfile.1
36}
37set N [expr $i / 3]
38
drh762e5842005-10-03 15:11:08 +000039# Create a bunch of random database names
40#
41unset -nocomplain dbname
42unset -nocomplain used
43for {set i 0} {$i<$N} {incr i} {
44 while 1 {
45 set name test-[format %08x [expr {int(rand()*0x7fffffff)}]].db
46 if {[info exists used($name)]} continue
47 set dbname($i) $name
48 set used($name) $i
49 break
50 }
51}
52
53# Create a bunch of databases
54#
55for {set i 0} {$i<$N} {incr i} {
56 do_test manydb-1.$i {
57 sqlite3 db$i $dbname($i)
58 execsql {
59 CREATE TABLE t1(a,b);
60 BEGIN;
61 INSERT INTO t1 VALUES(1,2);
62 } db$i
63 } {}
64}
65
66# Finish the transactions
67#
68for {set i 0} {$i<$N} {incr i} {
69 do_test manydb-2.$i {
70 execsql {
71 COMMIT;
72 SELECT * FROM t1;
73 } db$i
74 } {1 2}
75}
76
77
78# Close the databases and erase the files.
79#
80for {set i 0} {$i<$N} {incr i} {
81 do_test manydb-3.$i {
82 db$i close
83 file delete -force $dbname($i)
84 } {}
85}
86
87
88
89
90finish_test