danielk1977 | 489468c | 2004-06-28 08:25:47 +0000 | [diff] [blame] | 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 | # |
danielk1977 | ff340d8 | 2009-05-01 10:55:34 +0000 | [diff] [blame] | 14 | # $Id: lock2.test,v 1.11 2009/05/01 10:55:34 danielk1977 Exp $ |
danielk1977 | 489468c | 2004-06-28 08:25:47 +0000 | [diff] [blame] | 15 | |
| 16 | |
| 17 | set testdir [file dirname $argv0] |
| 18 | source $testdir/tester.tcl |
dan | e264d98 | 2010-04-14 18:06:50 +0000 | [diff] [blame] | 19 | source $testdir/lock_common.tcl |
danielk1977 | 489468c | 2004-06-28 08:25:47 +0000 | [diff] [blame] | 20 | |
danielk1977 | 489468c | 2004-06-28 08:25:47 +0000 | [diff] [blame] | 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 | # |
| 35 | do_test lock2-1.1 { |
| 36 | set ::tf1 [launch_testfixture] |
| 37 | testfixture $::tf1 { |
drh | 25d6543 | 2004-07-22 15:02:25 +0000 | [diff] [blame] | 38 | sqlite3 db test.db -key xyzzy |
danielk1977 | 489468c | 2004-06-28 08:25:47 +0000 | [diff] [blame] | 39 | db eval {select * from sqlite_master} |
| 40 | } |
| 41 | } {} |
drh | a67367e | 2005-09-17 16:36:55 +0000 | [diff] [blame] | 42 | do_test lock2-1.1.1 { |
| 43 | execsql {pragma lock_status} |
| 44 | } {main unlocked temp closed} |
drh | 3aefaba | 2007-08-12 20:07:58 +0000 | [diff] [blame] | 45 | sqlite3_soft_heap_limit 0 |
danielk1977 | 489468c | 2004-06-28 08:25:47 +0000 | [diff] [blame] | 46 | do_test lock2-1.2 { |
| 47 | execsql { |
| 48 | BEGIN; |
| 49 | CREATE TABLE abc(a, b, c); |
| 50 | } |
| 51 | } {} |
| 52 | do_test lock2-1.3 { |
| 53 | testfixture $::tf1 { |
| 54 | db eval { |
| 55 | BEGIN; |
| 56 | SELECT * FROM sqlite_master; |
| 57 | } |
| 58 | } |
| 59 | } {} |
| 60 | do_test lock2-1.4 { |
| 61 | testfixture $::tf1 { |
dan | 2fce9ab | 2010-06-15 18:00:06 +0000 | [diff] [blame] | 62 | catch { db eval { CREATE TABLE def(d, e, f) } } msg |
| 63 | set msg |
danielk1977 | 489468c | 2004-06-28 08:25:47 +0000 | [diff] [blame] | 64 | } |
| 65 | } {database is locked} |
| 66 | do_test lock2-1.5 { |
| 67 | catchsql { |
| 68 | COMMIT; |
| 69 | } |
| 70 | } {1 {database is locked}} |
| 71 | do_test lock2-1.6 { |
| 72 | testfixture $::tf1 { |
| 73 | db eval { |
| 74 | SELECT * FROM sqlite_master; |
| 75 | COMMIT; |
| 76 | } |
| 77 | } |
| 78 | } {} |
| 79 | do_test lock2-1.7 { |
| 80 | testfixture $::tf1 { |
dan | 2fce9ab | 2010-06-15 18:00:06 +0000 | [diff] [blame] | 81 | catch { db eval { |
danielk1977 | 489468c | 2004-06-28 08:25:47 +0000 | [diff] [blame] | 82 | BEGIN; |
| 83 | SELECT * FROM sqlite_master; |
dan | 2fce9ab | 2010-06-15 18:00:06 +0000 | [diff] [blame] | 84 | } } msg |
| 85 | set msg |
danielk1977 | 489468c | 2004-06-28 08:25:47 +0000 | [diff] [blame] | 86 | } |
| 87 | } {database is locked} |
| 88 | do_test lock2-1.8 { |
| 89 | catchsql { |
| 90 | COMMIT; |
| 91 | } |
| 92 | } {0 {}} |
| 93 | do_test lock2-1.9 { |
| 94 | execsql { |
| 95 | SELECT * FROM sqlite_master; |
| 96 | } |
danielk1977 | 45901d6 | 2004-11-10 15:27:38 +0000 | [diff] [blame] | 97 | } "table abc abc [expr $AUTOVACUUM?3:2] {CREATE TABLE abc(a, b, c)}" |
dan | 0cf408f | 2010-07-13 07:38:51 +0000 | [diff] [blame] | 98 | catch flush_async_queue |
danielk1977 | 489468c | 2004-06-28 08:25:47 +0000 | [diff] [blame] | 99 | do_test lock2-1.10 { |
| 100 | testfixture $::tf1 { |
| 101 | db eval { |
| 102 | SELECT * FROM sqlite_master; |
| 103 | } |
| 104 | } |
danielk1977 | 45901d6 | 2004-11-10 15:27:38 +0000 | [diff] [blame] | 105 | } "table abc abc [expr $AUTOVACUUM?3:2] {CREATE TABLE abc(a, b, c)}" |
danielk1977 | 489468c | 2004-06-28 08:25:47 +0000 | [diff] [blame] | 106 | |
drh | 2ec8164 | 2004-06-28 11:52:45 +0000 | [diff] [blame] | 107 | catch {testfixture $::tf1 {db close}} |
| 108 | catch {close $::tf1} |
dan | c1a60c5 | 2010-06-07 14:28:16 +0000 | [diff] [blame] | 109 | sqlite3_soft_heap_limit $cmdlinearg(soft-heap-limit) |
danielk1977 | 489468c | 2004-06-28 08:25:47 +0000 | [diff] [blame] | 110 | |
drh | 2ec8164 | 2004-06-28 11:52:45 +0000 | [diff] [blame] | 111 | finish_test |