xref: /sqlite-3.40.0/test/walro2.test (revision dea5ce36)
1# 2011 May 09
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#
12# This file contains tests for using WAL databases in read-only mode.
13#
14
15set testdir [file dirname $argv0]
16source $testdir/tester.tcl
17source $testdir/lock_common.tcl
18set ::testprefix walro
19
20# These tests are only going to work on unix.
21#
22if {$::tcl_platform(platform) != "unix"} {
23  finish_test
24  return
25}
26
27# And only if the build is WAL-capable.
28#
29ifcapable !wal {
30  finish_test
31  return
32}
33
34do_multiclient_test tn {
35
36  # Close all connections and delete the database.
37  #
38  code1 { db close  }
39  code2 { db2 close }
40  code3 { db3 close }
41  forcedelete test.db
42
43  # Do not run tests with the connections in the same process.
44  #
45  if {$tn==2} continue
46
47  foreach c {code1 code2 code3} {
48    $c {
49      sqlite3_shutdown
50      sqlite3_config_uri 1
51    }
52  }
53
54  do_test 1.1 {
55    code2 { sqlite3 db2 test.db }
56    sql2 {
57      CREATE TABLE t1(x, y);
58      PRAGMA journal_mode = WAL;
59      INSERT INTO t1 VALUES('a', 'b');
60      INSERT INTO t1 VALUES('c', 'd');
61    }
62    file exists test.db-shm
63  } {1}
64
65  do_test 1.2 {
66    forcecopy test.db test.db2
67    forcecopy test.db-wal test.db2-wal
68    forcecopy test.db-shm test.db2-shm
69    code1 {
70      sqlite3 db file:test.db2?readonly_shm=1
71    }
72
73    sql1 { SELECT * FROM t1 }
74  } {}
75
76  do_test 1.3.1 {
77    code3 { sqlite3 db3 test.db2 }
78    sql3 { SELECT * FROM t1 }
79  } {a b c d}
80
81  do_test 1.3.2 {
82    sql1 { SELECT * FROM t1 }
83  } {a b c d}
84
85  code1 { db close  }
86  code2 { db2 close }
87  code3 { db3 close }
88
89  do_test 2.1 {
90    code2 { sqlite3 db2 test.db }
91    sql2 {
92      INSERT INTO t1 VALUES('e', 'f');
93      INSERT INTO t1 VALUES('g', 'h');
94    }
95    file exists test.db-shm
96  } {1}
97
98  do_test 2.2 {
99    forcecopy test.db test.db2
100    forcecopy test.db-wal test.db2-wal
101    forcecopy test.db-shm test.db2-shm
102    code1 {
103      sqlite3 db file:test.db2?readonly_shm=1
104    }
105    sql1 {
106      BEGIN;
107      SELECT * FROM t1;
108    }
109  } {a b c d}
110
111  do_test 2.3.1 {
112    code3 { sqlite3 db3 test.db2 }
113    sql3 { SELECT * FROM t1 }
114  } {a b c d e f g h}
115
116}
117
118finish_test
119