Annotation of embedaddon/sqlite3/test/manydb.test, revision 1.1

1.1     ! misho       1: # 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: #
        !            16: # $Id: manydb.test,v 1.4 2008/11/21 00:10:35 aswift Exp $
        !            17: 
        !            18: set testdir [file dirname $argv0]
        !            19: source $testdir/tester.tcl
        !            20: 
        !            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
        !            28: }
        !            29: set num_fd_per_openwrite_db 3
        !            30: if {$using_proxy>0} {
        !            31:   set num_fd_per_openwrite_db 5
        !            32: } 
        !            33: 
        !            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:   }
        !            42: }
        !            43: foreach fd $filehandles {
        !            44:   close $fd
        !            45: }
        !            46: catch {
        !            47:   forcedelete testfile.1
        !            48: }
        !            49: set N [expr $i / $num_fd_per_openwrite_db]
        !            50: 
        !            51: # Create a bunch of random database names
        !            52: #
        !            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:   }
        !            63: }
        !            64: 
        !            65: # Create a bunch of databases
        !            66: #
        !            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:   } {}
        !            76: }
        !            77: 
        !            78: # Finish the transactions
        !            79: #
        !            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}
        !            87: }
        !            88: 
        !            89: 
        !            90: # Close the databases and erase the files.
        !            91: #
        !            92: for {set i 0} {$i<$N} {incr i} {
        !            93:   do_test manydb-3.$i {
        !            94:     db$i close
        !            95:     forcedelete $dbname($i)
        !            96:   } {}
        !            97: }
        !            98: 
        !            99: 
        !           100: 
        !           101: 
        !           102: finish_test

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>