Skip to content
This repository was archived by the owner on Apr 25, 2022. It is now read-only.

Commit 8baf0ff

Browse files
committed
tests: drop kcov
1 parent 9221887 commit 8baf0ff

File tree

4 files changed

+48
-148
lines changed

4 files changed

+48
-148
lines changed

.github/workflows/rust.yml

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -86,52 +86,3 @@ jobs:
8686
with:
8787
command: build
8888
args: --target wasm32-unknown-unknown
89-
90-
coverage:
91-
name: coverage testing
92-
runs-on: ubuntu-20.04
93-
steps:
94-
- uses: actions/checkout@v2
95-
96-
- uses: actions-rs/toolchain@v1
97-
name: install toolchain
98-
with:
99-
profile: minimal
100-
toolchain: stable
101-
102-
- uses: Swatinem/rust-cache@v1
103-
with:
104-
key: "coverage"
105-
106-
- uses: actions-rs/cargo@v1
107-
name: cargo generate lockfile
108-
with:
109-
command: generate-lockfile
110-
111-
- name: install kcov
112-
uses: ryankurte/action-apt@v0.2.0
113-
with:
114-
packages: "kcov"
115-
116-
- name: install cargo kcov
117-
uses: actions-rs/cargo@v1
118-
with:
119-
command: install
120-
args: cargo-kcov
121-
122-
- uses: actions-rs/cargo@v1
123-
name: cargo kcov
124-
with:
125-
command: kcov
126-
args: --features client,server -- --exclude-pattern=/.cargo,/usr/lib
127-
128-
- name: kcov subprocesses only
129-
shell: bash
130-
run: find target/debug/deps
131-
-executable -type f -name 'cli-*' -not -name '*.so'
132-
-execdir {} \;
133-
env:
134-
KCOV_ARGS: --exclude-pattern=/.cargo,/usr/lib target/cov/cli-
135-
136-
- name: upload coverage
137-
uses: codecov/codecov-action@v1

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# at2-node
22

