xref: /sqlite-3.40.0/test/sync.test (revision 3bdca9c9)
1# 2005 August 28
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# This file implements regression tests for SQLite library.
12#
13# This file implements tests to verify that fsync is disabled when
14# pragma synchronous=off even for multi-database commits.
15#
16# $Id: sync.test,v 1.3 2006/01/17 09:35:02 danielk1977 Exp $
17
18set testdir [file dirname $argv0]
19source $testdir/tester.tcl
20
21#
22# These tests are only applicable on unix when pager pragma are
23# enabled.
24#
25if {$::tcl_platform(platform)!="unix"} {
26  finish_test
27}
28ifcapable !pager_pragmas {
29  finish_test
30}
31
32do_test sync-1.1 {
33  set sqlite_sync_count 0
34  file delete -force test2.db
35  file delete -force test2.db-journal
36  execsql {
37    CREATE TABLE t1(a,b);
38    ATTACH DATABASE 'test2.db' AS db2;
39    CREATE TABLE db2.t2(x,y);
40  }
41  ifcapable !dirsync {
42    incr sqlite_sync_count 2
43  }
44  set sqlite_sync_count
45} 8
46ifcapable pager_pragmas {
47  do_test sync-1.2 {
48    set sqlite_sync_count 0
49    execsql {
50      PRAGMA main.synchronous=on;
51      PRAGMA db2.synchronous=on;
52      BEGIN;
53      INSERT INTO t1 VALUES(1,2);
54      INSERT INTO t2 VALUES(3,4);
55      COMMIT;
56    }
57    ifcapable !dirsync {
58      incr sqlite_sync_count 3
59    }
60    set sqlite_sync_count
61  } 8
62}
63do_test sync-1.3 {
64  set sqlite_sync_count 0
65  execsql {
66    PRAGMA main.synchronous=full;
67    PRAGMA db2.synchronous=full;
68    BEGIN;
69    INSERT INTO t1 VALUES(3,4);
70    INSERT INTO t2 VALUES(5,6);
71    COMMIT;
72  }
73  ifcapable !dirsync {
74    incr sqlite_sync_count 3
75  }
76  set sqlite_sync_count
77} 10
78ifcapable pager_pragmas {
79  do_test sync-1.4 {
80    set sqlite_sync_count 0
81    execsql {
82      PRAGMA main.synchronous=off;
83      PRAGMA db2.synchronous=off;
84      BEGIN;
85      INSERT INTO t1 VALUES(5,6);
86      INSERT INTO t2 VALUES(7,8);
87      COMMIT;
88    }
89    set sqlite_sync_count
90  } 0
91}
92
93
94finish_test
95