feat(server): add tracing spans and caching to archive and blame services
- Add tracing spans with repo labels for archive and blame operations - Implement caching for archive list entries when using OID selectors - Implement caching for blame operations when using OID selectors - Add detailed
This commit is contained in:
+90
-58
@@ -1,13 +1,23 @@
|
||||
mod common;
|
||||
|
||||
use gitks::pb::commit_service_server::CommitService;
|
||||
use gitks::pb::diff_service_server::DiffService;
|
||||
use gitks::pb::*;
|
||||
|
||||
#[test]
|
||||
fn test_get_diff() {
|
||||
let (_dir, gb) = common::setup_bare_repo();
|
||||
let result = gb
|
||||
.get_diff(GetDiffRequest {
|
||||
repository: None,
|
||||
fn hdr() -> RepositoryHeader {
|
||||
RepositoryHeader {
|
||||
relative_path: "test-repo".into(),
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_get_diff() {
|
||||
let (dir, _gb) = common::setup_bare_repo();
|
||||
let svc = common::setup_service(dir.path());
|
||||
let result = svc
|
||||
.get_diff(tonic::Request::new(GetDiffRequest {
|
||||
repository: Some(hdr()),
|
||||
base: Some(ObjectSelector {
|
||||
selector: Some(object_selector::Selector::Revision(ObjectName {
|
||||
revision: "main~3".into(),
|
||||
@@ -20,8 +30,10 @@ fn test_get_diff() {
|
||||
}),
|
||||
options: None,
|
||||
pagination: None,
|
||||
})
|
||||
.expect("get_diff");
|
||||
}))
|
||||
.await
|
||||
.unwrap()
|
||||
.into_inner();
|
||||
|
||||
assert!(!result.files.is_empty());
|
||||
let paths: Vec<&str> = result.files.iter().map(|f| f.new_path.as_str()).collect();
|
||||
@@ -34,12 +46,13 @@ fn test_get_diff() {
|
||||
assert!(stats.additions > 0 || stats.changed_files > 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_get_diff_with_patch() {
|
||||
let (_dir, gb) = common::setup_bare_repo();
|
||||
let result = gb
|
||||
.get_diff(GetDiffRequest {
|
||||
repository: None,
|
||||
#[tokio::test]
|
||||
async fn test_get_diff_with_patch() {
|
||||
let (dir, _gb) = common::setup_bare_repo();
|
||||
let svc = common::setup_service(dir.path());
|
||||
let result = svc
|
||||
.get_diff(tonic::Request::new(GetDiffRequest {
|
||||
repository: Some(hdr()),
|
||||
base: Some(ObjectSelector {
|
||||
selector: Some(object_selector::Selector::Revision(ObjectName {
|
||||
revision: "main~1".into(),
|
||||
@@ -56,8 +69,10 @@ fn test_get_diff_with_patch() {
|
||||
..Default::default()
|
||||
}),
|
||||
pagination: None,
|
||||
})
|
||||
.expect("get_diff with patch");
|
||||
}))
|
||||
.await
|
||||
.unwrap()
|
||||
.into_inner();
|
||||
|
||||
assert!(!result.files.is_empty());
|
||||
for file in &result.files {
|
||||
@@ -71,12 +86,13 @@ fn test_get_diff_with_patch() {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_get_diff_with_rename_detection() {
|
||||
let (_dir, gb) = common::setup_bare_repo();
|
||||
#[tokio::test]
|
||||
async fn test_get_diff_with_rename_detection() {
|
||||
let (dir, _gb) = common::setup_bare_repo();
|
||||
let svc = common::setup_service(dir.path());
|
||||
|
||||
gb.create_commit(CreateCommitRequest {
|
||||
repository: None,
|
||||
svc.create_commit(tonic::Request::new(CreateCommitRequest {
|
||||
repository: Some(hdr()),
|
||||
branch: "main".into(),
|
||||
message: "rename file".into(),
|
||||
author: None,
|
||||
@@ -108,12 +124,13 @@ fn test_get_diff_with_rename_detection() {
|
||||
}),
|
||||
force: false,
|
||||
trailers: vec![],
|
||||
})
|
||||
.expect("create rename commit");
|
||||
}))
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let result = gb
|
||||
.get_diff(GetDiffRequest {
|
||||
repository: None,
|
||||
let result = svc
|
||||
.get_diff(tonic::Request::new(GetDiffRequest {
|
||||
repository: Some(hdr()),
|
||||
base: Some(ObjectSelector {
|
||||
selector: Some(object_selector::Selector::Revision(ObjectName {
|
||||
revision: "main~1".into(),
|
||||
@@ -129,8 +146,10 @@ fn test_get_diff_with_rename_detection() {
|
||||
..Default::default()
|
||||
}),
|
||||
pagination: None,
|
||||
})
|
||||
.expect("get_diff with rename detection");
|
||||
}))
|
||||
.await
|
||||
.unwrap()
|
||||
.into_inner();
|
||||
|
||||
let has_rename = result
|
||||
.files
|
||||
@@ -143,12 +162,13 @@ fn test_get_diff_with_rename_detection() {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_get_commit_diff_root() {
|
||||
let (_dir, gb) = common::setup_bare_repo();
|
||||
let commits = gb
|
||||
.list_commits(ListCommitsRequest {
|
||||
repository: None,
|
||||
#[tokio::test]
|
||||
async fn test_get_commit_diff_root() {
|
||||
let (dir, _gb) = common::setup_bare_repo();
|
||||
let svc = common::setup_service(dir.path());
|
||||
let commits = svc
|
||||
.list_commits(tonic::Request::new(ListCommitsRequest {
|
||||
repository: Some(hdr()),
|
||||
revision: Some(ObjectSelector {
|
||||
selector: Some(object_selector::Selector::Revision(ObjectName {
|
||||
revision: "main".into(),
|
||||
@@ -166,13 +186,15 @@ fn test_get_commit_diff_root() {
|
||||
page_size: 1,
|
||||
page_token: String::new(),
|
||||
}),
|
||||
})
|
||||
.expect("list_commits for root");
|
||||
}))
|
||||
.await
|
||||
.unwrap()
|
||||
.into_inner();
|
||||
let root_oid = commits.commits[0].oid.as_ref().unwrap().hex.clone();
|
||||
|
||||
let result = gb
|
||||
.get_commit_diff(GetCommitDiffRequest {
|
||||
repository: None,
|
||||
let result = svc
|
||||
.get_commit_diff(tonic::Request::new(GetCommitDiffRequest {
|
||||
repository: Some(hdr()),
|
||||
commit: Some(ObjectSelector {
|
||||
selector: Some(object_selector::Selector::Revision(ObjectName {
|
||||
revision: root_oid,
|
||||
@@ -180,18 +202,21 @@ fn test_get_commit_diff_root() {
|
||||
}),
|
||||
options: None,
|
||||
pagination: None,
|
||||
})
|
||||
.expect("get_commit_diff on root");
|
||||
}))
|
||||
.await
|
||||
.unwrap()
|
||||
.into_inner();
|
||||
|
||||
assert!(!result.files.is_empty(), "root commit should have files");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_get_diff_stats() {
|
||||
let (_dir, gb) = common::setup_bare_repo();
|
||||
let stats = gb
|
||||
.get_diff_stats(GetDiffStatsRequest {
|
||||
repository: None,
|
||||
#[tokio::test]
|
||||
async fn test_get_diff_stats() {
|
||||
let (dir, _gb) = common::setup_bare_repo();
|
||||
let svc = common::setup_service(dir.path());
|
||||
let stats = svc
|
||||
.get_diff_stats(tonic::Request::new(GetDiffStatsRequest {
|
||||
repository: Some(hdr()),
|
||||
base: Some(ObjectSelector {
|
||||
selector: Some(object_selector::Selector::Revision(ObjectName {
|
||||
revision: "main~3".into(),
|
||||
@@ -203,17 +228,20 @@ fn test_get_diff_stats() {
|
||||
})),
|
||||
}),
|
||||
options: None,
|
||||
})
|
||||
.expect("get_diff_stats");
|
||||
}))
|
||||
.await
|
||||
.unwrap()
|
||||
.into_inner();
|
||||
assert!(stats.additions > 0 || stats.changed_files > 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_get_patch() {
|
||||
let (_dir, gb) = common::setup_bare_repo();
|
||||
let patches = gb
|
||||
.get_patch(GetPatchRequest {
|
||||
repository: None,
|
||||
#[tokio::test]
|
||||
async fn test_get_patch() {
|
||||
let (dir, _gb) = common::setup_bare_repo();
|
||||
let svc = common::setup_service(dir.path());
|
||||
let stream = svc
|
||||
.get_patch(tonic::Request::new(GetPatchRequest {
|
||||
repository: Some(hdr()),
|
||||
base: Some(ObjectSelector {
|
||||
selector: Some(object_selector::Selector::Revision(ObjectName {
|
||||
revision: "main~1".into(),
|
||||
@@ -225,12 +253,16 @@ fn test_get_patch() {
|
||||
})),
|
||||
}),
|
||||
options: None,
|
||||
})
|
||||
.expect("get_patch");
|
||||
}))
|
||||
.await
|
||||
.unwrap()
|
||||
.into_inner();
|
||||
|
||||
let patches: Vec<_> = tokio_stream::StreamExt::collect(stream).await;
|
||||
assert!(!patches.is_empty());
|
||||
let combined: String = patches
|
||||
.iter()
|
||||
.map(|p| String::from_utf8_lossy(&p.data).to_string())
|
||||
.map(|p| String::from_utf8_lossy(&p.as_ref().unwrap().data).to_string())
|
||||
.collect();
|
||||
assert!(combined.contains("diff --git") || combined.contains("@@"));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user