Skip to content

Commit

Permalink
more rustdoc
Browse files Browse the repository at this point in the history
  • Loading branch information
Dav1dde committed Oct 24, 2024
1 parent 869b215 commit 8314334
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
16 changes: 16 additions & 0 deletions relay-server/src/services/projects/cache/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ use super::state::Shared;
use crate::services::projects::cache::service::ProjectEvent;
use crate::services::projects::cache::{Project, ProjectCache};

/// A synchronous handle to the [`ProjectCache`].
///
/// The handle allows lock free access to cached projects. It also acts as an interface
/// to the [`ProjectCacheService`](super::ProjectCacheService).
#[derive(Clone)]
pub struct ProjectCacheHandle {
pub(super) shared: Arc<Shared>,
Expand Down Expand Up @@ -56,6 +60,9 @@ mod test {
use crate::services::projects::project::ProjectState;

impl ProjectCacheHandle {
/// Creates a new [`ProjectCacheHandle`] for testing only.
///
/// A project cache handle created this way does not require a service to function.
pub fn for_test() -> Self {
Self {
shared: Default::default(),
Expand All @@ -65,6 +72,9 @@ mod test {
}
}

/// Sets the project state for a project.
///
/// This can be used to emulate a project cache update in tests.
pub fn test_set_project_state(&self, project_key: ProjectKey, state: ProjectState) {
let is_pending = state.is_pending();
self.shared.test_set_project_state(project_key, state);
Expand All @@ -75,10 +85,16 @@ mod test {
}
}

/// Returns `true` if there is a project created for this `project_key`.
///
/// A project is automatically created on access via [`Self::get`].
pub fn test_has_project_created(&self, project_key: ProjectKey) -> bool {
self.shared.test_has_project_created(project_key)
}

/// The amount of fetches triggered for projects.
///
/// A fetch is triggered for both [`Self::get`] and [`Self::fetch`].
pub fn test_num_fetches(&self) -> u64 {
self.service.len()
}
Expand Down
3 changes: 3 additions & 0 deletions relay-server/src/services/projects/cache/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,17 @@ impl<'a> Project<'a> {
Self { shared, config }
}

/// Returns a reference to the currently cached project state.
pub fn project_state(&self) -> &ProjectState {
self.shared.project_state()
}

/// Returns a reference to the currently cached rate limits.
pub fn rate_limits(&self) -> &CachedRateLimits {
self.shared.cached_rate_limits()
}

/// Returns a reference to the currently reservoir counters.
pub fn reservoir_counters(&self) -> &ReservoirCounters {
self.shared.reservoir_counters()
}
Expand Down
1 change: 1 addition & 0 deletions relay-server/src/services/projects/cache/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ impl Shared {
.set_project_state(state);
}

/// Returns `true` if there exists a shared state for the passed `project_key`.
pub fn test_has_project_created(&self, project_key: ProjectKey) -> bool {
self.projects.pin().contains_key(&project_key)
}
Expand Down

0 comments on commit 8314334

Please sign in to comment.