Fix a problem causing the recovery extension to use excessive memory and CPU time...
[sqlite.git] / test / readonly.test
blob1ccbcee284174ddbdf270496a81d41caf36ef387
1 # 2024 March 21
3 # The author disclaims copyright to this source code.  In place of
4 # a legal notice, here is a blessing:
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.
10 #***********************************************************************
12 # This file contains tests for using databases in read-only mode on
13 # unix.
16 set testdir [file dirname $argv0]
17 source $testdir/tester.tcl
18 if {$tcl_platform(platform)=="windows"} finish_test
19 source $testdir/lock_common.tcl
20 source $testdir/wal_common.tcl
21 set ::testprefix readonly
23 do_execsql_test 1.0 {
24   CREATE TABLE t1(a, b);
25   INSERT INTO t1 VALUES(1, 2), (3, 4), (5, 6);
28 db close
29 file attributes test.db -permissions r--r--r--
31 sqlite3 db test.db
33 do_catchsql_test 1.1 {
34   INSERT INTO t1 VALUES(7, 8);
35 } {1 {attempt to write a readonly database}}
37 do_execsql_test 1.2 {
38   BEGIN;
39     SELECT * FROM t1;
40 } {1 2 3 4 5 6}
42 # The following attempts to open a read/write fd on the database 20,000 
43 # times. And each time instead opens a read-only fd. At one point this
44 # was failing to reuse cached fds, causing a "too many open file-descriptors"
45 # error.
46 do_test 1.3 {
47   for {set ii 0} {$ii < 20000} {incr ii} {
48     sqlite3 db2 test.db
49     db2 close
50   }
51   set {} {} 
52 } {}
55 finish_test