node: inspect outdated sigrefs test

This test is flakey and requires further investigation. Some extra
assertions are added to ensure that the expected behaviour is
happening upon fetching. It is unknown if the fetch queue is behaving
properly, and it's suspected that some existing fetch results might be
used for queued fetches.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
This commit is contained in:
Fintan Halpenny 2023-12-15 13:41:51 +00:00 committed by cloudhead
parent 48aa725bea
commit a6ba1b0103
No known key found for this signature in database
4 changed files with 59 additions and 8 deletions

View File

@ -901,12 +901,12 @@ where
}
for sub in &fetching.subscribers {
debug!(target: "service", "Found existing fetch request, sending result..");
debug!(target: "service", "Found existing fetch request from {remote}, sending result..");
if sub.send(result.clone()).is_err() {
error!(target: "service", "Error sending fetch result for {rid}..");
error!(target: "service", "Error sending fetch result for {rid} from {remote}..");
} else {
debug!(target: "service", "Sent fetch result for {rid}..");
debug!(target: "service", "Sent fetch result for {rid} from {remote}..");
}
}

View File

@ -842,7 +842,24 @@ fn test_non_fastforward_sigrefs() {
// Eve fetches the inital project from Bob.
eve.handle.fetch(rid, bob.id, DEFAULT_TIMEOUT).unwrap();
// Alice fetches it too.
alice.handle.fetch(rid, bob.id, DEFAULT_TIMEOUT).unwrap();
let old_bob = alice.handle.fetch(rid, bob.id, DEFAULT_TIMEOUT).unwrap();
let bob_sigrefs = bob
.storage
.repository(rid)
.unwrap()
.reference_oid(&bob.id, &radicle::storage::refs::SIGREFS_BRANCH)
.unwrap();
let up = old_bob
.find_updated(
&(*radicle::storage::refs::Special::SignedRefs.namespaced(&bob.id)).to_ref_string(),
)
.unwrap();
let old_bob = match up {
RefUpdate::Created { oid, .. } => oid,
RefUpdate::Skipped { oid, .. } => oid,
_ => panic!("rad/sigrefs should have been created or skipped: {:?}", up),
};
assert_eq!(bob_sigrefs, old_bob);
// Log the before Oid value of bob's 'rad/sigrefs', for debugging purposes.
{
@ -867,7 +884,25 @@ fn test_non_fastforward_sigrefs() {
"Updated sigrefs are harshing my vibes",
);
// Alice fetches from Bob.
alice.handle.fetch(rid, bob.id, DEFAULT_TIMEOUT).unwrap();
let new_bob = alice.handle.fetch(rid, bob.id, DEFAULT_TIMEOUT).unwrap();
let bob_sigrefs = bob
.storage
.repository(rid)
.unwrap()
.reference_oid(&bob.id, &radicle::storage::refs::SIGREFS_BRANCH)
.unwrap();
let up = new_bob
.find_updated(
&(*radicle::storage::refs::Special::SignedRefs.namespaced(&bob.id)).to_ref_string(),
)
.unwrap();
let new_bob = match up {
RefUpdate::Updated { new, .. } => new,
// FIXME: Really it shouldn't be skipped but let's see what happens
RefUpdate::Skipped { oid, .. } => oid,
_ => panic!("rad/sigrefs should have been updated {:?}", up),
};
assert_eq!(bob_sigrefs, new_bob);
// Log the after Oid value of bob's 'rad/sigrefs', for debugging purposes.
{
@ -877,11 +912,9 @@ fn test_non_fastforward_sigrefs() {
.unwrap()
.reference_oid(&bob.id, &radicle::storage::refs::SIGREFS_BRANCH)
.unwrap();
log::debug!(target: "test", "bob's old 'rad/sigrefs': {}", after);
log::debug!(target: "test", "bob's new 'rad/sigrefs': {}", after);
}
// Now Alice has the latest, and when she tries to fetch from Eve, it breaks because
// Eve has old refs.
assert_matches!(
alice.handle.fetch(rid, eve.id, DEFAULT_TIMEOUT).unwrap(),
FetchResult::Success { updated, .. } if updated.is_empty()

View File

@ -24,6 +24,7 @@ use serde::{Deserialize, Serialize};
use serde_json as json;
use crate::crypto::PublicKey;
use crate::git;
use crate::identity::Id;
use crate::profile;
use crate::storage::refs::RefsAt;
@ -655,6 +656,14 @@ impl FetchResult {
_ => None,
}
}
pub fn find_updated(&self, name: &git::RefString) -> Option<RefUpdate> {
let updated = match self {
Self::Success { updated, .. } => Some(updated),
_ => None,
}?;
updated.iter().find(|up| up.name() == name).cloned()
}
}
impl<S: ToString> From<Result<(Vec<RefUpdate>, HashSet<NodeId>), S>> for FetchResult {

View File

@ -170,6 +170,15 @@ impl RefUpdate {
Self::Skipped { name, oid: old }
}
}
pub fn name(&self) -> &RefString {
match &self {
RefUpdate::Updated { name, .. } => name,
RefUpdate::Created { name, .. } => name,
RefUpdate::Deleted { name, .. } => name,
RefUpdate::Skipped { name, .. } => name,
}
}
}
impl fmt::Display for RefUpdate {