Skip to content

Commit

Permalink
Merge branch 'develop' into call
Browse files Browse the repository at this point in the history
  • Loading branch information
freesig committed Nov 5, 2020
2 parents 9339d10 + 9273239 commit 0db6a8f
Show file tree
Hide file tree
Showing 10 changed files with 275 additions and 242 deletions.
30 changes: 3 additions & 27 deletions crates/holochain/src/conductor/cell/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@ use crate::{
conductor::manager::spawn_task_manager,
core::workflow::incoming_dht_ops_workflow::IncomingDhtOpsWorkspace,
fixt::{DnaFileFixturator, SignatureFixturator},
test_utils::test_network,
};
use ::fixt::prelude::*;
use futures::future::FutureExt;
use ghost_actor::GhostControlSender;
use holo_hash::HasHash;
use holochain_p2p::actor::HolochainP2pRefToCell;
use holochain_state::test_utils::{test_cell_env, TestEnvironment};
use holochain_types::{
dht_op::{DhtOp, DhtOpHashed},
Expand All @@ -24,32 +22,13 @@ async fn test_cell_handle_publish() {
env,
tmpdir: _tmpdir,
} = test_cell_env();
let (holochain_p2p, mut p2p_evt) =
holochain_p2p::spawn_holochain_p2p(holochain_p2p::kitsune_p2p::KitsuneP2pConfig::default())
.await
.unwrap();

let r_task = tokio::task::spawn(async move {
use tokio::stream::StreamExt;
while let Some(evt) = p2p_evt.next().await {
use holochain_p2p::event::HolochainP2pEvent::*;
match evt {
SignNetworkData { respond, .. } => {
respond.r(Ok(async move { Ok(vec![0; 64].into()) }.boxed().into()));
}
PutAgentInfoSigned { respond, .. } => {
respond.r(Ok(async move { Ok(()) }.boxed().into()));
}
_ => (),
}
}
});

let cell_id = fake_cell_id(1);
let dna = cell_id.dna_hash().clone();
let agent = cell_id.agent_pubkey().clone();

let holochain_p2p_cell = holochain_p2p.clone().to_cell(dna.clone(), agent.clone());
let test_network = test_network(Some(dna.clone()), Some(agent.clone())).await;
let holochain_p2p_cell = test_network.cell_network();

let mut mock_handler = crate::conductor::handle::MockConductorHandleT::new();
mock_handler
Expand Down Expand Up @@ -102,7 +81,4 @@ async fn test_cell_handle_publish() {

stop_tx.send(()).unwrap();
shutdown.await.unwrap();

holochain_p2p.ghost_actor_shutdown().await.unwrap();
r_task.await.unwrap();
}
22 changes: 13 additions & 9 deletions crates/holochain/src/conductor/compat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ pub async fn load_conductor_from_legacy_config(
}
let mut app_install_payload = Vec::new();

let mut agent_list: HashMap<String, AgentPubKey> = HashMap::new();
for i in &legacy.instances {
let dna_config = legacy.dna_by_id(&i.dna).ok_or_else(|| {
CompatConfigError::BrokenReference(format!("No DNA for id: {}", i.dna))
Expand All @@ -86,13 +87,16 @@ pub async fn load_conductor_from_legacy_config(
})?
.clone();

// FIXME [ B-01893 ]:
// currently we can't specify a seed for generating a keypair
// via TestKeystore, so for now we are limited to generating a
// unique agent every time. Once we have same-agent tests, this will
// have to be addressed.
let _agent_name = i.agent.clone();
let agent_pubkey = keystore.generate_sign_keypair_from_pure_entropy().await?;
let agent_name = i.agent.clone();
// make sure we create new pubkey for new agents.
let agent_pubkey = match agent_list.get(&agent_name) {
Some(pubkey) => pubkey.clone(),
_ => {
let pubkey = keystore.generate_sign_keypair_from_pure_entropy().await?;
agent_list.insert(agent_name, pubkey.clone());
pubkey
}
};
let cell_id = CellId::new(dna_hash, agent_pubkey.clone());
let cell_handle = i.id.clone();
app_install_payload.push((InstalledCell::new(cell_id, cell_handle), None));
Expand Down Expand Up @@ -229,13 +233,13 @@ pub mod tests {
];
let instances = vec![
legacy::InstanceConfig {
agent: "".to_string(),
agent: "ag1".to_string(),
dna: "a1".to_string(),
id: "i1".to_string(),
storage: legacy::StorageConfiguration::Memory,
},
legacy::InstanceConfig {
agent: "".to_string(),
agent: "ag2".to_string(),
dna: "a2".to_string(),
id: "i2".to_string(),
storage: legacy::StorageConfiguration::Memory,
Expand Down
6 changes: 1 addition & 5 deletions crates/holochain/src/conductor/conductor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1064,11 +1064,7 @@ pub mod tests {
} = test_p2p_env();
let dna_store = MockDnaStore::new();
let keystore = environment.keystore().clone();
let (holochain_p2p, _p2p_evt) = holochain_p2p::spawn_holochain_p2p(
holochain_p2p::kitsune_p2p::KitsuneP2pConfig::default(),
)
.await
.unwrap();
let holochain_p2p = holochain_p2p::stub_network().await;
let conductor = Conductor::new(
environment,
wasm_env,
Expand Down
6 changes: 2 additions & 4 deletions crates/holochain/src/core/ribosome.rs
Original file line number Diff line number Diff line change
Expand Up @@ -555,11 +555,12 @@ pub mod wasm_test {
.unwrap();

// Required because otherwise the network will return routing errors
let (network, r_task, cell_network) = crate::test_utils::test_network(
let test_network = crate::test_utils::test_network(
Some(ribosome.dna_file().dna_hash().clone()),
Some(author),
)
.await;
let cell_network = test_network.cell_network();
let cell_id = holochain_types::cell::CellId::new(
cell_network.dna_hash(),
cell_network.from_agent(),
Expand Down Expand Up @@ -591,9 +592,6 @@ pub mod wasm_test {
}
crate::core::ribosome::ZomeCallResponse::Unauthorized => unreachable!(),
};
use ghost_actor::GhostControlSender;
network.ghost_actor_shutdown().await.unwrap();
r_task.await.unwrap();
output
})
.await
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

use super::*;

use crate::fixt::CallContextFixturator;
use crate::fixt::ZomeCallHostAccessFixturator;
use crate::here;
use crate::{
Expand All @@ -13,8 +12,8 @@ use crate::{
workflow::CallZomeWorkspaceLock,
},
fixt::*,
test_utils::test_network,
};
use crate::{fixt::CallContextFixturator, test_utils::test_network};
use ::fixt::prelude::*;
use holo_hash::*;
use holochain_state::{
Expand Down Expand Up @@ -1041,7 +1040,7 @@ async fn get_links(
.zomes
.push((zome_name.clone().into(), fixt!(Zome)));

let (_network, _r, cell_network) = test_network(Some(dna_file.dna_hash().clone()), None).await;
let test_network = test_network(Some(dna_file.dna_hash().clone()), None).await;

// Create ribosome mock to return fixtures
// This is a lot faster then compiling a zome
Expand All @@ -1060,7 +1059,7 @@ async fn get_links(
let output = {
let mut host_access = fixt!(ZomeCallHostAccess);
host_access.workspace = workspace_lock;
host_access.network = cell_network;
host_access.network = test_network.cell_network();
call_context.host_access = host_access.into();
let ribosome = Arc::new(ribosome);
let call_context = Arc::new(call_context);
Expand Down
90 changes: 43 additions & 47 deletions crates/holochain/src/core/workflow/publish_dht_ops_workflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,15 +183,12 @@ mod tests {
SourceChainError,
},
fixt::{CreateLinkFixturator, EntryFixturator},
test_utils::{test_network_with_events, TestNetwork},
};
use ::fixt::prelude::*;
use futures::future::FutureExt;
use ghost_actor::GhostControlSender;
use holo_hash::fixt::*;
use holochain_p2p::{
actor::{HolochainP2p, HolochainP2pRefToCell, HolochainP2pSender},
spawn_holochain_p2p, HolochainP2pRef,
};
use holochain_p2p::{actor::HolochainP2pSender, HolochainP2pRef};
use holochain_state::{
buffer::BufferedStore,
env::{EnvironmentWrite, ReadManager, WriteManager},
Expand Down Expand Up @@ -231,7 +228,7 @@ mod tests {
num_hash: u32,
panic_on_publish: bool,
) -> (
ghost_actor::GhostSender<HolochainP2p>,
TestNetwork,
HolochainP2pCell,
JoinHandle<()>,
tokio::sync::oneshot::Receiver<()>,
Expand Down Expand Up @@ -290,12 +287,21 @@ mod tests {
.collect::<Vec<_>>();

// Create the network
let (network, mut recv) =
spawn_holochain_p2p(holochain_p2p::kitsune_p2p::KitsuneP2pConfig::default())
.await
.unwrap();
let filter_events = |evt: &_| match evt {
holochain_p2p::event::HolochainP2pEvent::Publish { .. } => true,
_ => false,
};
let (tx, mut recv) = tokio::sync::mpsc::channel(10);
let test_network = test_network_with_events(
Some(dna.clone()),
Some(agents[0].clone()),
filter_events,
tx,
)
.await;
let (tx_complete, rx_complete) = tokio::sync::oneshot::channel();
let cell_network = network.to_cell(dna.clone(), agents[0].clone());
let cell_network = test_network.cell_network();
let network = test_network.network();
let mut recv_count: u32 = 0;
let total_expected = num_agents * num_hash;

Expand All @@ -319,26 +325,21 @@ mod tests {
break;
}
}
SignNetworkData { respond, .. } => {
respond.r(Ok(async move { Ok(vec![0; 64].into()) }.boxed().into()));
}
PutAgentInfoSigned { respond, .. } => {
respond.r(Ok(async move { Ok(()) }.boxed().into()));
}
_ => (),
}
}
}
});

// Join some agents onto the network
for agent in agents {
// Skip the first agent as it has already joined
for agent in agents.into_iter().skip(1) {
HolochainP2pRef::join(&network, dna.clone(), agent)
.await
.unwrap();
}

(network, cell_network, recv_task, rx_complete)
(test_network, cell_network, recv_task, rx_complete)
}

/// Call the workflow
Expand Down Expand Up @@ -368,7 +369,7 @@ mod tests {
let env = test_env.env();

// Setup
let (network, cell_network, recv_task, rx_complete) =
let (_network, cell_network, recv_task, rx_complete) =
setup(env.clone(), num_agents, num_hash, false).await;

call_workflow(env.clone().into(), cell_network).await;
Expand All @@ -393,9 +394,6 @@ mod tests {
};

// Shutdown
tokio::time::timeout(Duration::from_secs(10), network.ghost_actor_shutdown())
.await
.ok();
tokio::time::timeout(Duration::from_secs(10), check)
.await
.ok();
Expand Down Expand Up @@ -423,7 +421,7 @@ mod tests {
let env_ref = env.guard();

// Setup
let (network, cell_network, recv_task, _) =
let (_network, cell_network, recv_task, _) =
setup(env.clone(), num_agents, num_hash, true).await;

// Update the authored to have > R counts
Expand Down Expand Up @@ -466,9 +464,6 @@ mod tests {
.await;

// Shutdown
tokio::time::timeout(Duration::from_secs(10), network.ghost_actor_shutdown())
.await
.ok();
tokio::time::timeout(Duration::from_secs(10), recv_task)
.await
.ok();
Expand Down Expand Up @@ -683,11 +678,20 @@ mod tests {
.collect::<Vec<_>>();

// Create the network
let (network, mut recv) =
spawn_holochain_p2p(holochain_p2p::kitsune_p2p::KitsuneP2pConfig::default())
.await
.unwrap();
let cell_network = network.to_cell(dna.clone(), agents[0].clone());

let filter_events = |evt: &_| match evt {
holochain_p2p::event::HolochainP2pEvent::Publish { .. } => true,
_ => false,
};
let (tx, mut recv) = tokio::sync::mpsc::channel(10);
let test_network = test_network_with_events(
Some(dna.clone()),
Some(agents[0].clone()),
filter_events,
tx,
)
.await;
let cell_network = test_network.cell_network();
let (tx_complete, rx_complete) = tokio::sync::oneshot::channel();
// We are expecting five ops per agent
let total_expected = num_agents * 6;
Expand Down Expand Up @@ -730,14 +734,6 @@ mod tests {
tx_complete.take().unwrap().send(()).unwrap();
}
}
SignNetworkData { respond, .. } => {
respond.r(Ok(async move { Ok(vec![0; 64].into()) }
.boxed()
.into()));
}
PutAgentInfoSigned { respond, .. } => {
respond.r(Ok(async move { Ok(()) }.boxed().into()));
}
_ => (),
}
}
Expand All @@ -746,10 +742,13 @@ mod tests {
});

// Join some agents onto the network
for agent in agents {
HolochainP2pRef::join(&network, dna.clone(), agent)
.await
.unwrap()
{
let network = test_network.network();
for agent in agents {
HolochainP2pRef::join(&network, dna.clone(), agent)
.await
.unwrap()
}
}

call_workflow(env.clone().into(), cell_network).await;
Expand Down Expand Up @@ -778,9 +777,6 @@ mod tests {
);

// Shutdown
tokio::time::timeout(Duration::from_secs(10), network.ghost_actor_shutdown())
.await
.ok();
tokio::time::timeout(Duration::from_secs(10), recv_task)
.await
.ok();
Expand Down

1 comment on commit 0db6a8f

@thedavidmeister
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmarking wasm_call_n/1: Analyzing
wasm_call_n/1           time:   [1.5745 ms 1.5827 ms 1.5914 ms]
                        thrpt:  [628.38   B/s 631.84   B/s 635.13   B/s]
                 change:
                        time:   [-0.7553% -0.1910% +0.4434%] (p = 0.53 > 0.05)
                        thrpt:  [-0.4415% +0.1914% +0.7610%]
                        No change in performance detected.
Found 4 outliers among 100 measurements (4.00%)
  3 (3.00%) high mild
  1 (1.00%) high severe
Benchmarking wasm_call_n/1000
Benchmarking wasm_call_n/1000: Analyzing
wasm_call_n/1000        time:   [1.6551 ms 1.6576 ms 1.6609 ms]
                        thrpt:  [587.98 KiB/s 589.15 KiB/s 590.02 KiB/s]
                 change:
                        time:   [-0.8862% -0.5606% -0.2523%] (p = 0.00 < 0.05)
                        thrpt:  [+0.2529% +0.5638% +0.8941%]
                        Change within noise threshold.
Found 8 outliers among 100 measurements (8.00%)
  2 (2.00%) low severe
  2 (2.00%) low mild
  2 (2.00%) high mild
  2 (2.00%) high severe
Benchmarking wasm_call_n/1000000
Benchmarking wasm_call_n/1000000: Analyzing
wasm_call_n/1000000     time:   [28.253 ms 28.350 ms 28.456 ms]
                        thrpt:  [33.514 MiB/s 33.640 MiB/s 33.755 MiB/s]
                 change:
                        time:   [-0.7132% -0.2164% +0.3004%] (p = 0.41 > 0.05)
                        thrpt:  [-0.2995% +0.2169% +0.7184%]
                        No change in performance detected.
Found 12 outliers among 100 measurements (12.00%)
  12 (12.00%) high mild```

Please sign in to comment.