Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use different directories for cluster marker tests #1628

Merged
merged 2 commits into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/admin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ tracing = { workspace = true }

[dev-dependencies]
restate-schema = { workspace = true, features = ["test-util"] }
restate-schema-api = { workspace = true, features = ["mocks"] }
restate-schema-api = { workspace = true, features = ["test-util"] }
restate-test-util = { workspace = true }

tempfile = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion crates/ingress-dispatcher/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ publish = false

[features]
default = []
mocks = ["dep:restate-test-util"]
test-util = ["dep:restate-test-util"]

[dependencies]
restate-bifrost = { workspace = true }
Expand Down
4 changes: 2 additions & 2 deletions crates/ingress-dispatcher/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,8 @@ impl IngressDispatcherRequest {
}
}

#[cfg(feature = "mocks")]
pub mod mocks {
#[cfg(feature = "test-util")]
pub mod test_util {
use super::*;

use crate::error::IngressDispatchError;
Expand Down
4 changes: 2 additions & 2 deletions crates/ingress-http/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ humantime = { workspace = true }

[dev-dependencies]
restate-core = { workspace = true, features = ["test-util"] }
restate-ingress-dispatcher = { workspace = true, features = ["mocks"] }
restate-ingress-dispatcher = { workspace = true, features = ["test-util"] }
restate-test-util = { workspace = true }
restate-types = { workspace = true, features = ["test-util"] }
restate-schema-api = { workspace = true, features = ["mocks"]}
restate-schema-api = { workspace = true, features = ["test-util"]}

hyper = { version = "1.0", features = ["full"] }
hyper-util = { version = "0.1", features = ["full"] }
Expand Down
2 changes: 1 addition & 1 deletion crates/ingress-http/src/handler/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use http::StatusCode;
use http::{Method, Request, Response};
use http_body_util::{BodyExt, Empty, Full};
use restate_core::TestCoreEnv;
use restate_ingress_dispatcher::mocks::MockDispatcher;
use restate_ingress_dispatcher::test_util::MockDispatcher;
use restate_ingress_dispatcher::IngressDispatcherRequest;
use restate_schema_api::invocation_target::{
InputContentType, InputRules, InputValidationRule, InvocationTargetMetadata,
Expand Down
4 changes: 2 additions & 2 deletions crates/ingress-http/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ mod mocks {
use super::*;

use anyhow::Error;
use restate_schema_api::invocation_target::mocks::MockInvocationTargetResolver;
use restate_schema_api::invocation_target::test_util::MockInvocationTargetResolver;
use restate_schema_api::invocation_target::{
InvocationTargetMetadata, InvocationTargetResolver, DEFAULT_IDEMPOTENCY_RETENTION,
};
use restate_schema_api::service::mocks::MockServiceMetadataResolver;
use restate_schema_api::service::test_util::MockServiceMetadataResolver;
use restate_schema_api::service::{HandlerMetadata, ServiceMetadata, ServiceMetadataResolver};
use restate_types::identifiers::DeploymentId;
use restate_types::ingress::InvocationResponse;
Expand Down
2 changes: 1 addition & 1 deletion crates/ingress-http/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ mod tests {
use hyper_util::client::legacy::Client;
use hyper_util::rt::TokioExecutor;
use restate_core::{TaskCenter, TaskKind, TestCoreEnv};
use restate_ingress_dispatcher::mocks::MockDispatcher;
use restate_ingress_dispatcher::test_util::MockDispatcher;
use restate_ingress_dispatcher::{IngressDispatcherRequest, IngressInvocationResponse};
use restate_test_util::assert_eq;
use restate_types::identifiers::InvocationId;
Expand Down
4 changes: 2 additions & 2 deletions crates/ingress-kafka/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ tracing = { workspace = true }
tracing-opentelemetry = { workspace = true }

[dev-dependencies]
restate-ingress-dispatcher = { workspace = true, features = ["mocks"] }
restate-ingress-dispatcher = { workspace = true, features = ["test-util"] }
restate-schema = { workspace = true }
restate-schema-api = { workspace = true, features = ["mocks"] }
restate-schema-api = { workspace = true, features = ["test-util"] }
restate-test-util = { workspace = true }
restate-types = { workspace = true, features = ["test-util"] }

Expand Down
3 changes: 1 addition & 2 deletions crates/invoker-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@ publish = false

[features]
default = []
mocks = []
test-util = ["restate-types/test-util"]
serde = ["dep:serde"]

[dependencies]
restate-errors = { workspace = true }
restate-types = { workspace = true }


anyhow = { workspace = true }
bytes = { workspace = true }
bytestring = { workspace = true }
Expand Down
4 changes: 2 additions & 2 deletions crates/invoker-api/src/entry_enricher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ pub trait EntryEnricher {
) -> Result<EnrichedRawEntry, InvocationError>;
}

#[cfg(any(test, feature = "mocks"))]
pub mod mocks {
#[cfg(any(test, feature = "test-util"))]
pub mod test_util {
use super::*;

use restate_types::identifiers::{InvocationId, InvocationUuid};
Expand Down
4 changes: 2 additions & 2 deletions crates/invoker-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ pub use journal_reader::{JournalMetadata, JournalReader};
pub use state_reader::{EagerState, StateReader};
pub use status_handle::{InvocationErrorReport, InvocationStatusReport, StatusHandle};

#[cfg(any(test, feature = "mocks"))]
pub mod mocks {
#[cfg(any(test, feature = "test-util"))]
pub mod test_util {
use super::*;
use bytes::Bytes;
use restate_types::identifiers::{InvocationId, ServiceId};
Expand Down
4 changes: 2 additions & 2 deletions crates/invoker-api/src/status_handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ pub trait StatusHandle {
) -> impl Future<Output = Self::Iterator> + Send;
}

#[cfg(any(test, feature = "mocks"))]
pub mod mocks {
#[cfg(any(test, feature = "test-util"))]
pub mod test_util {
use super::*;

#[derive(Debug, Clone, Default)]
Expand Down
4 changes: 2 additions & 2 deletions crates/invoker-impl/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ tracing-opentelemetry = { workspace = true }

[dev-dependencies]
restate-core = { workspace = true, features = ["test-util"] }
restate-invoker-api = { workspace = true, features = ["mocks"] }
restate-schema-api = { workspace = true, features = ["mocks"] }
restate-invoker-api = { workspace = true, features = ["test-util"] }
restate-schema-api = { workspace = true, features = ["test-util"] }
restate-service-protocol = { workspace = true, features = ["codec"] }
restate-test-util = { workspace = true }
restate-types = { workspace = true }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ use restate_types::journal::EntryType;
use restate_types::service_protocol::ServiceProtocolVersion;
use std::collections::HashSet;
use std::future::poll_fn;
use tracing::log::warn;
use tracing::{debug, info, trace, Span};
use tracing::{debug, info, trace, warn, Span};
use tracing_opentelemetry::OpenTelemetrySpanExt;

/// Runs the interaction between the server and the service endpoint.
Expand Down
6 changes: 3 additions & 3 deletions crates/invoker-impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1022,7 +1022,7 @@ mod tests {
use bytes::Bytes;
use restate_core::TaskKind;
use restate_core::TestCoreEnv;
use restate_invoker_api::mocks::EmptyStorageReader;
use restate_invoker_api::test_util::EmptyStorageReader;
use restate_types::arc_util::Constant;
use restate_types::config::InvokerOptionsBuilder;
use tempfile::tempdir;
Expand All @@ -1031,7 +1031,7 @@ mod tests {
use tokio_util::sync::CancellationToken;

use restate_invoker_api::{entry_enricher, ServiceHandle};
use restate_schema_api::deployment::mocks::MockDeploymentMetadataRegistry;
use restate_schema_api::deployment::test_util::MockDeploymentMetadataRegistry;
use restate_test_util::{check, let_assert};
use restate_types::identifiers::{LeaderEpoch, PartitionId};
use restate_types::journal::enriched::EnrichedEntryHeader;
Expand Down Expand Up @@ -1162,7 +1162,7 @@ mod tests {
restate_service_client::AssumeRoleCacheMode::None,
)
.unwrap(),
entry_enricher::mocks::MockEntryEnricher,
entry_enricher::test_util::MockEntryEnricher,
);

let mut handle = service.handle();
Expand Down
66 changes: 30 additions & 36 deletions crates/node/src/cluster_marker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,8 @@ mod tests {
use semver::Version;
use std::fs;
use std::fs::OpenOptions;
use std::io::Write;
use std::path::Path;
use tempfile::{tempdir, NamedTempFile};
use tempfile::tempdir;

fn read_cluster_marker(path: impl AsRef<Path>) -> anyhow::Result<ClusterMarker> {
let bytes = fs::read(path)?;
Expand All @@ -248,11 +247,8 @@ mod tests {
cluster_marker: &ClusterMarker,
path: impl AsRef<Path>,
) -> anyhow::Result<()> {
let mut file = OpenOptions::new().create(true).write(true).open(path)?;
let file = OpenOptions::new().create(true).write(true).open(path)?;
serde_json::to_writer(&file, cluster_marker)?;
file.flush()?;
file.sync_all()?;

Ok(())
}

Expand All @@ -263,10 +259,8 @@ mod tests {

#[test]
fn cluster_marker_is_created() {
let file = tempdir()
.unwrap()
.into_path()
.join(CLUSTER_MARKER_FILE_NAME);
let dir = tempdir().unwrap();
let file = dir.path().join(CLUSTER_MARKER_FILE_NAME);
let current_version = Version::new(2, 2, 3);

validate_and_update_cluster_marker_inner(
Expand Down Expand Up @@ -296,7 +290,8 @@ mod tests {

#[test]
fn cluster_marker_is_updated() -> anyhow::Result<()> {
let mut file = NamedTempFile::new().unwrap();
let dir = tempdir().unwrap();
let file = dir.path().join(CLUSTER_MARKER_FILE_NAME);
let previous_version = Version::new(1, 1, 6);
let current_version = Version::new(2, 2, 3);

Expand All @@ -308,20 +303,19 @@ mod tests {
.min_forward_compatible_version
.clone(),
),
file.path(),
&file,
)
.unwrap();
file.flush()?;

validate_and_update_cluster_marker_inner(
CLUSTER_NAME,
current_version.clone(),
file.path(),
&file,
&TESTING_COMPATIBILITY_INFORMATION,
)
.unwrap();

let cluster_marker = read_cluster_marker(file.path()).unwrap();
let cluster_marker = read_cluster_marker(file).unwrap();

assert_eq!(
cluster_marker,
Expand All @@ -341,7 +335,8 @@ mod tests {

#[test]
fn max_version_is_maintained() -> anyhow::Result<()> {
let mut file = NamedTempFile::new().unwrap();
let dir = tempdir().unwrap();
let file = dir.path().join(CLUSTER_MARKER_FILE_NAME);
let max_version = Version::new(2, 2, 6);
let current_version = Version::new(2, 1, 3);

Expand All @@ -353,20 +348,19 @@ mod tests {
.min_forward_compatible_version
.clone(),
),
file.path(),
&file,
)
.unwrap();
file.flush()?;

validate_and_update_cluster_marker_inner(
CLUSTER_NAME,
current_version.clone(),
file.path(),
&file,
&TESTING_COMPATIBILITY_INFORMATION,
)
.unwrap();

let cluster_marker = read_cluster_marker(file.path()).unwrap();
let cluster_marker = read_cluster_marker(file).unwrap();

assert_eq!(
cluster_marker,
Expand All @@ -386,7 +380,8 @@ mod tests {

#[test]
fn incompatible_cluster_name() -> anyhow::Result<()> {
let mut file = NamedTempFile::new().unwrap();
let dir = tempdir().unwrap();
let file = dir.path().join(CLUSTER_MARKER_FILE_NAME);
let max_version = Version::new(2, 2, 6);
let current_version = Version::new(2, 1, 3);

Expand All @@ -398,15 +393,14 @@ mod tests {
.min_forward_compatible_version
.clone(),
),
file.path(),
&file,
)
.unwrap();
file.flush()?;

let result = validate_and_update_cluster_marker_inner(
CLUSTER_NAME,
current_version.clone(),
file.path(),
&file,
&TESTING_COMPATIBILITY_INFORMATION,
);
assert!(matches!(
Expand All @@ -418,7 +412,8 @@ mod tests {

#[test]
fn forward_incompatible_version() -> anyhow::Result<()> {
let mut file = NamedTempFile::new().unwrap();
let dir = tempdir().unwrap();
let file = dir.path().join(CLUSTER_MARKER_FILE_NAME);
let max_version = Version::new(2, 2, 6);
let this_version = Version::new(1, 0, 3);

Expand All @@ -428,15 +423,14 @@ mod tests {
max_version.clone(),
Version::new(2, 0, 0),
),
file.path(),
&file,
)
.unwrap();
file.flush()?;

let result = validate_and_update_cluster_marker_inner(
CLUSTER_NAME,
this_version.clone(),
file.path(),
&file,
&COMPATIBILITY_INFORMATION,
);
assert!(matches!(
Expand All @@ -448,7 +442,8 @@ mod tests {

#[test]
fn backward_incompatible_version() -> anyhow::Result<()> {
let mut file = NamedTempFile::new().unwrap();
let dir = tempdir().unwrap();
let file = dir.path().join(CLUSTER_MARKER_FILE_NAME);
let max_version = Version::new(0, 9, 2);
let this_version = Version::new(2, 1, 1);
write_cluster_marker(
Expand All @@ -457,15 +452,14 @@ mod tests {
max_version.clone(),
Version::new(0, 9, 0),
),
file.path(),
&file,
)
.unwrap();
file.flush()?;

let result = validate_and_update_cluster_marker_inner(
CLUSTER_NAME,
this_version.clone(),
file.path(),
&file,
&COMPATIBILITY_INFORMATION,
);
assert!(matches!(
Expand All @@ -478,7 +472,8 @@ mod tests {

#[test]
fn compatible_version() -> anyhow::Result<()> {
let mut file = NamedTempFile::new().unwrap();
let dir = tempdir().unwrap();
let file = dir.path().join(CLUSTER_MARKER_FILE_NAME);
let max_version = Version::new(2, 0, 2);
let this_version = Version::new(2, 3, 1);
write_cluster_marker(
Expand All @@ -489,15 +484,14 @@ mod tests {
.min_forward_compatible_version
.clone(),
),
file.path(),
&file,
)
.unwrap();
file.flush()?;

let result = validate_and_update_cluster_marker_inner(
CLUSTER_NAME,
this_version.clone(),
file.path(),
&file,
&TESTING_COMPATIBILITY_INFORMATION,
);
assert!(result.is_ok());
Expand Down
Loading
Loading