Skip to content

Commit

Permalink
ci/test: speed up tests (#6987)
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniPopes authored Mar 6, 2024
1 parent d1dc906 commit e42fb32
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 48 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/hive.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
with:
context: .
tags: ghcr.io/paradigmxyz/reth:latest
build-args: BUILD_PROFILE=hivetests
build-args: BUILD_PROFILE=hivetests,FEATURES=asm-keccak
outputs: type=docker,dest=./artifacts/reth_image.tar
cache-from: type=gha
cache-to: type=gha,mode=max
Expand Down Expand Up @@ -198,7 +198,7 @@ jobs:
echo "Simulator failed, creating issue"
# Check if issue already exists
# get all issues with the label C-hivetest, loop over each page and check if the issue already exists
existing_issues=$(gh api /repos/paradigmxyz/reth/issues -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" -F "labels=C-hivetest" --method GET | jq '.[].title')
if [[ $existing_issues == *"Hive Test Failure: ${{ matrix.sim }}"* ]]; then
echo "Issue already exists"
Expand All @@ -211,7 +211,7 @@ jobs:
/repos/${{ github.repository }}/issues \
-f title='Hive Test Failure: ${{ matrix.sim }}' \
-f body="!!!!!!! This is an automated issue created by the hive test failure !!!!!!!<br /><br />The hive test for ${{ matrix.sim }} failed. Please investigate and fix the issue.<br /><br />[Link to the failed run](https://github.com/paradigmxyz/reth/actions/runs/${{ github.run_id }})" \
-f "labels[]=C-hivetest"
-f "labels[]=C-hivetest"
- name: Print simulator output
if: ${{ failure() }}
run: |
Expand Down
10 changes: 4 additions & 6 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,13 @@ concurrency:

jobs:
test:
name: test / ${{ matrix.network }} (${{ matrix.partition }}/2)
name: test / ${{ matrix.network }}
runs-on:
group: Reth
env:
RUST_BACKTRACE: 1
strategy:
matrix:
partition: [1, 2]
network: ["ethereum", "optimism"]
timeout-minutes: 60
steps:
Expand All @@ -40,10 +39,9 @@ jobs:
- name: Run tests
run: |
cargo nextest run \
--locked --features "${{ matrix.network }}" \
--locked --features "asm-keccak ${{ matrix.network }}" \
--workspace --exclude examples --exclude ef-tests \
--partition hash:${{ matrix.partition }}/2 \
-E 'kind(test)'
-E "kind(test)"
sync:
name: sync / 100k blocks
Expand All @@ -63,7 +61,7 @@ jobs:
cache-on-failure: true
- name: Run sync
run: |
cargo run --release --features jemalloc,min-error-logs --bin reth \
cargo run --release --features asm-keccak,jemalloc,min-error-logs --bin reth \
-- node \
--debug.tip 0x91c90676cab257a59cd956d7cb0bceb9b1a71d79755c23c7277a0697ccfaf8c4 \
--debug.max-block 100000 \
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/unit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ jobs:
- name: Run tests
run: |
cargo nextest run \
--locked --features "${{ matrix.network }}" \
--locked --features "asm-keccak ${{ matrix.network }}" \
--workspace --exclude examples --exclude ef-tests \
--partition hash:${{ matrix.partition }}/2 \
-E "kind(lib) | kind(bin) | kind(proc-macro)"
-E "!kind(test)"
state:
name: Ethereum state tests
Expand All @@ -65,7 +65,7 @@ jobs:
- uses: Swatinem/rust-cache@v2
with:
cache-on-failure: true
- run: cargo nextest run --release -p ef-tests --features ef-tests
- run: cargo nextest run --release -p ef-tests --features "asm-keccak ef-tests"

doc:
name: doc tests (${{ matrix.network }})
Expand Down
7 changes: 7 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,13 @@ homepage = "https://paradigmxyz.github.io/reth"
repository = "https://github.com/paradigmxyz/reth"
exclude = [".github/"]

# Speed up tests.
[profile.dev.package]
proptest.opt-level = 3
rand_xorshift.opt-level = 3
rand_chacha.opt-level = 3
unarray.opt-level = 3

# Meant for testing - all optimizations, but with debug assertions and overflow checks.
[profile.hivetests]
inherits = "test"
Expand Down
8 changes: 6 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@ RUN cargo chef prepare --recipe-path recipe.json
FROM chef AS builder
COPY --from=planner /app/recipe.json recipe.json

# Set the build profile to be release
# Build profile, release by default
ARG BUILD_PROFILE=release
ENV BUILD_PROFILE $BUILD_PROFILE

# Extra Cargo features
ARG FEATURES=""
ENV FEATURES $FEATURES

# Install system dependencies
RUN apt-get update && apt-get -y upgrade && apt-get install -y libclang-dev pkg-config

Expand All @@ -24,7 +28,7 @@ RUN cargo chef cook --profile $BUILD_PROFILE --recipe-path recipe.json

# Build application
COPY . .
RUN cargo build --profile $BUILD_PROFILE --no-default-features --locked --bin reth
RUN cargo build --profile $BUILD_PROFILE --features "$FEATURES" --no-default-features --locked --bin reth

# ARG is not resolved in COPY so we have to hack around it by copying the
# binary to a temporary location
Expand Down
18 changes: 10 additions & 8 deletions crates/storage/db/src/implementation/mdbx/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,12 +415,13 @@ mod tests {
// Give the `TxnManager` some time to time out the transaction.
sleep(MAX_DURATION + Duration::from_millis(100));

// Transaction has not timed out.
assert_eq!(
tx.get::<tables::Transactions>(0).err(),
Some(DatabaseError::Open(reth_libmdbx::Error::NotFound.into()))
); // Transaction is not timeout-ed
tx.get::<tables::Transactions>(0),
Err(DatabaseError::Open(reth_libmdbx::Error::NotFound.into()))
);
// Backtrace is not recorded.
assert!(!tx.metrics_handler.unwrap().backtrace_recorded.load(Ordering::Relaxed));
// Backtrace is not recorded
}

#[test]
Expand All @@ -437,11 +438,12 @@ mod tests {
// Give the `TxnManager` some time to time out the transaction.
sleep(MAX_DURATION + Duration::from_millis(100));

// Transaction has timed out.
assert_eq!(
tx.get::<tables::Transactions>(0).err(),
Some(DatabaseError::Open(reth_libmdbx::Error::ReadTransactionTimeout.into()))
); // Transaction is timeout-ed
tx.get::<tables::Transactions>(0),
Err(DatabaseError::Open(reth_libmdbx::Error::ReadTransactionTimeout.into()))
);
// Backtrace is recorded.
assert!(tx.metrics_handler.unwrap().backtrace_recorded.load(Ordering::Relaxed));
// Backtrace is recorded
}
}
51 changes: 25 additions & 26 deletions crates/trie/src/trie.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1249,37 +1249,36 @@ mod tests {
#![proptest_config(ProptestConfig {
cases: 128, ..ProptestConfig::default()
})]

