xref: /sqlite-3.40.0/test/pcache2.test (revision 4bd3ce69)
1# 2008 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#
12# This file is focused on testing the pcache module.
13#
14# $Id: pcache2.test,v 1.2 2008/10/14 19:21:52 danielk1977 Exp $
15
16set testdir [file dirname $argv0]
17source $testdir/tester.tcl
18
19
20# Set up a pcache memory pool so that we can easily track how many
21# pages are being used for cache.
22#
23do_test pcache2-1.1 {
24  db close
25  sqlite3_shutdown
26  sqlite3_config_pagecache 6000 100
27  sqlite3_initialize
28  sqlite3_status SQLITE_STATUS_PAGECACHE_USED 1
29  sqlite3_status SQLITE_STATUS_PAGECACHE_USED 0
30} {0 0 0}
31
32# Open up two database connections to separate files.
33#
34do_test pcache2-1.2 {
35  file delete -force test.db test.db-journal
36  sqlite3 db test.db
37  db eval {PRAGMA cache_size=10}
38  lindex [sqlite3_status SQLITE_STATUS_PAGECACHE_USED 0] 1
39} {2}
40do_test pcache2-1.3 {
41  file delete -force test2.db test2.db-journal
42  sqlite3 db2 test2.db
43  db2 eval {PRAGMA cache_size=50}
44  lindex [sqlite3_status SQLITE_STATUS_PAGECACHE_USED 0] 1
45} {4}
46
47# Make lots of changes on the first connection.  Verify that the
48# page cache usage does not grow to consume the page space set aside
49# for the second connection.
50#
51do_test pcache2-1.4 {
52  db eval {
53     CREATE TABLE t1(a,b);
54     CREATE TABLE t2(x,y);
55     INSERT INTO t1 VALUES(1, zeroblob(800));
56     INSERT INTO t1 VALUES(2, zeroblob(800));
57     INSERT INTO t2 SELECT * FROM t1;
58     INSERT INTO t1 SELECT x+2, y FROM t2;
59     INSERT INTO t2 SELECT a+10, b FROM t1;
60     INSERT INTO t1 SELECT x+10, y FROM t2;
61     INSERT INTO t2 SELECT a+100, b FROM t1;
62     INSERT INTO t1 SELECT x+100, y FROM t2;
63     INSERT INTO t2 SELECT a+1000, b FROM t1;
64     INSERT INTO t1 SELECT x+1000, y FROM t2;
65  }
66  sqlite3_status SQLITE_STATUS_PAGECACHE_USED 0
67} {0 13 13}
68
69db close
70catch {db2 close}
71sqlite3_shutdown
72sqlite3_config_pagecache 0 0
73finish_test
74