Annotation of embedaddon/sqlite3/test/lock5.test, revision 1.1
1.1 ! misho 1: # 2008 June 28
! 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. The
! 12: # focus of this script is database locks.
! 13: #
! 14: # $Id: lock5.test,v 1.6 2008/12/04 12:34:16 drh Exp $
! 15:
! 16: set testdir [file dirname $argv0]
! 17: source $testdir/tester.tcl
! 18:
! 19: # This file is only run if using the unix backend compiled with the
! 20: # SQLITE_ENABLE_LOCKING_STYLE macro.
! 21: db close
! 22: if {[catch {sqlite3 db test.db -vfs unix-none} msg]} {
! 23: finish_test
! 24: return
! 25: }
! 26: db close
! 27: forcedelete test.db.lock
! 28:
! 29: ifcapable lock_proxy_pragmas {
! 30: set ::using_proxy 0
! 31: foreach {name value} [array get env SQLITE_FORCE_PROXY_LOCKING] {
! 32: set ::using_proxy $value
! 33: }
! 34: # Disable the proxy locking for these tests
! 35: set env(SQLITE_FORCE_PROXY_LOCKING) "0"
! 36: }
! 37:
! 38:
! 39: do_test lock5-dotfile.1 {
! 40: sqlite3 db test.db -vfs unix-dotfile
! 41: execsql {
! 42: BEGIN;
! 43: CREATE TABLE t1(a, b);
! 44: }
! 45: } {}
! 46:
! 47: do_test lock5-dotfile.2 {
! 48: file exists test.db.lock
! 49: } {1}
! 50:
! 51: do_test lock5-dotfile.3 {
! 52: execsql COMMIT
! 53: file exists test.db.lock
! 54: } {0}
! 55:
! 56: do_test lock5-dotfile.4 {
! 57: sqlite3 db2 test.db -vfs unix-dotfile
! 58: execsql {
! 59: INSERT INTO t1 VALUES('a', 'b');
! 60: SELECT * FROM t1;
! 61: } db2
! 62: } {a b}
! 63:
! 64: do_test lock5-dotfile.5 {
! 65: execsql {
! 66: BEGIN;
! 67: SELECT * FROM t1;
! 68: } db2
! 69: } {a b}
! 70:
! 71: do_test lock5-dotfile.6 {
! 72: file exists test.db.lock
! 73: } {1}
! 74:
! 75: do_test lock5-dotfile.7 {
! 76: catchsql { SELECT * FROM t1; }
! 77: } {1 {database is locked}}
! 78:
! 79: do_test lock5-dotfile.8 {
! 80: execsql {
! 81: SELECT * FROM t1;
! 82: ROLLBACK;
! 83: } db2
! 84: } {a b}
! 85:
! 86: do_test lock5-dotfile.9 {
! 87: catchsql { SELECT * FROM t1; }
! 88: } {0 {a b}}
! 89:
! 90: do_test lock5-dotfile.10 {
! 91: file exists test.db.lock
! 92: } {0}
! 93:
! 94: do_test lock5-dotfile.X {
! 95: db2 close
! 96: execsql {BEGIN EXCLUSIVE}
! 97: db close
! 98: file exists test.db.lock
! 99: } {0}
! 100:
! 101: #####################################################################
! 102:
! 103: forcedelete test.db
! 104: if {[catch {sqlite3 db test.db -vfs unix-flock} msg]} {
! 105: finish_test
! 106: return
! 107: }
! 108:
! 109: do_test lock5-flock.1 {
! 110: sqlite3 db test.db -vfs unix-flock
! 111: execsql {
! 112: CREATE TABLE t1(a, b);
! 113: BEGIN;
! 114: INSERT INTO t1 VALUES(1, 2);
! 115: }
! 116: } {}
! 117:
! 118: # Make sure we are not accidentally using the dotfile locking scheme.
! 119: do_test lock5-flock.2 {
! 120: file exists test.db.lock
! 121: } {0}
! 122:
! 123: do_test lock5-flock.3 {
! 124: catch { sqlite3 db2 test.db -vfs unix-flock }
! 125: catchsql { SELECT * FROM t1 } db2
! 126: } {1 {database is locked}}
! 127:
! 128: do_test lock5-flock.4 {
! 129: execsql COMMIT
! 130: catchsql { SELECT * FROM t1 } db2
! 131: } {0 {1 2}}
! 132:
! 133: do_test lock5-flock.5 {
! 134: execsql BEGIN
! 135: catchsql { SELECT * FROM t1 } db2
! 136: } {0 {1 2}}
! 137:
! 138: do_test lock5-flock.6 {
! 139: execsql {SELECT * FROM t1}
! 140: catchsql { SELECT * FROM t1 } db2
! 141: } {1 {database is locked}}
! 142:
! 143: do_test lock5-flock.7 {
! 144: db close
! 145: catchsql { SELECT * FROM t1 } db2
! 146: } {0 {1 2}}
! 147:
! 148: do_test lock5-flock.8 {
! 149: db2 close
! 150: } {}
! 151:
! 152: #####################################################################
! 153:
! 154: do_test lock5-none.1 {
! 155: sqlite3 db test.db -vfs unix-none
! 156: sqlite3 db2 test.db -vfs unix-none
! 157: execsql {
! 158: BEGIN;
! 159: INSERT INTO t1 VALUES(3, 4);
! 160: }
! 161: } {}
! 162: do_test lock5-none.2 {
! 163: execsql { SELECT * FROM t1 }
! 164: } {1 2 3 4}
! 165: do_test lock5-flock.3 {
! 166: execsql { SELECT * FROM t1 } db2
! 167: } {1 2}
! 168: do_test lock5-none.4 {
! 169: execsql {
! 170: BEGIN;
! 171: SELECT * FROM t1;
! 172: } db2
! 173: } {1 2}
! 174: do_test lock5-none.5 {
! 175: execsql COMMIT
! 176: execsql {SELECT * FROM t1} db2
! 177: } {1 2}
! 178:
! 179: ifcapable memorymanage {
! 180: do_test lock5-none.6 {
! 181: sqlite3_release_memory 1000000
! 182: execsql {SELECT * FROM t1} db2
! 183: } {1 2 3 4}
! 184: }
! 185:
! 186: do_test lock5-flock.X {
! 187: db close
! 188: db2 close
! 189: } {}
! 190:
! 191: ifcapable lock_proxy_pragmas {
! 192: set env(SQLITE_FORCE_PROXY_LOCKING) $::using_proxy
! 193: }
! 194:
! 195: finish_test
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>