blob: d24054a1e69d6329a4493a14d3896d213af1ea74 [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#
drh27641702007-08-22 02:56:42 +000012# $Id: cache.test,v 1.4 2007/08/22 02:56:44 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]
drh27641702007-08-22 02:56:42 +000025 db_enter $db
danielk197724168722007-04-02 05:07:47 +000026 array set stats [btree_pager_stats $bt]
drh27641702007-08-22 02:56:42 +000027 db_leave $db
danielk197724168722007-04-02 05:07:47 +000028 return $stats(page)
29}
30
31do_test cache-1.1 {
32 pager_cache_size db
33} {0}
34
35do_test cache-1.2 {
36 execsql {
drh1e9daa62007-04-06 21:42:22 +000037 PRAGMA auto_vacuum=OFF;
danielk197724168722007-04-02 05:07:47 +000038 CREATE TABLE abc(a, b, c);
39 INSERT INTO abc VALUES(1, 2, 3);
40 }
41 pager_cache_size db
42} {2}
43
44# At one point, repeatedly locking and unlocking the cache was causing
45# a resource leak of one page per repetition. The page wasn't actually
46# leaked, but would not be reused until the pager-cache was full (i.e.
47# 2000 pages by default).
48#
49# This tests that once the pager-cache is initialised, it can be locked
50# and unlocked repeatedly without internally allocating any new pages.
51#
52set cache_size [pager_cache_size db]
53for {set ii 0} {$ii < 10} {incr ii} {
54
55 do_test cache-1.3.$ii {
56 execsql {SELECT * FROM abc}
57 pager_cache_size db
58 } $::cache_size
59
60}
danc1a60c52010-06-07 14:28:16 +000061sqlite3_soft_heap_limit $cmdlinearg(soft-heap-limit)
danielk197724168722007-04-02 05:07:47 +000062
63finish_test