Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: made unit tests use separate real dbs #213

Merged
merged 36 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
7e759a9
mvp
pompon0 Oct 12, 2023
45c7151
removed test pool
pompon0 Oct 12, 2023
eb2e740
macro is out
pompon0 Oct 12, 2023
54e2300
docker-compose is stupid
pompon0 Oct 12, 2023
c638f8d
removed hyphen
pompon0 Oct 13, 2023
6d87ed2
more tries
pompon0 Oct 13, 2023
fabe692
Merge remote-tracking branch 'public/main' into gprusak-testdb2
pompon0 Oct 13, 2023
395fb33
lint
pompon0 Oct 13, 2023
616dc97
fixed tries
pompon0 Oct 13, 2023
0ee68b7
sleep instead of wait
pompon0 Oct 13, 2023
ba91651
debugging docker
pompon0 Oct 13, 2023
62cb222
snapshot
pompon0 Oct 13, 2023
b561e41
fix
pompon0 Oct 13, 2023
7461573
snapshot
pompon0 Oct 13, 2023
efcd76e
Merge remote-tracking branch 'origin/main' into gprusak-testdb2
pompon0 Oct 13, 2023
edde172
removed dep
pompon0 Oct 13, 2023
8f82090
snapshot
pompon0 Oct 13, 2023
624eede
benchmark
pompon0 Oct 13, 2023
2fe4d8c
yarn
pompon0 Oct 13, 2023
d364445
Merge remote-tracking branch 'origin/main' into gprusak-testdb2
pompon0 Oct 23, 2023
b7be63a
postgres container rename
pompon0 Oct 23, 2023
4b12be9
applied comments
pompon0 Oct 23, 2023
e094b07
debugging
pompon0 Oct 23, 2023
1171c9f
Merge remote-tracking branch 'origin/main' into gprusak-testdb2
pompon0 Oct 23, 2023
633b6f0
debugging
pompon0 Oct 23, 2023
eeb76fb
debugging
pompon0 Oct 23, 2023
5adf267
debugging
pompon0 Oct 25, 2023
5268529
Merge remote-tracking branch 'origin/main' into gprusak-testdb2
pompon0 Oct 25, 2023
a6d7543
fixed tests
pompon0 Oct 25, 2023
3d8fdce
debugging
pompon0 Oct 25, 2023
5bb7d3c
revert
pompon0 Oct 25, 2023
ffb517b
wtf
pompon0 Oct 25, 2023
9cdc9e6
avoiding problems
pompon0 Oct 25, 2023
bc3717e
rolled back whitespace changes
pompon0 Oct 26, 2023
cf73797
changed port
pompon0 Oct 26, 2023
fd988a3
Merge branch 'main' into gprusak-testdb2
pompon0 Oct 26, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions .github/workflows/vm-perf-comparison.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,20 @@ jobs:

- name: init
run: |
docker-compose -f docker-compose-runner.yml up -d zk
docker compose -f docker-compose-runner.yml up -d zk

- name: run benchmarks on base branch
shell: bash
run: |
ci_run zk
ci_run zk compiler system-contracts
ci_run cargo bench --package vm-benchmark --bench iai | tee base-iai
docker compose -f docker-compose-runner.yml down

- name: checkout PR
run: git checkout --force FETCH_HEAD
run: |
git checkout --force FETCH_HEAD
docker compose -f docker-compose-runner.yml up -d zk

