blob: a0d7496c865de19801257b455dd1f5bee20cf681 [file] [log] [blame]
drhb5774cf2008-09-15 15:36:57 +00001# 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#
danielk1977f16c6242009-07-18 14:36:23 +000014# $Id: pcache2.test,v 1.5 2009/07/18 14:36:24 danielk1977 Exp $
drhb5774cf2008-09-15 15:36:57 +000015
16set testdir [file dirname $argv0]
17source $testdir/tester.tcl
18
dan03bc5252015-07-24 14:17:17 +000019test_set_config_pagecache 0 0
20
drhb5774cf2008-09-15 15:36:57 +000021# Set up a pcache memory pool so that we can easily track how many
22# pages are being used for cache.
23#
24do_test pcache2-1.1 {
25 db close
danielk1977ac8d7b32008-11-13 16:21:50 +000026 sqlite3_reset_auto_extension
drhb5774cf2008-09-15 15:36:57 +000027 sqlite3_shutdown
28 sqlite3_config_pagecache 6000 100
drhc54357c2015-07-07 14:06:18 +000029 sqlite3_config singlethread
drhb5774cf2008-09-15 15:36:57 +000030 sqlite3_initialize
danielk1977ac8d7b32008-11-13 16:21:50 +000031 autoinstall_test_functions
drhb5774cf2008-09-15 15:36:57 +000032 sqlite3_status SQLITE_STATUS_PAGECACHE_USED 1
33 sqlite3_status SQLITE_STATUS_PAGECACHE_USED 0
34} {0 0 0}
35
36# Open up two database connections to separate files.
37#
38do_test pcache2-1.2 {
mistachkinfda06be2011-08-02 00:57:34 +000039 forcedelete test.db test.db-journal
drhb5774cf2008-09-15 15:36:57 +000040 sqlite3 db test.db
drh957026a2015-07-16 18:18:19 +000041 db eval {PRAGMA cache_size=10; SELECT 1 FROM sqlite_master;}
drhb5774cf2008-09-15 15:36:57 +000042 lindex [sqlite3_status SQLITE_STATUS_PAGECACHE_USED 0] 1
43} {2}
44do_test pcache2-1.3 {
mistachkinfda06be2011-08-02 00:57:34 +000045 forcedelete test2.db test2.db-journal
drhb5774cf2008-09-15 15:36:57 +000046 sqlite3 db2 test2.db
drh957026a2015-07-16 18:18:19 +000047 db2 eval {PRAGMA cache_size=50; SELECT 1 FROM sqlite_master;}
drhb5774cf2008-09-15 15:36:57 +000048 lindex [sqlite3_status SQLITE_STATUS_PAGECACHE_USED 0] 1
49} {4}
50
danielk1977627a3d62009-07-18 08:30:44 +000051
drhb5774cf2008-09-15 15:36:57 +000052# Make lots of changes on the first connection. Verify that the
53# page cache usage does not grow to consume the page space set aside
54# for the second connection.
55#
56do_test pcache2-1.4 {
57 db eval {
58 CREATE TABLE t1(a,b);
59 CREATE TABLE t2(x,y);
60 INSERT INTO t1 VALUES(1, zeroblob(800));
61 INSERT INTO t1 VALUES(2, zeroblob(800));
62 INSERT INTO t2 SELECT * FROM t1;
63 INSERT INTO t1 SELECT x+2, y FROM t2;
64 INSERT INTO t2 SELECT a+10, b FROM t1;
65 INSERT INTO t1 SELECT x+10, y FROM t2;
66 INSERT INTO t2 SELECT a+100, b FROM t1;
67 INSERT INTO t1 SELECT x+100, y FROM t2;
68 INSERT INTO t2 SELECT a+1000, b FROM t1;
69 INSERT INTO t1 SELECT x+1000, y FROM t2;
70 }
71 sqlite3_status SQLITE_STATUS_PAGECACHE_USED 0
72} {0 13 13}
73
danielk19774bd3ce62008-10-14 19:21:51 +000074db close
drhb5774cf2008-09-15 15:36:57 +000075catch {db2 close}
danielk1977ac8d7b32008-11-13 16:21:50 +000076sqlite3_reset_auto_extension
danielk19774bd3ce62008-10-14 19:21:51 +000077sqlite3_shutdown
78sqlite3_config_pagecache 0 0
drhc54357c2015-07-07 14:06:18 +000079sqlite3_config serialized
danielk1977ac8d7b32008-11-13 16:21:50 +000080sqlite3_initialize
81autoinstall_test_functions
82
dan03bc5252015-07-24 14:17:17 +000083test_restore_config_pagecache
drhb5774cf2008-09-15 15:36:57 +000084finish_test