ci/test: speed up tests (#6987)

This commit is contained in:
DaniPopes
2024-03-06 14:30:18 +01:00
committed by GitHub
parent d1dc906d96
commit e42fb32c7f
8 changed files with 59 additions and 48 deletions

View File

@ -29,7 +29,7 @@ jobs:
with: with:
context: . context: .
tags: ghcr.io/paradigmxyz/reth:latest 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 outputs: type=docker,dest=./artifacts/reth_image.tar
cache-from: type=gha cache-from: type=gha
cache-to: type=gha,mode=max cache-to: type=gha,mode=max
@ -198,7 +198,7 @@ jobs:
echo "Simulator failed, creating issue" echo "Simulator failed, creating issue"
# Check if issue already exists # Check if issue already exists
# get all issues with the label C-hivetest, loop over each page and check if the 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') 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 if [[ $existing_issues == *"Hive Test Failure: ${{ matrix.sim }}"* ]]; then
echo "Issue already exists" echo "Issue already exists"
@ -211,7 +211,7 @@ jobs:
/repos/${{ github.repository }}/issues \ /repos/${{ github.repository }}/issues \
-f title='Hive Test Failure: ${{ matrix.sim }}' \ -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 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 - name: Print simulator output
if: ${{ failure() }} if: ${{ failure() }}
run: | run: |

View File

@ -18,14 +18,13 @@ concurrency:
jobs: jobs:
test: test:
name: test / ${{ matrix.network }} (${{ matrix.partition }}/2) name: test / ${{ matrix.network }}
runs-on: runs-on:
group: Reth group: Reth
env: env:
RUST_BACKTRACE: 1 RUST_BACKTRACE: 1
strategy: strategy:
matrix: matrix:
partition: [1, 2]
network: ["ethereum", "optimism"] network: ["ethereum", "optimism"]
timeout-minutes: 60 timeout-minutes: 60
steps: steps:
@ -40,10 +39,9 @@ jobs:
- name: Run tests - name: Run tests
run: | run: |
cargo nextest run \ cargo nextest run \
--locked --features "${{ matrix.network }}" \ --locked --features "asm-keccak ${{ matrix.network }}" \
--workspace --exclude examples --exclude ef-tests \ --workspace --exclude examples --exclude ef-tests \
--partition hash:${{ matrix.partition }}/2 \ -E "kind(test)"
-E 'kind(test)'
sync: sync:
name: sync / 100k blocks name: sync / 100k blocks
@ -63,7 +61,7 @@ jobs:
cache-on-failure: true cache-on-failure: true
- name: Run sync - name: Run sync
run: | run: |
cargo run --release --features jemalloc,min-error-logs --bin reth \ cargo run --release --features asm-keccak,jemalloc,min-error-logs --bin reth \
-- node \ -- node \
--debug.tip 0x91c90676cab257a59cd956d7cb0bceb9b1a71d79755c23c7277a0697ccfaf8c4 \ --debug.tip 0x91c90676cab257a59cd956d7cb0bceb9b1a71d79755c23c7277a0697ccfaf8c4 \
--debug.max-block 100000 \ --debug.max-block 100000 \

View File

@ -38,10 +38,10 @@ jobs:
- name: Run tests - name: Run tests
run: | run: |
cargo nextest run \ cargo nextest run \
--locked --features "${{ matrix.network }}" \ --locked --features "asm-keccak ${{ matrix.network }}" \
--workspace --exclude examples --exclude ef-tests \ --workspace --exclude examples --exclude ef-tests \
--partition hash:${{ matrix.partition }}/2 \ --partition hash:${{ matrix.partition }}/2 \
-E "kind(lib) | kind(bin) | kind(proc-macro)" -E "!kind(test)"
state: state:
name: Ethereum state tests name: Ethereum state tests
@ -65,7 +65,7 @@ jobs:
- uses: Swatinem/rust-cache@v2 - uses: Swatinem/rust-cache@v2
with: with:
cache-on-failure: true 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: doc:
name: doc tests (${{ matrix.network }}) name: doc tests (${{ matrix.network }})

View File

@ -96,6 +96,13 @@ homepage = "https://paradigmxyz.github.io/reth"
repository = "https://github.com/paradigmxyz/reth" repository = "https://github.com/paradigmxyz/reth"
exclude = [".github/"] 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. # Meant for testing - all optimizations, but with debug assertions and overflow checks.
[profile.hivetests] [profile.hivetests]
inherits = "test" inherits = "test"

View File

@ -12,10 +12,14 @@ RUN cargo chef prepare --recipe-path recipe.json
FROM chef AS builder FROM chef AS builder
COPY --from=planner /app/recipe.json recipe.json COPY --from=planner /app/recipe.json recipe.json
# Set the build profile to be release # Build profile, release by default
ARG BUILD_PROFILE=release ARG BUILD_PROFILE=release
ENV BUILD_PROFILE $BUILD_PROFILE ENV BUILD_PROFILE $BUILD_PROFILE
# Extra Cargo features
ARG FEATURES=""
ENV FEATURES $FEATURES
# Install system dependencies # Install system dependencies
RUN apt-get update && apt-get -y upgrade && apt-get install -y libclang-dev pkg-config RUN apt-get update && apt-get -y upgrade && apt-get install -y libclang-dev pkg-config
@ -24,7 +28,7 @@ RUN cargo chef cook --profile $BUILD_PROFILE --recipe-path recipe.json
# Build application # Build application
COPY . . 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 # ARG is not resolved in COPY so we have to hack around it by copying the
# binary to a temporary location # binary to a temporary location

View File

@ -415,12 +415,13 @@ mod tests {
// Give the `TxnManager` some time to time out the transaction. // Give the `TxnManager` some time to time out the transaction.
sleep(MAX_DURATION + Duration::from_millis(100)); sleep(MAX_DURATION + Duration::from_millis(100));
// Transaction has not timed out.
assert_eq!( assert_eq!(
tx.get::<tables::Transactions>(0).err(), tx.get::<tables::Transactions>(0),
Some(DatabaseError::Open(reth_libmdbx::Error::NotFound.into())) Err(DatabaseError::Open(reth_libmdbx::Error::NotFound.into()))
); // Transaction is not timeout-ed );
// Backtrace is not recorded.
assert!(!tx.metrics_handler.unwrap().backtrace_recorded.load(Ordering::Relaxed)); assert!(!tx.metrics_handler.unwrap().backtrace_recorded.load(Ordering::Relaxed));
// Backtrace is not recorded
} }
#[test] #[test]
@ -437,11 +438,12 @@ mod tests {
// Give the `TxnManager` some time to time out the transaction. // Give the `TxnManager` some time to time out the transaction.
sleep(MAX_DURATION + Duration::from_millis(100)); sleep(MAX_DURATION + Duration::from_millis(100));
// Transaction has timed out.
assert_eq!( assert_eq!(
tx.get::<tables::Transactions>(0).err(), tx.get::<tables::Transactions>(0),
Some(DatabaseError::Open(reth_libmdbx::Error::ReadTransactionTimeout.into())) Err(DatabaseError::Open(reth_libmdbx::Error::ReadTransactionTimeout.into()))
); // Transaction is timeout-ed );
// Backtrace is recorded.
assert!(tx.metrics_handler.unwrap().backtrace_recorded.load(Ordering::Relaxed)); assert!(tx.metrics_handler.unwrap().backtrace_recorded.load(Ordering::Relaxed));
// Backtrace is recorded
} }
} }