- name: run benchmarks on PR
shell: bash
Expand Down
14 changes: 2 additions & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ members = [
"core/lib/circuit_breaker",
"core/lib/commitment_utils",
"core/lib/dal",
"core/lib/db_test_macro",
"core/lib/eth_client",
"core/lib/eth_signer",
"core/lib/mempool",
Expand Down
3 changes: 2 additions & 1 deletion core/lib/dal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ zksync_health_check = { path = "../health_check" }
itertools = "0.10.1"
thiserror = "1.0"
anyhow = "1.0"
url = "2"
rand = "0.8"
tokio = { version = "1", features = ["full"] }
sqlx = { version = "0.5.13", default-features = false, features = [
"runtime-tokio-native-tls",
Expand All @@ -44,4 +46,3 @@ tracing = "0.1"

[dev-dependencies]
assert_matches = "1.5.0"
db_test_macro = { path = "../db_test_macro" }
11 changes: 6 additions & 5 deletions core/lib/dal/src/blocks_dal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1456,15 +1456,15 @@ impl BlocksDal<'_, '_> {

#[cfg(test)]
mod tests {
use db_test_macro::db_test;
use zksync_contracts::BaseSystemContractsHashes;
use zksync_types::{l2_to_l1_log::L2ToL1Log, Address, ProtocolVersion, ProtocolVersionId};

use super::*;
use crate::ConnectionPool;

#[db_test(dal_crate)]
async fn loading_l1_batch_header(pool: ConnectionPool) {
#[tokio::test]
async fn loading_l1_batch_header() {
let pool = ConnectionPool::test_pool().await;
let mut conn = pool.access_storage().await.unwrap();
conn.blocks_dal()
.delete_l1_batches(L1BatchNumber(0))
Expand Down Expand Up @@ -1523,8 +1523,9 @@ mod tests {
.is_none());
}

#[db_test(dal_crate)]
async fn getting_predicted_gas(pool: ConnectionPool) {
#[tokio::test]
async fn getting_predicted_gas() {
let pool = ConnectionPool::test_pool().await;
let mut conn = pool.access_storage().await.unwrap();
conn.blocks_dal()
.delete_l1_batches(L1BatchNumber(0))
Expand Down
36 changes: 20 additions & 16 deletions core/lib/dal/src/blocks_web3_dal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,6 @@ impl BlocksWeb3Dal<'_, '_> {

#[cfg(test)]
mod tests {
use db_test_macro::db_test;
use zksync_contracts::BaseSystemContractsHashes;
use zksync_types::{
block::{miniblock_hash, MiniblockHeader},
Expand All @@ -592,9 +591,10 @@ mod tests {
use super::*;
use crate::{tests::create_miniblock_header, ConnectionPool};

#[db_test(dal_crate)]
async fn getting_web3_block_and_tx_count(connection_pool: ConnectionPool) {
let mut conn = connection_pool.access_test_storage().await;
#[tokio::test]
async fn getting_web3_block_and_tx_count() {
let connection_pool = ConnectionPool::test_pool().await;
let mut conn = connection_pool.access_storage().await.unwrap();
conn.blocks_dal()
.delete_miniblocks(MiniblockNumber(0))
.await
Expand Down Expand Up @@ -659,9 +659,10 @@ mod tests {
}
}

#[db_test(dal_crate)]
async fn resolving_earliest_block_id(connection_pool: ConnectionPool) {
let mut conn = connection_pool.access_test_storage().await;
#[tokio::test]
async fn resolving_earliest_block_id() {
let connection_pool = ConnectionPool::test_pool().await;
let mut conn = connection_pool.access_storage().await.unwrap();
conn.blocks_dal()
.delete_miniblocks(MiniblockNumber(0))
.await
Expand All @@ -674,9 +675,10 @@ mod tests {
assert_eq!(miniblock_number.unwrap(), Some(MiniblockNumber(0)));
}

#[db_test(dal_crate)]
async fn resolving_latest_block_id(connection_pool: ConnectionPool) {
let mut conn = connection_pool.access_test_storage().await;
#[tokio::test]
async fn resolving_latest_block_id() {
let connection_pool = ConnectionPool::test_pool().await;
let mut conn = connection_pool.access_storage().await.unwrap();
conn.blocks_dal()
.delete_miniblocks(MiniblockNumber(0))
.await
Expand Down Expand Up @@ -729,9 +731,10 @@ mod tests {
assert_eq!(miniblock_number.unwrap(), Some(MiniblockNumber(1)));
}

#[db_test(dal_crate)]
async fn resolving_block_by_hash(connection_pool: ConnectionPool) {
let mut conn = connection_pool.access_test_storage().await;
#[tokio::test]
async fn resolving_block_by_hash() {
let connection_pool = ConnectionPool::test_pool().await;
let mut conn = connection_pool.access_storage().await.unwrap();
conn.blocks_dal()
.delete_miniblocks(MiniblockNumber(0))
.await
Expand Down Expand Up @@ -759,9 +762,10 @@ mod tests {
assert_eq!(miniblock_number.unwrap(), None);
}

#[db_test(dal_crate)]
async fn getting_miniblocks_for_virtual_block(connection_pool: ConnectionPool) {
let mut conn = connection_pool.access_test_storage().await;
#[tokio::test]
async fn getting_miniblocks_for_virtual_block() {
let connection_pool = ConnectionPool::test_pool().await;
let mut conn = connection_pool.access_storage().await.unwrap();

conn.protocol_versions_dal()
.save_protocol_version_with_tx(ProtocolVersion::default())
Expand Down
8 changes: 1 addition & 7 deletions core/lib/dal/src/connection/holder.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
// Built-in deps
use std::fmt;
// External imports
use sqlx::pool::PoolConnection;
use sqlx::{postgres::Postgres, PgConnection, Transaction};
// Workspace imports
// Local imports
use crate::connection::test_pool::TestPoolLock;
use std::fmt;

/// Connection holder unifies the type of underlying connection, which
/// can be either pooled or direct.
pub enum ConnectionHolder<'a> {
Pooled(PoolConnection<Postgres>),
Direct(PgConnection),
Transaction(Transaction<'a, Postgres>),
TestTransaction(TestPoolLock),
}

impl<'a> fmt::Debug for ConnectionHolder<'a> {
Expand All @@ -22,7 +17,6 @@ impl<'a> fmt::Debug for ConnectionHolder<'a> {
Self::Pooled(_) => write!(f, "Pooled connection"),
Self::Direct(_) => write!(f, "Direct connection"),
Self::Transaction(_) => write!(f, "Database Transaction"),
Self::TestTransaction(_) => write!(f, "Test Database Transaction"),
}
}
}
Loading