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