libdoltlite-sys 0.38.26

Native bindings to the DoltLite SQLite-compatible library
Documentation
#
# 26-July-2021
#
#-------------------------------------------------------------------------
#

source [file join [file dirname [info script]] test_common.tcl]
set testprefix proxy_cleanup1

# This test is designed to run with the proxy.tcl/azurite combination 
# only. Print an error message and exit if it cannot be found.
if {[catch bcv_proxy_test msg]} { puts $msg ; exit }

bcv_proxy_config {
  DELETE FROM new_client_message;
}

proc xLog {args} {
  puts $args
}
bcv_create_container cont1
set bcv [bcv_open cont1]
#$bcv config log xLog
$bcv cleanup 0
$bcv close

bcv_create_container cont1
bcv_upload_new_db cont1 test.db {
  CREATE TABLE t1(a, b);
  WITH s(i) AS (
    VALUES(1) UNION ALL SELECT i+1 FROM s WHERE i<1000
  )
  INSERT INTO t1 SELECT hex(randomblob(1000)), hex(randomblob(1000)) FROM s;
}

bcv_mkdir testdir
set cmd [bcvfs_create testdir bcvfs]
bcvfs_attach $cmd cont1

sqlite3 db /cont1/test.db -vfs bcvfs
sqlite3_bcvfs_register_vtab db

do_execsql_test 1.0 {
  UPDATE t1 SET a = hex(randomblob(999));
}
$cmd upload cont1

set ::progress_handler [list]
proc bcv_progress_handler {nDone nTotal} {
  lappend ::progress_handler [list $nDone $nTotal]
  if {$nDone==12} { return 1 }
  return 0
}

bcv_proxy_config {
  INSERT INTO new_client_message(pattern, action) VALUES ('GET%', 'delay 100')
}

do_test 1.1 {
  set bcv [bcv_open cont1]
  $bcv config progress bcv_progress_handler
  $bcv config nrequest 8
  $bcv cleanup 0
} {4}
$bcv close

$cmd poll cont1
do_execsql_test 1.2 {
  SELECT name, ncleanup FROM bcv_container
} {cont1 32}

set ::progress_handler [list]
proc bcv_progress_handler {nDone nTotal} {
  lappend ::progress_handler [list $nDone $nTotal]
  if {$nDone==12} { return 101 }
  return 0
}

do_test 1.3 {
  set bcv [bcv_open cont1]
  $bcv config progress bcv_progress_handler
  $bcv config nrequest 8
  $bcv cleanup 0
} {0}
$bcv close

$cmd poll cont1
do_execsql_test 1.4 {
  SELECT name, ncleanup FROM bcv_container
} {cont1 13}

db close
$cmd destroy
finish_test