Skip to content

Commit

Permalink
setup integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
yngrtc committed Feb 12, 2024
1 parent 8efd083 commit 194e448
Show file tree
Hide file tree
Showing 7 changed files with 152 additions and 1 deletion.
5 changes: 4 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
run: cargo run --release --package sfu --example chat -- -d --level info > sfu.log 2>&1 & echo $! > server_pid.txt

- name: Run tests
run: cargo test --release -- --show-output > test.log 2>&1
run: cargo test --release --no-fail-fast -- --show-output > test.log 2>&1 || true

- name: Shutdown server
run: kill -INT $(cat server_pid.txt) || true
Expand All @@ -38,3 +38,6 @@ jobs:
path: |
sfu.log
test.log
- name: Parse test results
run: ./scripts/parse_test_results.sh test.log
79 changes: 79 additions & 0 deletions scripts/parse_test_results.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#!/bin/bash

# Initialize accumulated totals
total_passed=0
total_failed=0
total_ignored=0
total_measured=0
total_filtered=0
total_time=0

# Arrays to store passed, failed, and ignored tests
passed_tests=()
failed_tests=()
ignored_tests=()

# Read each line from the log file
while IFS= read -r line; do
# Check if the line indicates test results
if [[ $line =~ test\ result:\ (FAILED|ok).\ ([0-9]+)\ passed\;\ ([0-9]+)\ failed\;\ ([0-9]+)\ ignored\;\ ([0-9]+)\ measured\;\ ([0-9]+)\ filtered\ out\;\ finished\ in\ ([0-9]+\.[0-9]+)s ]]; then
# Extract the test results
result="${BASH_REMATCH[1]}"
passed="${BASH_REMATCH[2]}"
failed="${BASH_REMATCH[3]}"
ignored="${BASH_REMATCH[4]}"
measured="${BASH_REMATCH[5]}"
filtered="${BASH_REMATCH[6]}"
time="${BASH_REMATCH[7]}"

# Accumulate the test results
total_passed=$((total_passed + passed))
total_failed=$((total_failed + failed))
total_ignored=$((total_ignored + ignored))
total_measured=$((total_measured + measured))
total_filtered=$((total_filtered + filtered))
total_time=$(bc <<< "$total_time + $time")
elif [[ $line =~ test\ (.*)\ \.\.\.\ (FAILED|ok|ignored) ]]; then
# Extract the test name and result
test_name="${BASH_REMATCH[1]}"
test_result="${BASH_REMATCH[2]}"

# Add the test name to the appropriate array based on the result
case "$test_result" in
"ok")
passed_tests+=("$test_name")
;;
"FAILED")
failed_tests+=("$test_name")
;;
"ignored")
ignored_tests+=("$test_name")
;;
esac
fi
done < "$1"

# Print passed tests with indentation
echo "Total Passed: $total_passed"
for test_name in "${passed_tests[@]}"; do
echo " $test_name"
done

# Print failed tests with indentation
echo "Total Failed: $total_failed"
for test_name in "${failed_tests[@]}"; do
echo " $test_name"
done

# Print ignored tests with indentation
echo "Total Ignored: $total_ignored"
for test_name in "${ignored_tests[@]}"; do
echo " $test_name"
done

# Return non-zero exit code if there are failed tests
if [[ $total_failed -gt 0 ]]; then
exit 1
else
exit 0
fi
26 changes: 26 additions & 0 deletions tests/common/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use log::info;
use log::LevelFilter::Debug;
use std::io::Write;

pub fn setup() -> anyhow::Result<()> {
env_logger::Builder::new()
.format(|buf, record| {
writeln!(
buf,
"{}:{} [{}] {} - {}",
record.file().unwrap_or("unknown"),
record.line().unwrap_or(0),
record.level(),
chrono::Local::now().format("%H:%M:%S.%6f"),
record.args()
)
})
.filter(None, Debug)
.try_init()?;

// some setup code, like creating required files/directories, starting
// servers, etc.
info!("common setup");

Ok(())
}
10 changes: 10 additions & 0 deletions tests/datachannel_test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// importing common module.
mod common;

#[test]
fn test_datachannel() -> anyhow::Result<()> {
// using common code.
common::setup()?;

Ok(())
}
11 changes: 11 additions & 0 deletions tests/rtcp_test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// importing common module.
mod common;

#[ignore]
#[test]
fn test_rtcp() -> anyhow::Result<()> {
// using common code.
common::setup()?;

Ok(())
}
10 changes: 10 additions & 0 deletions tests/rtp_test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// importing common module.
mod common;

#[test]
fn test_rtp() -> anyhow::Result<()> {
// using common code.
common::setup()?;

Ok(())
}
12 changes: 12 additions & 0 deletions tests/signaling_test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// importing common module.
mod common;

#[test]
fn test_signaling() -> anyhow::Result<()> {
// using common code.
common::setup()?;

assert_eq!(1, 2);

Ok(())
}

0 comments on commit 194e448

Please sign in to comment.