Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Add tests for sessions module. |
---|---|
Downloads: | Tarball | ZIP archive |
Timelines: | family | ancestors | descendants | both | sessions |
Files: | files | file ages | folders |
SHA1: |
82fdb1975f5b29a751089a8582713372 |
User & Date: | dan 2014-08-18 08:42:36.985 |
Context
2014-08-18
| ||
13:48 | Merge the latest trunk changes, and in particular the refactoring of the object names in the command-line shell. (check-in: 419d286a2f user: drh tags: sessions) | |
08:42 | Add tests for sessions module. (check-in: 82fdb1975f user: dan tags: sessions) | |
2014-08-16
| ||
19:01 | Fix some missing and out-of-date comments in the sessions module. (check-in: 05c1d9149b user: dan tags: sessions) | |
Changes
Changes to ext/session/sessionB.test.
︙ | ︙ | |||
323 324 325 326 327 328 329 | } { DELETE FROM t2 WHERE b=1; } { {DELETE t2 0 .XX. {{} {} i 1 i 1 {} {}} {}} {DELETE t2 0 .XX. {{} {} i 1 i 2 {} {}} {}} } | > > > > > > > > > > > > > > > > > > > > | > > > | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 | } { DELETE FROM t2 WHERE b=1; } { {DELETE t2 0 .XX. {{} {} i 1 i 1 {} {}} {}} {DELETE t2 0 .XX. {{} {} i 1 i 2 {} {}} {}} } #------------------------------------------------------------------------- # More rigorous testing of the _patchset(), _apply and _concat() APIs. # # The inputs to each test are a populate database and a list of DML # statements. This test determines that the final database is the same # if: # # 1) the statements are executed directly on the database. # # 2) a single patchset is collected while executing the statements and # then applied to a copy of the original database file. # # 3) individual patchsets are collected for statement while executing # them and concatenated together before being applied to a copy of # the original database. The concatenation is done in a couple of # different ways - linear, pairwise etc. # # All tests, as it happens, are run with both changesets and patchsets. # But the focus is on patchset capabilities. # # Return a checksum of the contents of the database file. Implicit IPK # columns are not included in the checksum - just modifying rowids does # not change the database checksum. # proc databasecksum {db} { set alltab [$db eval {SELECT name FROM sqlite_master WHERE type='table'}] foreach tab $alltab { $db eval "SELECT * FROM $tab LIMIT 1" res { } set slist [list] foreach col [lsort $res(*)] { lappend slist "quote($col)" } set sql "SELECT [join $slist ,] FROM $tab" append txt "[lsort [$db eval $sql]]\n" } return [md5 $txt] } proc do_patchset_test {tn tstcmd lSql} { if {$tstcmd != "patchset" && $tstcmd != "changeset"} { error "have $tstcmd: must be patchset or changeset" } foreach fname {test.db2 test.db3 test.db4 test.db5} { forcedelete $fname forcecopy test.db $fname } # Execute the SQL statements on [db]. Collect a patchset for each # individual statement, as well as a single patchset for the entire # operation. sqlite3session S db main S attach * foreach sql $lSql { sqlite3session T db main T attach * db eval $sql lappend lPatch [T patchset] T delete } set patchset [S patchset] S delete # Calculate a checksum for the final database. set cksum [databasecksum db] # 1. Apply the single large patchset to test.db2 sqlite3 db2 test.db2 sqlite3changeset_apply db2 $patchset noop uplevel [list do_test $tn.1 { databasecksum db2 } $cksum ] db2 close # 2. Apply each of the single-statement patchsets to test.db3 sqlite3 db2 test.db3 foreach p $lPatch { sqlite3changeset_apply db2 $p noop } uplevel [list do_test $tn.2 { databasecksum db2 } $cksum ] db2 close # 3. Concatenate all single-statement patchsets into a single large # patchset, then apply it to test.db4. # sqlite3 db2 test.db4 set big "" foreach p $lPatch { set big [sqlite3changeset_concat $big $p] } sqlite3changeset_apply db2 $big noop uplevel [list do_test $tn.3 { databasecksum db2 } $cksum ] db2 close # 4. Concatenate all single-statement patchsets pairwise into a single # large patchset, then apply it to test.db5. Pairwise concatenation: # # a b c d e f g h i j k # -> {a b} {c d} {e f} {g h} {i j} k # -> {a b c d} {e f g h} {i j k} # -> {a b c d e f g h} {i j k} # -> {a b c d e f g h i j k} # -> APPLY! # sqlite3 db2 test.db5 set L $lPatch while {[llength $L] > 1} { set O [list] for {set i 0} {$i < [llength $L]} {incr i 2} { if {$i==[llength $L]-1} { lappend O [lindex $L $i] } else { set i1 [expr $i+1] lappend O [sqlite3changeset_concat [lindex $L $i] [lindex $L $i1]] } } set L $O } sqlite3changeset_apply db2 [lindex $L 0] noop uplevel [list do_test $tn.4 { databasecksum db2 } $cksum ] db2 close } proc do_patchset_changeset_test {tn initsql args} { foreach tstcmd {patchset changeset} { reset_db execsql $initsql foreach sql $args { set lSql [split $sql ";"] uplevel [list do_patchset_test $tn.$tstcmd $tstcmd $lSql] } } } do_patchset_changeset_test 5.1 { CREATE TABLE t1(a PRIMARY KEY, b, c); INSERT INTO t1 VALUES(1, 2, 3); } { INSERT INTO t1 VALUES(4, 5, 6); DELETE FROM t1 WHERE a=1; } { INSERT INTO t1 VALUES(7, 8, 9); UPDATE t1 SET c = 5; INSERT INTO t1 VALUES(10, 11, 12); UPDATE t1 SET c = 6; INSERT INTO t1 VALUES(13, 14, 15); } { UPDATE t1 SET c=c+1; DELETE FROM t1 WHERE (a%2); } do_patchset_changeset_test 5.2 { CREATE TABLE t1(a PRIMARY KEY, b, c); CREATE TABLE t2(a, b, c, d, PRIMARY KEY(c, b)); } { INSERT INTO t1 VALUES(x'00', 0, 'zero'); INSERT INTO t1 VALUES(x'01', 1, 'one'); INSERT INTO t1 VALUES(x'02', 4, 'four'); INSERT INTO t1 VALUES(x'03', 9, 'nine'); INSERT INTO t1 VALUES(x'04', 16, 'sixteen'); INSERT INTO t1 VALUES(x'05', 25, 'twenty-five'); } { UPDATE t1 SET a = b WHERE b<=4; INSERT INTO t2 SELECT NULL, * FROM t1; DELETE FROM t1 WHERE b=25; } { DELETE FROM t2; INSERT INTO t2 SELECT NULL, * FROM t1; DELETE FROM t1; INSERT INTO t1 SELECT b, c, d FROM t2; UPDATE t1 SET b = b+1; UPDATE t1 SET b = b+1; UPDATE t1 SET b = b+1; } finish_test |