Skip to content

Commit 2ecfa7f

Browse files
committed
Support optional command priorities.
1 parent ab69b2c commit 2ecfa7f

File tree

4 files changed

+101
-40
lines changed

4 files changed

+101
-40
lines changed

justfile

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ build-contracts:
2828

2929
[private]
3030
build-port-alloc:
31-
cargo build --release -p test-utils --bin run --bin port-alloc --features ports
31+
cargo build --release -p test-utils --bin run --bin port-alloc --no-default-features --features ports
3232

3333
[private]
3434
build-test-utils:
35-
cargo build --release -p test-utils --all-features
35+
cargo build --release -p test-utils
3636

3737
####################
3838
###CHECK COMMANDS###
@@ -147,23 +147,23 @@ verify_blocks *ARGS:
147147
####TEST COMMANDS###
148148
####################
149149
test *ARGS: build-port-alloc
150-
target/release/run --with target/release/port-alloc cargo nextest run -- {{ARGS}}
150+
target/release/run --spawn target/release/port-alloc cargo nextest run -- {{ARGS}}
151151
@if [ "{{ARGS}}" == "" ]; then cargo test --doc; fi
152152

153153
test-contracts: build-contracts
154154
forge test
155155

156156
test_ci *ARGS: build-port-alloc
157157
env {{LOG_LEVELS}} NO_COLOR=1 target/release/run \
158-
--with target/release/port-alloc \
158+
--spawn target/release/port-alloc \
159159
-- cargo nextest run --workspace {{ARGS}}
160160
env {{LOG_LEVELS}} NO_COLOR=1 cargo test --doc {{ARGS}}
161161

162162
test-individually: build-port-alloc
163163
@for pkg in $(cargo metadata --no-deps --format-version 1 | jq -r '.packages[].name'); do \
164164
echo "Testing $pkg"; \
165165
target/release/run \
166-
--with target/release/port-alloc \
166+
--spawn target/release/port-alloc \
167167
-- cargo nextest run --no-tests=pass -p $pkg || exit 1; \
168168
done
169169

@@ -172,11 +172,10 @@ test-contract-deploy *ARGS:
172172

173173
test-all: build_release build-test-utils
174174
env RUST_LOG=timeboost_builder::submit=info,warn target/release/run \
175-
--exec "scripts/test-contract-deploy --keep-anvil" \
176-
--with "target/release/block-maker --port 55000 --committee test-configs/c0/committee.toml" \
177-
--with "target/release/yapper --keyset-file test-configs/c0/committee.toml" \
178-
target/release/run-committee -- \
179-
--max-duration 30 \
180-
--configs test-configs/local/ \
181-
--committee 0 \
182-
--timeboost target/release/timeboost
175+
--spawn "1:anvil --port 8545" \
176+
--run "2:sleep 3" \
177+
--run "3:scripts/deploy-test-contract" \
178+
--spawn "4:target/release/block-maker --port 55000 --committee test-configs/c0/committee.toml" \
179+
--spawn "4:target/release/yapper --keyset-file test-configs/c0/committee.toml" \
180+
--spawn "5:target/release/run-committee --configs test-configs/local/ --committee 0 --timeboost target/release/timeboost" \
181+
sleep -- 30

scripts/deploy-test-contract

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
MANAGER_MNEMONIC="attend year erase basket blind adapt stove broccoli isolate unveil acquire category"
6+
MANAGER_ACCOUNT_INDEX=0
7+
MANAGER_ADDRESS="0x36561082951eed7ffD59cFD82D70570C57072d02"
8+
FAUCET_PRIVATE_KEY="0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"
9+
URL="http://localhost:8545"
10+
DEPLOYMENT_FILE=$(mktemp -t timeboost-deployment-XXXXX)
11+
12+
# Fund manager account && create deployment file
13+
cast send --value 1ether --private-key "$FAUCET_PRIVATE_KEY" "$MANAGER_ADDRESS"
14+
env RUST_LOG=info cargo run --release --bin deploy -- \
15+
-m "$MANAGER_MNEMONIC" \
16+
-i "$MANAGER_ACCOUNT_INDEX" \
17+
-u "$URL" \
18+
-o "$DEPLOYMENT_FILE"
19+
20+
# Extract the deployed KeyManager address
21+
km_addr=$(sed -nr 's/^key_manager.*=.*"(.+)"/\1/p' "$DEPLOYMENT_FILE")
22+
23+
# Update the contract
24+
env RUST_LOG=info cargo run --release --bin register -- \
25+
-m "$MANAGER_MNEMONIC" \
26+
-i "$MANAGER_ACCOUNT_INDEX" \
27+
-u "$URL" \
28+
-k "$km_addr" \
29+
-c "test-configs/c0/committee.toml"
30+
31+
# Clean up the temporary deployment file
32+
rm -f "$DEPLOYMENT_FILE"

