summaryrefslogtreecommitdiffstats
path: root/test/swarmvtabfault.test
blob: 8cca3b2744ffc09a5c09c1561c47c001e0bb3f85 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# 2017-07-15
#
# The author disclaims copyright to this source code.  In place of
# a legal notice, here is a blessing:
#
#    May you do good and not evil.
#    May you find forgiveness for yourself and forgive others.
#    May you share freely, never taking more than you give.
#
#***********************************************************************
# This file implements regression tests for SQLite library.  The
# focus of this file is error handling in the swarmvtab extension.
#

set testdir [file dirname $argv0]
source $testdir/tester.tcl
set testprefix swarmvtabfault

ifcapable !vtab {
  finish_test
  return
}

proc fetch_db {file} {
  forcedelete $file
  sqlite3 dbX $file
  set rc [catch {
    dbX eval { CREATE TABLE t1(a INTEGER PRIMARY KEY, b) }
  } res]
  dbX close
  if {$rc!=0} {error $res}
}

forcedelete test.db1
forcedelete test.db2

do_execsql_test 1.0 {
  ATTACH 'test.db1' AS aux;
  CREATE TABLE aux.t1(a INTEGER PRIMARY KEY, b);
  INSERT INTO aux.t1 VALUES(1, NULL);
  INSERT INTO aux.t1 VALUES(2, NULL);
  INSERT INTO aux.t1 VALUES(9, NULL);
  DETACH aux;
} {}

faultsim_save_and_close
do_faultsim_test 1.1 -faults oom* -prep {
  faultsim_restore_and_reopen
  db func fetch_db fetch_db
  load_static_extension db unionvtab
  db eval {
    CREATE VIRTUAL TABLE temp.xyz USING swarmvtab(
        'VALUES
        ("test.db1", "t1", 1, 10),
        ("test.db2", "t1", 11, 20)
        ', 'fetch_db'
    );
  }
} -body {
  execsql { SELECT a FROM xyz }
} -test {
  faultsim_test_result {0 {1 2 9}} {1 {sql error: out of memory}}
}

finish_test