xref: /sqlite-3.40.0/test/sync.test (revision 7aae9943)
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.4 2006/01/31 15:19:45 drh 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  return
28}
29ifcapable !pager_pragmas {
30  finish_test
31  return
32}
33
34do_test sync-1.1 {
35  set sqlite_sync_count 0
36  file delete -force test2.db
37  file delete -force test2.db-journal
38  execsql {
39    CREATE TABLE t1(a,b);
40    ATTACH DATABASE 'test2.db' AS db2;
41    CREATE TABLE db2.t2(x,y);
42  }
43  ifcapable !dirsync {
44    incr sqlite_sync_count 2
45  }
46  set sqlite_sync_count
47} 8
48ifcapable pager_pragmas {
49  do_test sync-1.2 {
50    set sqlite_sync_count 0
51    execsql {
52      PRAGMA main.synchronous=on;
53      PRAGMA db2.synchronous=on;
54      BEGIN;
55      INSERT INTO t1 VALUES(1,2);
56      INSERT INTO t2 VALUES(3,4);
57      COMMIT;
58    }
59    ifcapable !dirsync {
60      incr sqlite_sync_count 3
61    }
62    set sqlite_sync_count
63  } 8
64}
65do_test sync-1.3 {
66  set sqlite_sync_count 0
67  execsql {
68    PRAGMA main.synchronous=full;
69    PRAGMA db2.synchronous=full;
70    BEGIN;
71    INSERT INTO t1 VALUES(3,4);
72    INSERT INTO t2 VALUES(5,6);
73    COMMIT;
74  }
75  ifcapable !dirsync {
76    incr sqlite_sync_count 3
77  }
78  set sqlite_sync_count
79} 10
80ifcapable pager_pragmas {
81  do_test sync-1.4 {
82    set sqlite_sync_count 0
83    execsql {
84      PRAGMA main.synchronous=off;
85      PRAGMA db2.synchronous=off;
86      BEGIN;
87      INSERT INTO t1 VALUES(5,6);
88      INSERT INTO t2 VALUES(7,8);
89      COMMIT;
90    }
91    set sqlite_sync_count
92  } 0
93}
94
95
96finish_test
97