/ Check-in [54f87899]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Enhance thread001.test again, this time to also test in shared-cache mode. (CVS 4418)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:54f87899033ddd892bfd3a16310f64fb42d807ae
User & Date: danielk1977 2007-09-10 07:35:47
Context
2007-09-10
10:53
Add another test file to help verify thread-safety. (CVS 4419) check-in: c758cc1d user: danielk1977 tags: trunk
07:35
Enhance thread001.test again, this time to also test in shared-cache mode. (CVS 4418) check-in: 54f87899 user: danielk1977 tags: trunk
06:23
Upgrade thread001.test to test with multiple database handles. (CVS 4417) check-in: 6ee2b8ff user: danielk1977 tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to test/thread001.test.

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
66
67
68
69
70
71
72
73












74
75
76
77
78
79
80
#
#    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.
#
#***********************************************************************
#
# $Id: thread001.test,v 1.3 2007/09/10 06:23:54 danielk1977 Exp $

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



if {[info commands sqlthread] eq ""} {
  puts -nonewline "Skipping thread-safety tests - "
  puts            " not running a threadsafe sqlite/tcl build"
  puts -nonewline "Both SQLITE_THREADSAFE and TCL_THREADS must be defined when"
  puts            " building testfixture"
  finish_test
  return
}

set ::NTHREAD 10

# The following script is sourced by every thread spawned using 
# [sqlthread spawn]:
set thread_procs {


  # Execute the supplied SQL using database handle $::DB.



  #




  proc execsql {sql} {
    set res [list]
    set ::STMT [sqlite3_prepare $::DB $sql -1 dummy_tail]
    while {[sqlite3_step $::STMT] eq "SQLITE_ROW"} {
      for {set i 0} {$i < [sqlite3_column_count $::STMT]} {incr i} {
        lappend res [sqlite3_column_text $::STMT 0]
      }
    }
    set rc [sqlite3_finalize $::STMT]
    if {$rc ne "SQLITE_OK"} {
      error [sqlite3_errmsg $::DB]
    }
    set res
  }

  proc do_test {name script result} {
    set res [eval $script]
    if {$res ne $result} {
      error "$name failed: expected \"$result\" got \"$res\""
    }
  }
}

proc thread_spawn {varname args} {
  sqlthread spawn $varname [join $args ;]
}

#########################################################################
# End of infrastruture. Start of test cases.
#########################################################################


# Run this test twice: Once with all threads using the same database
# connection, and once with each using it's own connection.
#
foreach {dbconfig tn} [list "set ::DB $::DB" 1 "" 2] {

  # Empty the database.
  #
  catchsql { DROP TABLE ab; }













  # Set up a database and a schema. The database contains a single
  # table with two columns. The first column ("a") is an INTEGER PRIMARY 
  # KEY. The second contains the md5sum of all rows in the table with
  # a smaller value stored in column "a".
  #
  do_test thread001.$tn.1 {







|


<

>
>

<
<
<
<
<





<
<
<
>
|
<
>
>
>
|
>
>
>
>
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<



>
>
>
>
>
>
>
>
>
>
>
>







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
#
#    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.
#
#***********************************************************************
#
# $Id: thread001.test,v 1.4 2007/09/10 07:35:47 danielk1977 Exp $

set testdir [file dirname $argv0]


source $testdir/tester.tcl
source $testdir/thread_common.tcl
if {[info commands sqlthread] eq ""} {





  return
}

set ::NTHREAD 10




# Run this test three times: 
# 

#    1) All threads use the same database handle.
#    2) All threads use their own database handles.
#    3) All threads use their own database handles, shared-cache is enabled.
#
foreach {tn same_db shared_cache} [list \
         1  1       0                   \
         2  0       0                   \
         3  0       1                   \
] {




































  # Empty the database.
  #
  catchsql { DROP TABLE ab; }

  do_test thread001.$tn.0 {
    db close
    sqlite3_enable_shared_cache $shared_cache
    sqlite3_enable_shared_cache $shared_cache
  } $shared_cache
  sqlite3 db test.db

  set dbconfig ""
  if {$same_db} {
    set dbconfig [list set ::DB [sqlite3_connection_pointer db]]
  }

  # Set up a database and a schema. The database contains a single
  # table with two columns. The first column ("a") is an INTEGER PRIMARY 
  # KEY. The second contains the md5sum of all rows in the table with
  # a smaller value stored in column "a".
  #
  do_test thread001.$tn.1 {

Added test/thread_common.tcl.













































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
66
67
68
69
70
# 2007 September 10
#
# 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.
#
#***********************************************************************
#
# $Id: thread_common.tcl,v 1.1 2007/09/10 07:35:47 danielk1977 Exp $

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

if {[info commands sqlthread] eq ""} {
  puts -nonewline "Skipping thread-safety tests - "
  puts            " not running a threadsafe sqlite/tcl build"
  puts -nonewline "Both SQLITE_THREADSAFE and TCL_THREADS must be defined when"
  puts            " building testfixture"
  finish_test
  return
}

set ::NTHREAD 10

# The following script is sourced by every thread spawned using 
# [sqlthread spawn]:
set thread_procs {

  # Execute the supplied SQL using database handle $::DB.
  #
  proc execsql {sql} {

    set rc SQLITE_LOCKED
    while {$rc eq "SQLITE_LOCKED"} {
      set res [list]
      set ::STMT [sqlite3_prepare $::DB $sql -1 dummy_tail]
      while {[set rc [sqlite3_step $::STMT]] eq "SQLITE_ROW"} {
        for {set i 0} {$i < [sqlite3_column_count $::STMT]} {incr i} {
          lappend res [sqlite3_column_text $::STMT 0]
        }
      }

      set rc [sqlite3_finalize $::STMT]
      if {$rc eq "SQLITE_LOCKED"} {
        after 20
      }
    }

    if {$rc ne "SQLITE_OK"} {
      error "$rc - [sqlite3_errmsg $::DB]"
    }
    set res
  }

  proc do_test {name script result} {
    set res [eval $script]
    if {$res ne $result} {
      error "$name failed: expected \"$result\" got \"$res\""
    }
  }
}

proc thread_spawn {varname args} {
  sqlthread spawn $varname [join $args ;]
}

return 0