Skip to content

Commit 3bf495f

Browse files
committed
Debugging sync test.
1 parent b3b437b commit 3bf495f

File tree

5 files changed

+26
-6
lines changed

5 files changed

+26
-6
lines changed

tests/integration/sync/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ pub async fn assert_local_remote_events_eq(
4848
writer.account_status().await?
4949
};
5050
let remote_status = provider.account_status().await?;
51+
52+
println!("{:#?}", local_status);
53+
println!("{:#?}", remote_status);
54+
5155
assert_eq!(local_status, remote_status);
5256

5357
Ok(())

tests/integration/sync/send_events.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ async fn integration_sync_send_events() -> Result<()> {
4040
let (rx, _handle) = spawn()?;
4141
let _ = rx.await?;
4242

43-
let (mut owner, _, _default_folder, passphrase) =
43+
let (mut owner, _, default_folder, passphrase) =
4444
create_local_account(
4545
"sync_basic_1",
4646
Some(test_data_dir.join("debug"))).await?;
@@ -96,7 +96,8 @@ async fn integration_sync_send_events() -> Result<()> {
9696
// the remote which should create the account on the remote
9797
owner.sync().await?;
9898

99-
let default_folder = owner.default_folder().await.unwrap();
99+
println!("Default folder {}", default_folder.id());
100+
100101
owner.open_folder(&default_folder).await?;
101102
other_owner.open_folder(&default_folder).await?;
102103

@@ -113,7 +114,7 @@ async fn integration_sync_send_events() -> Result<()> {
113114
other_owner
114115
.create_secret(meta, secret, Default::default())
115116
.await?;
116-
117+
117118
// Get the remote out of the owner so we can
118119
// assert on equality between local and remote
119120
let mut provider = owner.delete_remote(&remote_origin).unwrap();

tests/integration/test_utils/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ pub async fn create_local_account(
233233
.save_passphrase(false)
234234
.create_archive(true)
235235
.create_authenticator(false)
236-
.create_contacts(true)
236+
.create_contacts(false)
237237
.create_file_password(true)
238238
},
239239
None,

workspace/net/src/client/provider/remote_provider.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -475,8 +475,9 @@ impl RemoteProvider {
475475

476476
if num_events > 0 {
477477
let patch: Patch = decode(&body).await?;
478-
println!("Apply remote patch to local {:#?}", patch);
479-
panic!("Apply remote events to local");
478+
let events = patch.into_events().await?;
479+
let mut writer = self.local.write().await;
480+
writer.patch(folder, events).await?;
480481
}
481482

482483
Ok(())

workspace/sdk/src/events/mod.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
//! Log and sync events.
22
3+
use crate::{Error, Result};
4+
35
mod audit;
46
mod change;
57
mod event;
@@ -21,3 +23,15 @@ pub use write::WriteEvent;
2123
/// Patch wraps a changeset of events to be sent across the network.
2224
#[derive(Clone, Debug, Default)]
2325
pub struct Patch(pub Vec<EventRecord>);
26+
27+
impl Patch {
28+
/// Convert this patch into a collection of events.
29+
pub async fn into_events(&self) -> Result<Vec<WriteEvent<'static>>> {
30+
let mut events = Vec::new();
31+
for record in &self.0 {
32+
let event = record.decode_event().await?;
33+
events.push(event);
34+
}
35+
Ok(events)
36+
}
37+
}

0 commit comments

Comments
 (0)