1# 2001 September 15 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 between competing processes. 13# 14# $Id: lock2.test,v 1.11 2009/05/01 10:55:34 danielk1977 Exp $ 15 16 17set testdir [file dirname $argv0] 18source $testdir/tester.tcl 19source $testdir/lock_common.tcl 20 21 22# Simple locking test case: 23# 24# lock2-1.1: Connect a second process to the database. 25# lock2-1.2: Establish a RESERVED lock with this process. 26# lock2-1.3: Get a SHARED lock with the second process. 27# lock2-1.4: Try for a RESERVED lock with process 2. This fails. 28# lock2-1.5: Try to upgrade the first process to EXCLUSIVE, this fails so 29# it gets PENDING. 30# lock2-1.6: Release the SHARED lock held by the second process. 31# lock2-1.7: Attempt to reaquire a SHARED lock with the second process. 32# this fails due to the PENDING lock. 33# lock2-1.8: Ensure the first process can now upgrade to EXCLUSIVE. 34# 35do_test lock2-1.1 { 36 set ::tf1 [launch_testfixture] 37 testfixture $::tf1 "sqlite3_test_control_pending_byte $::sqlite_pending_byte" 38 testfixture $::tf1 { 39 sqlite3 db test.db -key xyzzy 40 db eval {select * from sqlite_master} 41 } 42} {} 43do_test lock2-1.1.1 { 44 execsql {pragma lock_status} 45} {main unlocked temp closed} 46sqlite3_soft_heap_limit 0 47do_test lock2-1.2 { 48 execsql { 49 BEGIN; 50 CREATE TABLE abc(a, b, c); 51 } 52} {} 53do_test lock2-1.3 { 54 testfixture $::tf1 { 55 db eval { 56 BEGIN; 57 SELECT * FROM sqlite_master; 58 } 59 } 60} {} 61do_test lock2-1.4 { 62 testfixture $::tf1 { 63 db eval { 64 CREATE TABLE def(d, e, f) 65 } 66 } 67} {database is locked} 68do_test lock2-1.5 { 69 catchsql { 70 COMMIT; 71 } 72} {1 {database is locked}} 73do_test lock2-1.6 { 74 testfixture $::tf1 { 75 db eval { 76 SELECT * FROM sqlite_master; 77 COMMIT; 78 } 79 } 80} {} 81do_test lock2-1.7 { 82 testfixture $::tf1 { 83 db eval { 84 BEGIN; 85 SELECT * FROM sqlite_master; 86 } 87 } 88} {database is locked} 89do_test lock2-1.8 { 90 catchsql { 91 COMMIT; 92 } 93} {0 {}} 94do_test lock2-1.9 { 95 execsql { 96 SELECT * FROM sqlite_master; 97 } 98} "table abc abc [expr $AUTOVACUUM?3:2] {CREATE TABLE abc(a, b, c)}" 99do_test lock2-1.10 { 100 testfixture $::tf1 { 101 db eval { 102 SELECT * FROM sqlite_master; 103 } 104 } 105} "table abc abc [expr $AUTOVACUUM?3:2] {CREATE TABLE abc(a, b, c)}" 106 107catch {testfixture $::tf1 {db close}} 108catch {close $::tf1} 109sqlite3_soft_heap_limit $soft_limit 110 111finish_test 112