mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 16:57:58 +00:00
8351ada6a3
* Add new hardware and software metrics * Move sysinfo tests into `mod tests` * Correct a typo in a comment * Remove unnecessary `nix` dependency * Fix the version tests * Add a `--disable-hardware-benchmarks` CLI argument * Disable hardware benchmarks in the integration tests * Remove unused import * Fix benchmarks compilation * Move code to a new `sc-sysinfo` crate * Correct `impl_version` comment * Move `--disable-hardware-benchmarks` to the chain-specific bin crate * Move printing out of hardware bench results to `sc-sysinfo` * Move hardware benchmarks to a separate messages; trigger them manually * Rename some of the fields in the `HwBench` struct * Revert changes to the telemetry crate; manually send hwbench messages * Move sysinfo logs into the sysinfo crate * Move the `TARGET_OS_*` constants into the sysinfo crate * Minor cleanups * Move the `HwBench` struct to the sysinfo crate * Derive `Clone` for `HwBench` * Fix broken telemetry connection notification stream * Prevent the telemetry connection notifiers from leaking if they're disconnected * Turn the telemetry notification failure log into a debug log * Rename `--disable-hardware-benchmarks` to `--no-hardware-benchmarks`
95 lines
2.9 KiB
Rust
95 lines
2.9 KiB
Rust
// This file is part of Substrate.
|
|
|
|
// Copyright (C) 2021-2022 Parity Technologies (UK) Ltd.
|
|
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU General Public License for more details.
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
use assert_cmd::cargo::cargo_bin;
|
|
use nix::{
|
|
sys::signal::{kill, Signal::SIGINT},
|
|
unistd::Pid,
|
|
};
|
|
use std::process;
|
|
|
|
pub mod common;
|
|
pub mod websocket_server;
|
|
|
|
#[async_std::test]
|
|
async fn telemetry_works() {
|
|
let config = websocket_server::Config {
|
|
capacity: 1,
|
|
max_frame_size: 1048 * 1024,
|
|
send_buffer_len: 32,
|
|
bind_address: "127.0.0.1:0".parse().unwrap(),
|
|
};
|
|
let mut server = websocket_server::WsServer::new(config).await.unwrap();
|
|
|
|
let addr = server.local_addr().unwrap();
|
|
|
|
let server_task = async_std::task::spawn(async move {
|
|
loop {
|
|
use websocket_server::Event;
|
|
match server.next_event().await {
|
|
// New connection on the listener.
|
|
Event::ConnectionOpen { address } => {
|
|
println!("New connection from {:?}", address);
|
|
server.accept();
|
|
},
|
|
|
|
// Received a message from a connection.
|
|
Event::BinaryFrame { message, .. } => {
|
|
let json: serde_json::Value = serde_json::from_slice(&message).unwrap();
|
|
let object =
|
|
json.as_object().unwrap().get("payload").unwrap().as_object().unwrap();
|
|
if matches!(object.get("best"), Some(serde_json::Value::String(_))) {
|
|
break
|
|
}
|
|
},
|
|
|
|
Event::TextFrame { .. } => panic!("Got a TextFrame over the socket, this is a bug"),
|
|
|
|
// Connection has been closed.
|
|
Event::ConnectionError { .. } => {},
|
|
}
|
|
}
|
|
});
|
|
|
|
let mut substrate = process::Command::new(cargo_bin("substrate"));
|
|
|
|
let mut substrate = substrate
|
|
.args(&["--dev", "--tmp", "--telemetry-url"])
|
|
.arg(format!("ws://{} 10", addr))
|
|
.arg("--no-hardware-benchmarks")
|
|
.stdout(process::Stdio::piped())
|
|
.stderr(process::Stdio::piped())
|
|
.stdin(process::Stdio::null())
|
|
.spawn()
|
|
.unwrap();
|
|
|
|
server_task.await;
|
|
|
|
assert!(substrate.try_wait().unwrap().is_none(), "the process should still be running");
|
|
|
|
// Stop the process
|
|
kill(Pid::from_raw(substrate.id().try_into().unwrap()), SIGINT).unwrap();
|
|
assert!(common::wait_for(&mut substrate, 40).map(|x| x.success()).unwrap_or_default());
|
|
|
|
let output = substrate.wait_with_output().unwrap();
|
|
|
|
println!("{}", String::from_utf8(output.stdout).unwrap());
|
|
eprintln!("{}", String::from_utf8(output.stderr).unwrap());
|
|
assert!(output.status.success());
|
|
}
|