libdoltlite-sys 0.38.26

Native bindings to the DoltLite SQLite-compatible library
Documentation
#
# 12-July-2020
#
#-------------------------------------------------------------------------
# This file contains tests for uploading and downloading files from
# cloud storage.
#


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

bcv_create_container $D(container)

file delete -force test.db
sqlite3 db test.db
do_execsql_test 1.0 {
  CREATE TABLE t1(a PRIMARY KEY, b UNIQUE);
  WITH s(i) AS (
    SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<5000
  )
  INSERT INTO t1 SELECT randomblob(500), randomblob(500) FROM s;
}
db close

proc log_callback {args} {
  puts $args
}

do_test 1.1 {
  set bcv [bcv_open $D(container)]
  # $bcv config log log_callback
  $bcv config nrequest 8
  $bcv upload test.db new.db
} {0}

do_test 1.2 {
  $bcv download new.db xyz.db
} {0}

$bcv close


bcv_mkdir testdir
set cmd [bcvfs_create testdir "bcvfs"]
bcvfs_attach $cmd $D(container)
sqlite3 db /$D(container)/new.db -vfs bcvfs

do_execsql_test 1.3 {
  PRAGMA integrity_check
} {ok}

db close
$cmd destroy

#-------------------------------------------------------------------------
# Tests to ensure that partial downloads can be resumed without error. 
#
sqlite3 db2 xyz.db
do_execsql2_test 2.0 {
  PRAGMA integrity_check;
  SELECT count(*) FROM t1;
} {ok 5000}

do_test 2.1.1 {
  set bcv [bcv_open $D(container)]
  # $bcv config log log_callback
  $bcv config nrequest 8
  $bcv download new.db xyz.db
} {0}

sqlite3 db2 xyz.db
do_execsql2_test 2.1.2 {
  PRAGMA integrity_check;
  SELECT count(*) FROM t1;
} {ok 5000}

do_test 2.2.1 {
  set fd [open xyz.db r+] 
  fconfigure $fd -encoding binary -translation binary
  seek $fd [expr 6*1000*1000]
  puts $fd "hello world!!!!"
  close $fd
  $bcv download new.db xyz.db
} {0}

sqlite3 db2 xyz.db
do_execsql2_test 2.2.2 {
  PRAGMA integrity_check;
  SELECT count(*) FROM t1;
} {ok 5000}

set ::inject_progress_error_when -1
proc inject_progress_error {nDone nTotal} {
  if {$nDone==$::inject_progress_error} {
    return 1
  }
  return 0
}
$bcv config progress inject_progress_error
for {set i 1} {$i <= 10} {incr i} {
  set ::inject_progress_error_when $i
  do_test 2.3.$i.1 {
    $bcv download new.db xyz.db
  } {4}
  do_test 2.3.$i.2 {
    $bcv errmsg
  } {abort requested by progress callback}
}

$bcv close
db2 close
finish_test