Skip to content

Commit 82246d2

Browse files
author
Ariel Ben-Yehuda
committed
ci: add integration tests
1 parent 64752cb commit 82246d2

File tree

8 files changed

+96
-35
lines changed

8 files changed

+96
-35
lines changed

.github/actions/rust-build/action.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,12 @@ runs:
1616
- uses: Swatinem/rust-cache@v2
1717
- name: Build
1818
shell: bash
19-
run: if [ "${{ inputs.toolchain }}" != stable ]; then rm -fv Cargo.lock; fi && cargo build --all-features --verbose
19+
run: |
20+
if [ "${{ inputs.toolchain }}" != stable ]; then
21+
rm -fv Cargo.lock
22+
fi
23+
cargo build --all-features --verbose
24+
cargo build --all-features --verbose --example simple
2025
- name: Run tests
2126
shell: bash
2227
run: cargo test --all-features --verbose

.github/workflows/build-decoder.yml

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

.github/workflows/build.yml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ on: [pull_request]
33

44
jobs:
55
build:
6+
id: build
7+
name: Build
68
runs-on: ubuntu-latest
79
strategy:
810
matrix:
911
toolchain:
12+
- stable # Stable is first to test with Cargo.lock
1013
- "1.85" # Current MSRV due to Cargo MSRV feature
11-
- stable
1214
env:
1315
RUST_BACKTRACE: 1
1416
steps:
@@ -17,5 +19,8 @@ jobs:
1719
uses: ./.github/actions/rust-build
1820
with:
1921
toolchain: ${{ matrix.toolchain }}
20-
21-
22+
- name: Upload artifact for testing
23+
uses: actions/upload-artifact@v4
24+
with:
25+
name: example-simple
26+
path: ./target/debug/example/simple

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
/target
22
/decoder/target
3+
/tests/async-profiler
4+
/tests/profiles

Cargo.lock

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ tracing-subscriber = { version = "0.3", features = ["env-filter"] }
3131
tokio = { version = "1", features = ["test-util", "full"] }
3232
test-case = "3"
3333
rand = "0.9"
34+
humantime = "2"
3435

3536
[[example]]
3637
name = 'simple'

examples/simple/main.rs

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33

44
use async_profiler_agent::{
55
profiler::ProfilerBuilder,
6-
reporter::s3::{S3Reporter, S3ReporterConfig},
6+
reporter::{
7+
local::LocalReporter,
8+
s3::{S3Reporter, S3ReporterConfig},
9+
},
710
};
811
use std::time::Duration;
912

@@ -34,6 +37,14 @@ struct Args {
3437
bucket_owner: String,
3538
#[arg(long)]
3639
bucket: String,
40+
#[arg(long)]
41+
local: bool,
42+
#[arg(long)]
43+
#[clap(value_parser = humantime::parse_duration)]
44+
duration: Option<Duration>,
45+
#[arg(long, default_value = "30s")]
46+
#[clap(value_parser = humantime::parse_duration)]
47+
reporting_interval: Duration,
3748
}
3849

3950
#[allow(unexpected_cfgs)]
@@ -56,23 +67,35 @@ async fn main_internal() -> Result<(), anyhow::Error> {
5667

5768
let args = Args::parse();
5869

59-
let sdk_config = aws_config::defaults(BehaviorVersion::latest()).load().await;
60-
let reporting_interval = Duration::from_secs(30);
70+
let profiler = ProfilerBuilder::default();
6171

62-
let profiler = ProfilerBuilder::default()
63-
.with_reporter(S3Reporter::new(S3ReporterConfig {
72+
let profiler = if args.local {
73+
profiler.with_reporter(LocalReporter::new(args.bucket))
74+
} else {
75+
let sdk_config = aws_config::defaults(BehaviorVersion::latest()).load().await;
76+
profiler.with_reporter(S3Reporter::new(S3ReporterConfig {
6477
sdk_config: &sdk_config,
6578
bucket_owner: args.bucket_owner,
6679
bucket_name: args.bucket,
6780
profiling_group_name: args.profiling_group,
6881
}))
69-
.with_reporting_interval(reporting_interval)
82+
};
83+
84+
let profiler = profiler
85+
.with_reporting_interval(args.reporting_interval)
7086
.build();
7187

7288
tracing::info!("starting profiler");
7389
profiler.spawn()?;
7490
tracing::info!("profiler started");
7591

76-
slow::run().await;
92+
if let Some(timeout) = args.duration {
93+
tokio::time::timeout(timeout, slow::run())
94+
.await
95+
.unwrap_err();
96+
} else {
97+
slow::run().await;
98+
}
99+
77100
Ok(())
78101
}

tests/integration.sh

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/bin/bash
2+
3+
set -exuo pipefail
4+
5+
git clone https://github.com/async-profiler/async-profiler
6+
(
7+
cd async-profiler
8+
git checkout 14c7e819b2054308da1bd980fe72137d2d0e0cf6
9+
make -j16
10+
)
11+
export LD_LIBRARY_PATH="$PWD/async-profiler/build/lib"
12+
mkdir -p profiles
13+
rm -f profiles/*.jfr
14+
(
15+
./example-simple -- --local --bucket tests/profiles --bucket-owner 0 --profiling-group PG --duration 30s --reporting-interval 5s
16+
)
17+
(
18+
for profile in profiles/*.jfr; do
19+
short_sleeps_100=$(./pollcatch-decoder longpolls --stack-depth=10 "$profile" 100us | ( grep -c short_sleep_2 || true ))
20+
short_sleeps_1000=$(./pollcatch-decoder longpolls --stack-depth=10 "$profile" 1000us | ( grep -c short_sleep_2 || true ))
21+
long_sleeps_100=$(./pollcatch-decoder longpolls --stack-depth=10 "$profile" 100us | ( grep -c accidentally_slow_2 || true ))
22+
long_sleeps_1000=$(./pollcatch-decoder longpolls --stack-depth=10 "$profile" 1000us | ( grep -c accidentally_slow_2 || true ))
23+
# Long sleeps should occur in both the 100us and 1000us filters
24+
if [ "$long_sleeps_100" -lt 1 ]; then
25+
echo "No long sleeps in 100us"
26+
exit 1
27+
fi
28+
if [ "$long_sleeps_1000" -lt 1 ]; then
29+
echo "No long sleeps in 1000us"
30+
exit 1
31+
fi
32+
# short sleeps should only occur in the 100us filter. Allow a small number of short sleeps if there was OS jank
33+
if [ "$short_sleeps_100" -lt 5 ]; then
34+
echo "No short sleeps in 100us"
35+
exit 1
36+
fi
37+
if [ "$short_sleeps_1000" -gt 5 ]; then
38+
echo "Too many short sleeps in 1000us"
39+
exit 1
40+
fi
41+
done
42+
)

0 commit comments

Comments
 (0)