blob: 6a463aa8c31f944d21d211069c5a2cd1fad9e626 [file] [log] [blame]
danielk197724168722007-04-02 05:07:47 +00001# 2007 March 24
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#
drh3aefaba2007-08-12 20:07:58 +000012# $Id: cache.test,v 1.3 2007/08/12 20:07:59 drh Exp $
danielk197724168722007-04-02 05:07:47 +000013
14set testdir [file dirname $argv0]
15source $testdir/tester.tcl
16
17ifcapable {!pager_pragmas} {
18 finish_test
19 return
20}
drh3aefaba2007-08-12 20:07:58 +000021sqlite3_soft_heap_limit 0
danielk197724168722007-04-02 05:07:47 +000022
23proc pager_cache_size {db} {
24 set bt [btree_from_db $db]
25 array set stats [btree_pager_stats $bt]
26 return $stats(page)
27}
28
29do_test cache-1.1 {
30 pager_cache_size db
31} {0}
32
33do_test cache-1.2 {
34 execsql {
drh1e9daa62007-04-06 21:42:22 +000035 PRAGMA auto_vacuum=OFF;
danielk197724168722007-04-02 05:07:47 +000036 CREATE TABLE abc(a, b, c);
37 INSERT INTO abc VALUES(1, 2, 3);
38 }
39 pager_cache_size db
40} {2}
41
42# At one point, repeatedly locking and unlocking the cache was causing
43# a resource leak of one page per repetition. The page wasn't actually
44# leaked, but would not be reused until the pager-cache was full (i.e.
45# 2000 pages by default).
46#
47# This tests that once the pager-cache is initialised, it can be locked
48# and unlocked repeatedly without internally allocating any new pages.
49#
50set cache_size [pager_cache_size db]
51for {set ii 0} {$ii < 10} {incr ii} {
52
53 do_test cache-1.3.$ii {
54 execsql {SELECT * FROM abc}
55 pager_cache_size db
56 } $::cache_size
57
58}
drh3aefaba2007-08-12 20:07:58 +000059sqlite3_soft_heap_limit $soft_limit
danielk197724168722007-04-02 05:07:47 +000060
61finish_test