#[test]
fn fuzz_state_root_incremental(account_changes: [BTreeMap<B256, U256>; 5]) {
tokio::runtime::Runtime::new().unwrap().block_on(async {
let factory = create_test_provider_factory();
let tx = factory.provider_rw().unwrap();
let mut hashed_account_cursor = tx.tx_ref().cursor_write::<tables::HashedAccounts>().unwrap();

let mut state = BTreeMap::default();
for accounts in account_changes {
let should_generate_changeset = !state.is_empty();
let mut changes = PrefixSetMut::default();
for (hashed_address, balance) in accounts.clone() {
hashed_account_cursor.upsert(hashed_address, Account { balance, ..Default::default() }).unwrap();
if should_generate_changeset {
changes.insert(Nibbles::unpack(hashed_address));
}
let factory = create_test_provider_factory();
let tx = factory.provider_rw().unwrap();
let mut hashed_account_cursor = tx.tx_ref().cursor_write::<tables::HashedAccounts>().unwrap();

let mut state = BTreeMap::default();
for accounts in account_changes {
let should_generate_changeset = !state.is_empty();
let mut changes = PrefixSetMut::default();
for (hashed_address, balance) in accounts.clone() {
hashed_account_cursor.upsert(hashed_address, Account { balance, ..Default::default() }).unwrap();
if should_generate_changeset {
changes.insert(Nibbles::unpack(hashed_address));
}
}

let (state_root, trie_updates) = StateRoot::from_tx(tx.tx_ref())
.with_prefix_sets(TriePrefixSets { account_prefix_set: changes.freeze(), ..Default::default() })
.root_with_updates()
.unwrap();
let (state_root, trie_updates) = StateRoot::from_tx(tx.tx_ref())
.with_prefix_sets(TriePrefixSets { account_prefix_set: changes.freeze(), ..Default::default() })
.root_with_updates()
.unwrap();

state.append(&mut accounts.clone());
let expected_root = state_root_prehashed(
state.clone().into_iter().map(|(key, balance)| (key, (Account { balance, ..Default::default() }, std::iter::empty())))
);
assert_eq!(expected_root, state_root);
trie_updates.flush(tx.tx_ref()).unwrap();
}
});
state.append(&mut accounts.clone());
let expected_root = state_root_prehashed(
state.iter().map(|(&key, &balance)| (key, (Account { balance, ..Default::default() }, std::iter::empty())))
);
assert_eq!(expected_root, state_root);
trie_updates.flush(tx.tx_ref()).unwrap();
}
}
}

Expand Down
1 change: 1 addition & 0 deletions testing/ef-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ workspace = true

[features]
ef-tests = []
asm-keccak = ["reth-primitives/asm-keccak"]

[dependencies]
reth-primitives.workspace = true
Expand Down

0 comments on commit e42fb32

Please sign in to comment.