xref: /sqlite-3.40.0/test/multiplex3.test (revision 658dd586)
1
2# 2011 December 13
3#
4# The author disclaims copyright to this source code.  In place of
5# a legal notice, here is a blessing:
6#
7#    May you do good and not evil.
8#    May you find forgiveness for yourself and forgive others.
9#    May you share freely, never taking more than you give.
10#
11#***********************************************************************
12#
13# This file contains tests for error (IO, OOM etc.) handling when using
14# the multiplexor extension with 8.3 filenames.
15#
16
17set testdir $env(SQLITE_TEST_DIR)
18source $testdir/tester.tcl
19source $testdir/malloc_common.tcl
20set ::testprefix multiplex3
21
22ifcapable !8_3_names {
23  puts -nonewline "SQLite compiled without SQLITE_ENABLE_8_3_NAMES. "
24  puts            "Skipping tests zipvfsD-*."
25  finish_test
26  return
27}
28
29db close
30sqlite3_shutdown
31sqlite3_config_uri 1
32autoinstall_test_functions
33
34sqlite3_multiplex_initialize "" 1
35
36proc destroy_vfs_stack {} {
37  generic_unregister stack
38  sqlite3_multiplex_shutdown
39}
40
41proc multiplex_delete_db {} {
42  forcedelete test.db
43  for {set i 1} {$i <= 1000} {incr i} {
44    forcedelete test.[format %03d $i]
45  }
46}
47
48# Procs to save and restore the current muliplexed database.
49#
50proc multiplex_save_db {} {
51  foreach f [glob -nocomplain sv_test.*] { forcedelete $f }
52  foreach f [glob -nocomplain test.*]    { forcecopy $f "sv_$f" }
53}
54proc multiplex_restore_db {} {
55  foreach f [glob -nocomplain test.*]    {forcedelete $f}
56  foreach f [glob -nocomplain sv_test.*] {forcecopy $f [string range $f 3 end]} }
57
58
59do_test 1.0 {
60  multiplex_delete_db
61  sqlite3 db file:test.db?8_3_names=1
62  sqlite3_multiplex_control db main chunk_size [expr 256*1024]
63  execsql {
64    CREATE TABLE t1(a PRIMARY KEY, b);
65    INSERT INTO t1 VALUES(randomblob(15), randomblob(2000));
66    INSERT INTO t1 SELECT randomblob(15), randomblob(2000) FROM t1;    --   2
67    INSERT INTO t1 SELECT randomblob(15), randomblob(2000) FROM t1;    --   4
68    INSERT INTO t1 SELECT randomblob(15), randomblob(2000) FROM t1;    --   8
69    INSERT INTO t1 SELECT randomblob(15), randomblob(2000) FROM t1;    --  16
70    INSERT INTO t1 SELECT randomblob(15), randomblob(2000) FROM t1;    --  32
71    INSERT INTO t1 SELECT randomblob(15), randomblob(2000) FROM t1;    --  64
72    INSERT INTO t1 SELECT randomblob(15), randomblob(2000) FROM t1;    -- 128
73    INSERT INTO t1 SELECT randomblob(15), randomblob(2000) FROM t1;    -- 256
74    INSERT INTO t1 SELECT randomblob(15), randomblob(2000) FROM t1;    -- 512
75  }
76  set ::cksum1 [execsql {SELECT md5sum(a, b) FROM t1 ORDER BY a}]
77  db close
78  multiplex_save_db
79} {}
80
81do_faultsim_test 1 -prep {
82  multiplex_restore_db
83  sqlite3 db file:test.db?8_3_names=1
84  sqlite3_multiplex_control db main chunk_size [expr 256*1024]
85} -body {
86  execsql "UPDATE t1 SET a=randomblob(12), b=randomblob(1500) WHERE (rowid%32)=0"
87} -test {
88  faultsim_test_result {0 {}}
89  if {$testrc!=0} {
90    set cksum2 [execsql {SELECT md5sum(a, b) FROM t1 ORDER BY a}]
91    if {$cksum2 != $::cksum1} { error "data mismatch" }
92  }
93}
94
95catch { db close }
96
97sqlite3_multiplex_shutdown
98finish_test
99
100