Skip to content
Open
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
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,12 @@ fn test_my_http_query() {
cargo test
```

Профиль сборки плагина наследуется от профиля, в котором собраны тесты. Чтобы запустить тесты на релизной сборке плагина:

```sh
cargo test --release
```

### Ограничения

1. `#[picotest_unit]` не может использоваться в модуле под `#[cfg(test)]`.
Expand Down
9 changes: 7 additions & 2 deletions picotest/src/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use picotest_helpers::topology::{
parse_topology, PluginTopology, SingleNodeTopologyTransformer, TopologyTransformer,
DEFAULT_TIER,
};
use picotest_helpers::{Cluster, DEFAULT_WAIT_VSHARD_ENABLED};
use picotest_helpers::{use_release_build, Cluster, DEFAULT_WAIT_VSHARD_ENABLED};
use serde::Deserialize;
use std::collections::HashMap;
use std::env::{var, VarError};
Expand All @@ -35,7 +35,12 @@ const ENV_PLUGIN_PATH: &str = "PLUGIN_PATH";
const ENV_TOPOLOGY_PATH: &str = "TOPOLOGY_PATH";

pub fn plugin_profile_build_path(plugin_path: &Path) -> PathBuf {
plugin_path.join("target").join("debug")
let profile = if use_release_build() {
"release"
} else {
"debug"
};
plugin_path.join("target").join(profile)
}

/// Constructs a path to the shared library of the plugin
Expand Down
13 changes: 8 additions & 5 deletions picotest/tests/common/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![allow(dead_code)]
use constcat::concat;
use picotest_helpers::run_pike;
use picotest_helpers::{run_pike, use_release_build};
use rstest::fixture;
use std::fs;
use std::io::{BufRead, BufReader, Error, Read, Write};
Expand Down Expand Up @@ -277,10 +277,13 @@ fn run_cargo_test(manifest_dir: &PathBuf, test_args: &[&str]) -> Child {
test_args,
);

Command::new("cargo")
.arg("test")
.arg("--quiet")
.arg("--")
let mut cmd = Command::new("cargo");
cmd.arg("test").arg("--quiet");
if use_release_build() {
cmd.arg("--release");
}

cmd.arg("--")
.args(test_args)
.current_dir(manifest_dir)
.stdout(Stdio::piped())
Expand Down
12 changes: 9 additions & 3 deletions picotest_helpers/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ pub mod topology;

pub type PluginConfigMap = pike::config::PluginConfigMap;

pub fn use_release_build() -> bool {
!cfg!(debug_assertions)
}

const ADMIN_SOCKET_NAME: &str = "admin.sock";
const LOCALHOST_IP: &str = "127.0.0.1";
pub const PICOTEST_USER: &str = "Picotest";
Expand Down Expand Up @@ -193,7 +197,8 @@ impl PicotestInstance {

let result = self.read_output(stdout)?;
if result.is_empty() {
let err_output = self.read_output(stderr)?;
let mut err_output = String::new();
BufReader::new(stderr).read_to_string(&mut err_output)?;
if !err_output.is_empty() {
picodata_admin.kill()?;
return Err(Error::other(err_output));
Expand Down Expand Up @@ -275,7 +280,8 @@ impl PicotestInstance {

let picodata_admin = Command::new("picodata")
.arg("admin")
.arg(self.socket_path.clone())
.arg(ADMIN_SOCKET_NAME)
.current_dir(self.socket_path.parent().unwrap())
.stdin(Stdio::piped())
.stdout(Stdio::piped())
.stderr(Stdio::piped())
Expand Down Expand Up @@ -540,7 +546,7 @@ impl Cluster {
.picodata_path(self.picodata_path.clone())
.wait_vshard_discovery(self.wait_vshard_discovery)
.wait_vshard_discovery_timeout(DEFAULT_WAIT_VSHARD_TIMEOUT_SECS)
.use_release(false)
.use_release(use_release_build())
.build()?;

let data_dir = self.data_dir_path();
Expand Down
Empty file removed tmp/.keep
Empty file.