Skip to content

Commit

Permalink
Merge pull request #397 from btpworks/fix/sleep-coverage-in-snapshot-…
Browse files Browse the repository at this point in the history
…tests

test: backport sleep coverage and determinism support
  • Loading branch information
suchapalaver authored Jul 22, 2023
2 parents 1de3a10 + 06c2e90 commit 3ff9cb9
Show file tree
Hide file tree
Showing 12 changed files with 181 additions and 122 deletions.
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ insta = { version = "1.26.0", features = ["redactions", "toml"] }
iref = "2.2"
iref-enum = "2.1"
json-ld = { version = "0.14" }
json-syntax = { version = "*", features = ["serde", "serde_json"] }
json-syntax = { version = "0.9", features = ["serde", "serde_json"] }
jsonschema = "0.17.0"
jwtk = { version = "0.2.4", features = ["remote-jwks"] }
k256 = { version = "0.11.3", features = [
Expand All @@ -79,7 +79,7 @@ mime = "0.3"
mockito = "1.0.2"
oauth2 = "4.4"
opa = "0.9.0"
openssl = "0.10.48"
openssl = "0.10.55"
opentelemetry = { version = "0.18.0", features = ["rt-tokio"] }
opentelemetry-jaeger = { version = "0.17.0", features = [
"rt-tokio",
Expand Down Expand Up @@ -120,7 +120,7 @@ structopt = "0.3.26"
temp-dir = "0.1.11"
tempfile = "3.4.0"
testcontainers = "0.14"
thiserror = "1.0.38"
thiserror = "1.0"
tokio = { version = "1.27", features = [
"time",
"macros",
Expand Down
6 changes: 3 additions & 3 deletions crates/api/src/chronicle_graphql/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ use common::{
ledger::{SubmissionError, SubmissionStage},
opa::{ExecutorContext, OpaExecutorError},
prov::{
to_json_ld::ToJson, ChronicleIri, ChronicleTransactionId, CompactedJson, ExternalId,
ExternalIdPart, ProvModel,
to_json_ld::ToJson, ChronicleIri, ChronicleTransactionId, ExternalId, ExternalIdPart,
ProvModel,
},
};
use derivative::*;
Expand Down Expand Up @@ -839,7 +839,7 @@ impl IriEndpoint {
Ok(()) => match self.store.connection() {
Ok(connection) => match retrieve(connection, id, ns) {
Ok(data) => match data.to_json().compact().await {
Ok(CompactedJson(mut json)) => {
Ok(mut json) => {
use serde_json::Value;
if let Value::Object(mut map) = json {
map.insert(
Expand Down
12 changes: 9 additions & 3 deletions crates/api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ where
signer: signing.clone(),
ledger_writer: Arc::new(BlockingLedgerWriter::new(ledger)),
store: store.clone(),
uuid_source: PhantomData::default(),
uuid_source: PhantomData,
policy_name,
};

Expand Down Expand Up @@ -338,7 +338,7 @@ where
Some((ChronicleOperationEvent(Ok(ref commit), id,),tx,block_id,_position,_span )) => {

debug!(committed = ?tx);
debug!(delta = %commit.to_json().compact().await.unwrap().pretty());
debug!(delta = %serde_json::to_string_pretty(&commit.to_json().compact().await.unwrap()).unwrap());

api.sync( commit.clone().into(), &block_id,ChronicleTransactionId::from(tx.as_str()))
.instrument(info_span!("Incoming confirmation", offset = ?block_id, tx_id = %tx))
Expand Down Expand Up @@ -1610,7 +1610,7 @@ mod test {
use rand_core::SeedableRng;
use sawtooth_sdk::messages::setting::{Setting, Setting_Entry};

use std::collections::HashMap;
use std::{collections::HashMap, time::Duration};
use tempfile::TempDir;
use uuid::Uuid;

Expand Down Expand Up @@ -1892,6 +1892,8 @@ mod test {
}
"###);

tokio::time::sleep(Duration::from_millis(1000)).await;

// Check that the operations that do not result in data changes are not submitted
insta::assert_json_snapshot!(api
.dispatch(ApiCommand::Import(ImportCommand { namespace, operations } ), identity)
Expand Down Expand Up @@ -2256,6 +2258,8 @@ mod test {
.await
.unwrap();

tokio::time::sleep(Duration::from_millis(1000)).await;

insta::assert_json_snapshot!(
api.dispatch(ApiCommand::Activity(ActivityCommand::Start {
id: ActivityId::from_external_id("testactivity"),
Expand Down Expand Up @@ -2362,6 +2366,8 @@ mod test {
}
"###);

tokio::time::sleep(Duration::from_millis(1000)).await;

let res = api
.dispatch(
ApiCommand::Agent(AgentCommand::Create {
Expand Down
16 changes: 6 additions & 10 deletions crates/api/src/persistence/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
use std::{
collections::{BTreeMap, HashMap},
str::FromStr,
time::Duration,
};
use std::{collections::BTreeMap, str::FromStr, time::Duration};

use async_sawtooth_sdk::ledger::{BlockId, BlockIdError};
use chrono::DateTime;
Expand Down Expand Up @@ -184,7 +180,7 @@ impl Store {
attributes,
..
}: &Activity,
ns: &HashMap<NamespaceId, Namespace>,
ns: &BTreeMap<NamespaceId, Namespace>,
) -> Result<(), StoreError> {
use schema::activity as dsl;
let _namespace = ns.get(namespaceid).ok_or(StoreError::InvalidNamespace {})?;
Expand Down Expand Up @@ -267,7 +263,7 @@ impl Store {
attributes,
..
}: &Agent,
ns: &HashMap<NamespaceId, Namespace>,
ns: &BTreeMap<NamespaceId, Namespace>,
) -> Result<(), StoreError> {
use schema::agent::dsl;
let _namespace = ns.get(namespaceid).ok_or(StoreError::InvalidNamespace {})?;
Expand Down Expand Up @@ -331,7 +327,7 @@ impl Store {
signature_time,
..
}: &Attachment,
ns: &HashMap<NamespaceId, Namespace>,
ns: &BTreeMap<NamespaceId, Namespace>,
) -> Result<(), StoreError> {
let _namespace = ns.get(namespaceid).ok_or(StoreError::InvalidNamespace {})?;
let (_, nsid) =
Expand Down Expand Up @@ -377,7 +373,7 @@ impl Store {
domaintypeid,
attributes,
}: &Entity,
ns: &HashMap<NamespaceId, Namespace>,
ns: &BTreeMap<NamespaceId, Namespace>,
) -> Result<(), StoreError> {
use schema::entity::dsl;
let _namespace = ns.get(namespaceid).ok_or(StoreError::InvalidNamespace {})?;
Expand Down Expand Up @@ -543,7 +539,7 @@ impl Store {
public_key,
..
}: &Identity,
ns: &HashMap<NamespaceId, Namespace>,
ns: &BTreeMap<NamespaceId, Namespace>,
) -> Result<(), StoreError> {
use schema::identity::dsl;
let _namespace = ns.get(namespaceid).ok_or(StoreError::InvalidNamespace {})?;
Expand Down
4 changes: 2 additions & 2 deletions crates/async-sawtooth-sdk/src/ledger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -364,8 +364,8 @@ impl<
builder,
channel,
last_seen_block: Default::default(),
_e: std::marker::PhantomData::default(),
_t: std::marker::PhantomData::default(),
_e: std::marker::PhantomData,
_t: std::marker::PhantomData,
}
}

Expand Down
Loading

0 comments on commit 3ff9cb9

Please sign in to comment.