33
[![at2-node](https://github.com/Distributed-EPFL/at2-node/actions/workflows/rust.yml/badge.svg)](https://github.com/Distributed-EPFL/at2-node/actions/workflows/rust.yml)
4-
[![codecov](https://codecov.io/gh/Distributed-EPFL/at2-node/branch/master/graph/badge.svg)](https://codecov.io/gh/Distributed-EPFL/at2-node)
54

65
An implementation of a distributed ledger using
76
[AT2](https://arxiv.org/abs/1812.10844) (Asynchronous Trustworthy Transfers).

codecov.yml

Lines changed: 0 additions & 11 deletions
This file was deleted.

tests/cli.rs

Lines changed: 48 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@
22
compile_error!("tests need both server and client features");
33

44
use std::{
5-
env, fs, io,
5+
env, io,
66
io::{BufRead, BufReader},
77
iter::{repeat_with, Extend},
88
net::{Ipv4Addr, SocketAddr},
9-
path::PathBuf,
109
sync::{
11-
atomic::{AtomicU16, AtomicU8, Ordering},
10+
atomic::{AtomicU16, Ordering},
1211
Arc,
1312
},
1413
time::{Duration, Instant},
@@ -21,13 +20,9 @@ use url::Url;
2120

2221
const CLIENT_BIN: &str = env!("CARGO_BIN_EXE_client");
2322
const SERVER_BIN: &str = env!("CARGO_BIN_EXE_server");
24-
const CRATE_ROOT: &str = env!("CARGO_MANIFEST_DIR");
2523

26-
fn next_test_id() -> u8 {
27-
static COUNTER: AtomicU8 = AtomicU8::new(0);
28-
29-
COUNTER.fetch_add(1, Ordering::Relaxed)
30-
}
24+
const TICK: Duration = Duration::from_millis(100);
25+
const TIMEOUT: Duration = Duration::from_secs(10);
3126

3227
fn next_test_port() -> u16 {
3328
static PORT_OFFSET: AtomicU16 = AtomicU16::new(0);
@@ -58,10 +53,10 @@ impl Drop for Server {
5853
let _ = signal::kill(Pid::from_raw(*pid as i32), Signal::SIGTERM);
5954
});
6055

61-
let timeout = Instant::now() + Duration::from_secs(1);
56+
let timeout = Instant::now() + TIMEOUT;
6257
while Instant::now() < timeout {
6358
if let Ok(None) = self.handle.try_wait() {
64-
thread::sleep(Duration::from_millis(10));
59+
thread::sleep(TICK);
6560
}
6661
}
6762

@@ -76,47 +71,20 @@ impl Drop for Server {
7671
type ServerConfig = Vec<u8>;
7772
type NodeConfig = Vec<u8>;
7873

79-
fn gen_cmd(binary: &str, binary_args: Vec<&str>) -> duct::Expression {
80-
let kcov_args_env = env::var("KCOV_ARGS");
81-
if kcov_args_env.is_err() {
82-
return cmd(binary, binary_args);
83-
}
84-
let kcov_args = kcov_args_env.unwrap();
85-
86-
let mut args: Vec<String> = kcov_args.split(' ').map(|s| s.to_string()).collect();
87-
88-
let outdir_prefix = args
89-
.pop()
90-
.expect("KCOV_ARGS should contains an outdir prefix");
91-
let mut outdir = PathBuf::new();
92-
outdir.push(CRATE_ROOT);
93-
outdir.push(format!("{}{}", outdir_prefix, next_test_id()));
94-
95-
fs::create_dir(&outdir).expect("create output dir");
96-
args.push(outdir.to_str().unwrap().to_string());
97-
98-
args.push(binary.into());
99-
args.extend(binary_args.iter().map(|a| a.to_string()));
100-
101-
cmd("kcov", &args)
102-
}
103-
104-
fn gen_server_cmd(server_args: Vec<&str>) -> duct::Expression {
105-
gen_cmd(SERVER_BIN, server_args)
106-
}
107-
108-
fn gen_client_cmd(client_args: Vec<&str>) -> duct::Expression {
109-
gen_cmd(CLIENT_BIN, client_args)
110-
}
111-
11274
fn gen_config(node: &SocketAddr, rpc: &SocketAddr) -> (ServerConfig, NodeConfig) {
113-
let full_config = gen_server_cmd(vec!["config", "new", &node.to_string(), &rpc.to_string()])
114-
.stdout_capture()
115-
.run()
116-
.expect("generate config")
117-
.stdout;
75+
let full_config = cmd!(
76+
SERVER_BIN,
77+
"config",
78+
"new",
79+
&node.to_string(),
80+
&rpc.to_string()
81+
)
82+
.stdout_capture()
83+
.run()
84+
.expect("generate config")
85+
.stdout;
11886

119-
let node_config = gen_server_cmd(vec!["config", "get-node"])
87+
let node_config = cmd!(SERVER_BIN, "config", "get-node")
12088
.stdin_bytes(full_config.clone())
12189
.stdout_capture()
12290
.run()
@@ -127,7 +95,7 @@ fn gen_config(node: &SocketAddr, rpc: &SocketAddr) -> (ServerConfig, NodeConfig)
12795
}
12896

12997
fn start_server(server_config: ServerConfig) -> Server {
130-
let handle = gen_server_cmd(vec!["run"])
98+
let handle = cmd!(SERVER_BIN, "run")
13199
.stdin_bytes(server_config)
132100
.stderr_to_stdout()
133101
.reader()
@@ -177,15 +145,15 @@ async fn server_started_twice_fails() {
177145

178146
let second_server = start_server(server_config);
179147

180-
let timeout = Instant::now() + Duration::from_secs(5);
148+
let timeout = Instant::now() + TIMEOUT;
181149
let mut exit = None;
182150
while Instant::now() < timeout {
183151
if let Err(err) = second_server.handle.try_wait() {
184152
exit = Some(err.kind());
185153
break;
186154
}
187155

188-
tokio::time::sleep(Duration::from_millis(10)).await;
156+
tokio::time::sleep(TICK).await;
189157
}
190158

191159
assert_eq!(exit, Some(io::ErrorKind::Other));
@@ -248,19 +216,19 @@ async fn can_run_network() {
248216
async fn client_without_servers_fails() {
249217
let (_, rpc) = start_network(2).await;
250218

251-
let recipient = gen_client_cmd(vec!["config", "new", &rpc.to_string()])
252-
.pipe(gen_client_cmd(vec!["config", "get-public-key"]))
219+
let recipient = cmd!(CLIENT_BIN, "config", "new", &rpc.to_string())
220+
.pipe(cmd!(CLIENT_BIN, "config", "get-public-key"))
253221
.read()
254222
.expect("recipient public key");
255223

256-
gen_client_cmd(vec!["config", "new", &rpc.to_string()])
257-
.pipe(gen_client_cmd(vec!["send-asset", "1", &recipient, "10"]))
224+
cmd!(CLIENT_BIN, "config", "new", &rpc.to_string())
225+
.pipe(cmd!(CLIENT_BIN, "send-asset", "1", &recipient, "10"))
258226
.run()
259227
.expect_err("send asset");
260228
}
261229

262230
fn get_balance(config: String) -> usize {
263-
gen_client_cmd(vec!["get-balance"])
231+
cmd!(CLIENT_BIN, "get-balance")
264232
.stdin_bytes(config)
265233
.read()
266234
.expect("get asset")
@@ -272,7 +240,7 @@ fn get_balance(config: String) -> usize {
272240
async fn new_client_has_some_asset() {
273241
let (_servers, rpc) = start_network(3).await;
274242

275-
let config = gen_client_cmd(vec!["config", "new", &rpc.to_string()])
243+
let config = cmd!(CLIENT_BIN, "config", "new", &rpc.to_string())
276244
.read()
277245
.expect("create sender");
278246

@@ -285,24 +253,25 @@ fn transfer(
285253
receiver_config: String,
286254
amount: usize,
287255
) {
288-
let second_client = gen_client_cmd(vec!["config", "get-public-key"])
256+
let second_client = cmd!(CLIENT_BIN, "config", "get-public-key")
289257
.stdin_bytes(receiver_config)
290258
.read()
291259
.expect("get public key");
292260

293-
gen_client_cmd(vec![
261+
cmd!(
262+
CLIENT_BIN,
294263
"send-asset",
295264
&sender_sequence.to_string(),
296265
&second_client,
297266
&amount.to_string(),
298-
])
267+
)
299268
.stdin_bytes(sender_config)
300269
.run()
301270
.expect("send asset");
302271
}
303272

304273
fn get_last_sequence(config: String) -> sieve::Sequence {
305-
gen_client_cmd(vec!["get-last-sequence"])
274+
cmd!(CLIENT_BIN, "get-last-sequence")
306275
.stdin_bytes(config)
307276
.read()
308277
.expect("get last sequence")
@@ -311,44 +280,36 @@ fn get_last_sequence(config: String) -> sieve::Sequence {
311280
}
312281

313282
async fn wait_for_sequence(config: String, sequence: sieve::Sequence) {
314-
let mut last_sequence = sieve::Sequence::default();
315-
316-
while last_sequence != sequence {
317-
tokio::time::sleep(Duration::from_millis(10)).await;
283+
let timeout = Instant::now() + TIMEOUT;
284+
while Instant::now() < timeout {
285+
let last_sequence = get_last_sequence(config.clone());
286+
if last_sequence == sequence {
287+
return;
288+
}
318289

319-
last_sequence = get_last_sequence(config.clone());
290+
tokio::time::sleep(TICK).await;
320291
}
292+
293+
panic!("timeout expired");
321294
}
322295

323296
#[tokio::test]
324297
async fn transfer_increment_sequence() {
325298
let (_servers, rpc) = start_network(3).await;
326299

327-
let sender = gen_client_cmd(vec!["config", "new", &rpc.to_string()])
300+
let sender = cmd!(CLIENT_BIN, "config", "new", &rpc.to_string())
328301
.read()
329302
.expect("create sender");
330303

331-
let receiver = gen_client_cmd(vec!["config", "new", &rpc.to_string()])
304+
let receiver = cmd!(CLIENT_BIN, "config", "new", &rpc.to_string())
332305
.read()
333306
.expect("create receiver");
334307

335-
let previous_sequence = get_last_sequence(sender.clone());
336-
337-
transfer(sender.clone(), 1, receiver.clone(), 1);
338-
339-
let timeout = Instant::now() + Duration::from_secs(5);
340-
while Instant::now() < timeout {
341-
let current_sequence = get_last_sequence(sender.clone());
342-
if previous_sequence != current_sequence {
343-
break;
344-
}
345-
346-
tokio::time::sleep(Duration::from_millis(10)).await;
347-
}
308+
let sequence = get_last_sequence(sender.clone());
348309

349-
let current_sequence = get_last_sequence(sender.clone());
310+
transfer(sender.clone(), sequence + 1, receiver.clone(), 1);
350311

351-
assert!(previous_sequence < current_sequence);
312+
wait_for_sequence(sender.clone(), sequence + 1).await;
352313
}
353314

354315
#[tokio::test]
@@ -357,11 +318,11 @@ async fn can_send_asset() {
357318

358319
let (_servers, rpc) = start_network(3).await;
359320

360-
let sender = gen_client_cmd(vec!["config", "new", &rpc.to_string()])
321+
let sender = cmd!(CLIENT_BIN, "config", "new", &rpc.to_string())
361322
.read()
362323
.expect("create sender");
363324

364-
let receiver = gen_client_cmd(vec!["config", "new", &rpc.to_string()])
325+
let receiver = cmd!(CLIENT_BIN, "config", "new", &rpc.to_string())
365326
.read()
366327
.expect("create receiver");
367328

0 commit comments

Comments
 (0)