View File

@ -1249,37 +1249,36 @@ mod tests {
#![proptest_config(ProptestConfig { #![proptest_config(ProptestConfig {
cases: 128, ..ProptestConfig::default() cases: 128, ..ProptestConfig::default()
})] })]
#[test] #[test]
fn fuzz_state_root_incremental(account_changes: [BTreeMap<B256, U256>; 5]) { 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 factory = create_test_provider_factory(); let tx = factory.provider_rw().unwrap();
let tx = factory.provider_rw().unwrap(); let mut hashed_account_cursor = tx.tx_ref().cursor_write::<tables::HashedAccounts>().unwrap();
let mut hashed_account_cursor = tx.tx_ref().cursor_write::<tables::HashedAccounts>().unwrap();
let mut state = BTreeMap::default(); let mut state = BTreeMap::default();
for accounts in account_changes { for accounts in account_changes {
let should_generate_changeset = !state.is_empty(); let should_generate_changeset = !state.is_empty();
let mut changes = PrefixSetMut::default(); let mut changes = PrefixSetMut::default();
for (hashed_address, balance) in accounts.clone() { for (hashed_address, balance) in accounts.clone() {
hashed_account_cursor.upsert(hashed_address, Account { balance, ..Default::default() }).unwrap(); hashed_account_cursor.upsert(hashed_address, Account { balance, ..Default::default() }).unwrap();
if should_generate_changeset { if should_generate_changeset {
changes.insert(Nibbles::unpack(hashed_address)); 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();
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();
} }
});
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.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();
}
} }
} }

View File

@ -13,6 +13,7 @@ workspace = true
[features] [features]
ef-tests = [] ef-tests = []
asm-keccak = ["reth-primitives/asm-keccak"]
[dependencies] [dependencies]
reth-primitives.workspace = true reth-primitives.workspace = true