-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move tests that don't need a network to a separate file; fix project …
…template. (#3293) ## Motivation `cargo test test_project_new` fails for me locally. ## Proposal Make sure it is executed in CI. Fix the project template. Increase the timeout for `default-features-and-witty-integration-test`, since it now runs more tests. ## Test Plan The test is now run in CI. (I tried without the second commit, and it failed.) ## Release Plan - Nothing to do / These changes follow the usual release cycle. ## Links - Maybe related to: #3217 - [reviewer checklist](https://github.com/linera-io/linera-protocol/blob/main/CONTRIBUTING.md#reviewer-checklist)
- Loading branch information
Showing
9 changed files
with
115 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,27 @@ | ||
// Copyright (c) Zefchain Labs, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
use std::sync::LazyLock; | ||
use std::env; | ||
|
||
use tokio::sync::Mutex; | ||
/// Restores the `RUSTFLAGS` environment variable to make warnings fail as errors. | ||
pub struct RestoreVarOnDrop; | ||
|
||
/// A static lock to prevent integration tests from running in parallel. | ||
pub static INTEGRATION_TEST_GUARD: LazyLock<Mutex<()>> = LazyLock::new(|| Mutex::new(())); | ||
impl Drop for RestoreVarOnDrop { | ||
fn drop(&mut self) { | ||
env::set_var("RUSTFLAGS", "-D warnings"); | ||
} | ||
} | ||
|
||
/// Clears the `RUSTFLAGS` environment variable, if it was configured to make warnings fail as | ||
/// errors. | ||
/// | ||
/// The returned [`RestoreVarOnDrop`] restores the environment variable to its original value when | ||
/// it is dropped. | ||
pub fn override_disable_warnings_as_errors() -> Option<RestoreVarOnDrop> { | ||
if matches!(env::var("RUSTFLAGS"), Ok(value) if value == "-D warnings") { | ||
env::set_var("RUSTFLAGS", ""); | ||
Some(RestoreVarOnDrop) | ||
} else { | ||
None | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// Copyright (c) Zefchain Labs, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
use std::sync::LazyLock; | ||
|
||
use tokio::sync::Mutex; | ||
|
||
/// A static lock to prevent integration tests from running in parallel. | ||
pub static INTEGRATION_TEST_GUARD: LazyLock<Mutex<()>> = LazyLock::new(|| Mutex::new(())); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// Copyright (c) Zefchain Labs, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
use std::{path::PathBuf, process::Command}; | ||
|
||
use anyhow::Result; | ||
use linera_service::cli_wrappers::{local_net::PathProvider, ClientWrapper, Network, OnClientDrop}; | ||
|
||
mod common; | ||
|
||
#[test_log::test(tokio::test)] | ||
async fn test_project_new() -> Result<()> { | ||
let _rustflags_override = common::override_disable_warnings_as_errors(); | ||
let path_provider = PathProvider::create_temporary_directory()?; | ||
let id = 0; | ||
let client = ClientWrapper::new( | ||
path_provider, | ||
Network::Grpc, | ||
None, | ||
id, | ||
OnClientDrop::LeakChains, | ||
); | ||
let manifest_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR")); | ||
let linera_root = manifest_dir | ||
.parent() | ||
.expect("CARGO_MANIFEST_DIR should not be at the root"); | ||
let tmp_dir = client.project_new("init-test", linera_root).await?; | ||
let project_dir = tmp_dir.path().join("init-test"); | ||
client | ||
.build_application(project_dir.as_path(), "init-test", false) | ||
.await?; | ||
|
||
let mut child = Command::new("cargo") | ||
.args(["fmt", "--check"]) | ||
.current_dir(project_dir.as_path()) | ||
.spawn()?; | ||
assert!(child.wait()?.success()); | ||
|
||
let mut child = Command::new("cargo") | ||
.arg("test") | ||
.current_dir(project_dir.as_path()) | ||
.spawn()?; | ||
assert!(child.wait()?.success()); | ||
|
||
Ok(()) | ||
} | ||
|
||
#[test_log::test(tokio::test)] | ||
async fn test_project_test() -> Result<()> { | ||
let path_provider = PathProvider::create_temporary_directory()?; | ||
let id = 0; | ||
let client = ClientWrapper::new( | ||
path_provider, | ||
Network::Grpc, | ||
None, | ||
id, | ||
OnClientDrop::LeakChains, | ||
); | ||
client | ||
.project_test(&ClientWrapper::example_path("counter")?) | ||
.await?; | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters