Skip to content
This repository was archived by the owner on Sep 12, 2018. It is now read-only.

Commit e7f56e6

Browse files
author
Grisha Kruglov
committed
(to-fold) scratchpad
1 parent c7bab02 commit e7f56e6

2 files changed

Lines changed: 91 additions & 7 deletions

File tree

db/src/timelines.rs

Lines changed: 86 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,91 @@ mod tests {
379379
"#);
380380
}
381381

382+
#[test]
383+
fn test_maybe_buggy() {
384+
let mut conn = TestConn::default();
385+
conn.sanitized_partition_map();
386+
387+
assert_transact!(conn, r#"
388+
[{:db/ident :person/name :db/valueType :db.type/string :db/cardinality :db.cardinality/one}]
389+
"#);
390+
391+
assert_transact!(conn, r#"[{:person/name "Ivan"}]"#);
392+
assert_transact!(conn, r#"[{:person/name "Ivan"}]"#);
393+
394+
assert_transact!(conn, r#"[[:db/add 65537 :person/name "Vanya"]]"#);
395+
396+
// Move the last assertion away from the main timeline.
397+
let (new_schema, new_partition_map) = move_from_main_timeline(
398+
&conn.sqlite, &conn.schema, conn.partition_map.clone(),
399+
conn.last_tx_id().., 1
400+
).expect("moved single tx");
401+
update_conn(&mut conn, &new_schema, &new_partition_map);
402+
403+
// Assert that our datoms are now just the schema.
404+
assert_matches!(conn.datoms(), r#"
405+
[[?e :db/ident :person/name]
406+
[?e :db/valueType :db.type/string]
407+
[?e :db/cardinality :db.cardinality/one]
408+
[65537 :person/name "Ivan"]
409+
[65538 :person/name "Ivan"]]"#);
410+
// Same for transactions.
411+
assert_matches!(conn.transactions(), r#"
412+
[[
413+
[?e :db/ident :person/name ?tx true]
414+
[?e :db/valueType :db.type/string ?tx true]
415+
[?e :db/cardinality :db.cardinality/one ?tx true]
416+
[?tx :db/txInstant ?ms ?tx true]
417+
]
418+
[
419+
[65537 :person/name "Ivan" ?tx2 true]
420+
[?tx2 :db/txInstant ?ms2 ?tx2 true]
421+
]
422+
[
423+
[65538 :person/name "Ivan" ?tx3 true]
424+
[?tx3 :db/txInstant ?ms3 ?tx3 true]
425+
]]"#);
426+
427+
assert_transact!(conn, r#"
428+
[[:db/retract 65537 :person/name "Ivan"]]"#);
429+
430+
assert_transact!(conn, r#"
431+
[[:db/retract "65537" :person/name "Ivan"]
432+
[:db/add "65537" :person/name "Vanya"]]"#);
433+
434+
// Assert that our datoms are now the schema and the final assertion.
435+
assert_matches!(conn.datoms(), r#"
436+
[[?e1 :db/ident :person/name]
437+
[?e1 :db/valueType :db.type/string]
438+
[?e1 :db/cardinality :db.cardinality/one]
439+
[65538 :person/name "Ivan"]
440+
[65539 :person/name "Vanya"]]
441+
"#);
442+
443+
// Assert that we have three correct looking transactions.
444+
// This will fail if we're not cleaning up the 'datoms' table
445+
// after the timeline move.
446+
assert_matches!(conn.transactions(), r#"
447+
[[
448+
[?e1 :db/ident :person/name ?tx1 true]
449+
[?e1 :db/valueType :db.type/string ?tx1 true]
450+
[?e1 :db/cardinality :db.cardinality/one ?tx1 true]
451+
[?e1 :db/unique :db.unique/identity ?tx1 true]
452+
[?e1 :db/index true ?tx1 true]
453+
[?tx1 :db/txInstant ?ms1 ?tx1 true]
454+
]
455+
[
456+
[?e2 :person/name "Vanya" ?tx2 true]
457+
[?tx2 :db/txInstant ?ms2 ?tx2 true]
458+
]
459+
[
460+
[?e2 :person/name "Ivan" ?tx3 true]
461+
[?e2 :person/name "Vanya" ?tx3 false]
462+
[?tx3 :db/txInstant ?ms3 ?tx3 true]
463+
]]
464+
"#);
465+
}
466+
382467
#[test]
383468
fn test_pop_schema() {
384469
let mut conn = TestConn::default();
@@ -494,7 +579,7 @@ mod tests {
494579
"#);
495580
}
496581

497-
#[test]
582+
#[test]
498583
fn test_pop_schema_all_attributes_component() {
499584
let mut conn = TestConn::default();
500585
conn.sanitized_partition_map();

tests/tolstoy.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,7 +1010,7 @@ mod tolstoy_tests {
10101010
assert_sync!(SyncReport::RemoteFastForward, conn_1, sqlite_1, remote_client);
10111011

10121012
// Merge bootstrap+schema transactions from 1 into 2.
1013-
// Will result in two Ivans.
1013+
// Merge will result in two Ivans.
10141014
assert_sync!(SyncReport::Merge(SyncFollowup::FullSync), conn_2, sqlite_2, remote_client);
10151015
// Upload the second Ivan.
10161016
assert_sync!(SyncReport::RemoteFastForward, conn_2, sqlite_2, remote_client);
@@ -1026,12 +1026,12 @@ mod tolstoy_tests {
10261026

10271027
// Second renames an Ivan.
10281028
conn_2.transact(&mut sqlite_2, r#"[
1029-
{:db/id 65537 :person/name "Vanya"}]"#).expect("transacted");
1029+
[:db/add 65537 :person/name "Vanya"]]"#).expect("transacted");
10301030

1031-
// First syncs first.
1031+
// First wins the sync race.
10321032
assert_sync!(SyncReport::RemoteFastForward, conn_1, sqlite_1, remote_client);
10331033

1034-
// And now, merge!
1034+
// Second merges its changes with first's.
10351035
assert_sync!(SyncReport::Merge(SyncFollowup::FullSync), conn_2, sqlite_2, remote_client);
10361036

10371037
// We currently have a primitive conflict resolution strategy,
@@ -1055,8 +1055,7 @@ mod tolstoy_tests {
10551055
[?tx :db/txInstant ?ms ?tx true]]"#);
10561056

10571057
assert_matches!(parts_to_datoms(&conn_2.current_schema(), &synced_txs_2[4].parts), r#"[
1058-
[65538 :person/name "Ivan" ?tx false]
1059-
[65538 :person/name "Vanya" ?tx true]
1058+
[65539 :person/name "Vanya" ?tx true]
10601059
[?tx :db/txInstant ?ms ?tx true]]"#);
10611060
}
10621061

0 commit comments

Comments
 (0)