test-utils/src/binaries/run-committee.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@ async fn main() -> Result<()> {
5050
.arg("false")
5151
.arg("--config")
5252
.arg(entry.path())
53-
.arg("--ignore-stamp")
54-
.kill_on_drop(true);
53+
.arg("--ignore-stamp");
5554
commands.push(cmd);
5655
}
5756

test-utils/src/binaries/run.rs

Lines changed: 56 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -17,48 +17,63 @@ use tokio::{
1717

1818
#[derive(Parser, Debug)]
1919
struct Args {
20-
/// Commands to run to completion first.
21-
#[clap(long, short)]
22-
exec: Vec<String>,
20+
/// Commands to run to completion.
21+
#[clap(long, short, value_parser = parse_command_line)]
22+
run: Vec<Commandline>,
2323

2424
/// Commands to run concurrently.
25-
#[clap(long, short)]
26-
with: Vec<String>,
25+
#[clap(long, short, value_parser = parse_command_line)]
26+
spawn: Vec<Commandline>,
2727

28-
/// Optional timeout in seconds.
28+
/// Optional timeout main command in seconds.
2929
#[clap(long, short)]
3030
timeout: Option<u64>,
3131

32+
#[clap(long, short)]
33+
verbose: bool,
34+
3235
/// Main command to execute.
3336
main: Vec<String>,
3437
}
3538

3639
#[tokio::main]
3740
async fn main() -> Result<()> {
38-
let args = Args::parse();
41+
let mut args = Args::parse();
42+
args.spawn.iter_mut().for_each(|c| c.sync = false);
43+
44+
let mut commands = args.run;
45+
commands.append(&mut args.spawn);
46+
commands.sort();
3947

4048
let mut term = signal(SignalKind::terminate())?;
4149
let mut intr = signal(SignalKind::interrupt())?;
50+
let mut helpers = JoinSet::<Result<ExitStatus>>::new();
4251

43-
for exe in &args.exec {
44-
let mut pg = ProcessGroup::spawn(exe.split_whitespace())?;
45-
let status = select! {
46-
s = pg.wait() => s?,
47-
_ = term.recv() => return Ok(()),
48-
_ = intr.recv() => return Ok(()),
49-
};
50-
if !status.success() {
51-
bail!("{exe:?} failed with {:?}", status.code());
52+
for commandline in commands {
53+
if args.verbose {
54+
if commandline.sync {
55+
eprintln!("running command: {}", commandline.args)
56+
} else {
57+
eprintln!("spawning command: {}", commandline.args)
58+
}
59+
}
60+
let mut pg = ProcessGroup::spawn(commandline.args.split_whitespace())?;
61+
if commandline.sync {
62+
let status = select! {
63+
s = pg.wait() => s?,
64+
_ = term.recv() => return Ok(()),
65+
_ = intr.recv() => return Ok(()),
66+
};
67+
if !status.success() {
68+
bail!("{:?} failed with {:?}", commandline.args, status.code());
69+
}
70+
} else {
71+
helpers.spawn(async move {
72+
let mut pg = ProcessGroup::spawn(commandline.args.split_whitespace())?;
73+
let status = pg.wait().await?;
74+
Ok(status)
75+
});
5276
}
53-
}
54-
55-
let mut helpers = JoinSet::<Result<ExitStatus>>::new();
56-
for w in args.with {
57-
helpers.spawn(async move {
58-
let mut pg = ProcessGroup::spawn(w.split_whitespace())?;
59-
let status = pg.wait().await?;
60-
Ok(status)
61-
});
6277
}
6378

6479
let mut main = ProcessGroup::spawn(args.main)?;
@@ -88,6 +103,22 @@ async fn main() -> Result<()> {
88103
Ok(())
89104
}
90105

106+
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
107+
struct Commandline {
108+
prio: u8,
109+
args: String,
110+
sync: bool,
111+
}
112+
113+
fn parse_command_line(s: &str) -> Result<Commandline> {
114+
let (p, a) = s.split_once(':').unwrap_or(("0", s));
115+
Ok(Commandline {
116+
prio: p.parse()?,
117+
args: a.to_string(),
118+
sync: true,
119+
})
120+
}
121+
91122
/// Every command is spawned into its own, newly created process group.
92123
struct ProcessGroup(Child, Pid);
93124

0 commit comments

Comments
 (0)