Skip to content

Commit a2a810d

Browse files
Change the tests of the linera-views and put the tombstone test for the RocksDb. (#3302)
## Motivation The tests of the `linera-views` can be made shorter in terms of code. The tombstone problem has emerged as a problem for `RocksDb`. We extend this test by supporting some read operations and adding it to the suite of tests for `RocksDb`. ## Proposal We propose the following changes: * Add the testing of read keys to the tombstone key test. * Iterate the reading of the keys from the store to see the evolution of the performance. * Introduce the tombstone test for RocksDb. Besides, there are a number of changes for the tests: * Simplification of the `MemoryContext::new_for_testing` function since the calls always took the same arguments. * Elimination of requirement for `Debug` in the error type since it was not used. * Put the creation of the testing store in the benchmark code. Therefore, only the type is used in the argument which makes the code simpler. ## Test Plan The CI is the object of those changes. ## Release Plan Not relevant to TestNet / DevNet. ## Links None.
1 parent 4d77d02 commit a2a810d

File tree

10 files changed

+157
-190
lines changed

10 files changed

+157
-190
lines changed

linera-chain/src/unit_tests/chain_tests.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ use linera_execution::{
3131
};
3232
use linera_views::{
3333
context::{Context as _, MemoryContext, ViewContext},
34-
memory::{MemoryStore, TEST_MEMORY_MAX_STREAM_QUERIES},
35-
random::generate_test_namespace,
34+
memory::MemoryStore,
3635
views::{View, ViewError},
3736
};
3837
use test_case::test_case;
@@ -54,12 +53,7 @@ where
5453
pub async fn new(chain_id: ChainId) -> Self {
5554
let exec_runtime_context =
5655
TestExecutionRuntimeContext::new(chain_id, ExecutionRuntimeConfig::default());
57-
let namespace = generate_test_namespace();
58-
let context = MemoryContext::new_for_testing(
59-
TEST_MEMORY_MAX_STREAM_QUERIES,
60-
&namespace,
61-
exec_runtime_context,
62-
);
56+
let context = MemoryContext::new_for_testing(exec_runtime_context);
6357
Self::load(context)
6458
.await
6559
.expect("Loading from memory should work")

linera-execution/src/test_utils/system_execution_state.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ use linera_base::{
1616
};
1717
use linera_views::{
1818
context::{Context, MemoryContext},
19-
memory::TEST_MEMORY_MAX_STREAM_QUERIES,
2019
random::generate_test_namespace,
2120
views::{CryptoHashView, View, ViewError},
2221
};
@@ -115,9 +114,7 @@ impl SystemExecutionState {
115114
extra.user_services().insert(id, mock_application.into());
116115
}
117116

118-
let namespace = generate_test_namespace();
119-
let context =
120-
MemoryContext::new_for_testing(TEST_MEMORY_MAX_STREAM_QUERIES, &namespace, extra);
117+
let context = MemoryContext::new_for_testing(extra);
121118
let mut view = ExecutionStateView::load(context)
122119
.await
123120
.expect("Loading from memory should work");

linera-storage-service/benches/store.rs

+13-15
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,32 @@
33

44
use criterion::{black_box, criterion_group, criterion_main, Criterion};
55
use linera_storage_service::client::ServiceStoreClient;
6-
use linera_views::{store::TestKeyValueStore as _, test_utils::performance};
6+
use linera_views::test_utils::performance;
77
use tokio::runtime::Runtime;
88

99
fn bench_storage_service(criterion: &mut Criterion) {
1010
criterion.bench_function("store_storage_service_contains_key", |bencher| {
1111
bencher
1212
.to_async(Runtime::new().expect("Failed to create Tokio runtime"))
1313
.iter_custom(|iterations| async move {
14-
let store = ServiceStoreClient::new_test_store().await.unwrap();
15-
performance::contains_key(store, iterations, black_box).await
14+
performance::contains_key::<ServiceStoreClient, _>(iterations, black_box).await
1615
})
1716
});
1817

1918
criterion.bench_function("store_storage_service_contains_keys", |bencher| {
2019
bencher
2120
.to_async(Runtime::new().expect("Failed to create Tokio runtime"))
2221
.iter_custom(|iterations| async move {
23-
let store = ServiceStoreClient::new_test_store().await.unwrap();
24-
performance::contains_keys(store, iterations, black_box).await
22+
performance::contains_keys::<ServiceStoreClient, _>(iterations, black_box).await
2523
})
2624
});
2725

2826
criterion.bench_function("store_storage_service_find_keys_by_prefix", |bencher| {
2927
bencher
3028
.to_async(Runtime::new().expect("Failed to create Tokio runtime"))
3129
.iter_custom(|iterations| async move {
32-
let store = ServiceStoreClient::new_test_store().await.unwrap();
33-
performance::find_keys_by_prefix(store, iterations, black_box).await
30+
performance::find_keys_by_prefix::<ServiceStoreClient, _>(iterations, black_box)
31+
.await
3432
})
3533
});
3634

@@ -40,8 +38,10 @@ fn bench_storage_service(criterion: &mut Criterion) {
4038
bencher
4139
.to_async(Runtime::new().expect("Failed to create Tokio runtime"))
4240
.iter_custom(|iterations| async move {
43-
let store = ServiceStoreClient::new_test_store().await.unwrap();
44-
performance::find_key_values_by_prefix(store, iterations, black_box).await
41+
performance::find_key_values_by_prefix::<ServiceStoreClient, _>(
42+
iterations, black_box,
43+
)
44+
.await
4545
})
4646
},
4747
);
@@ -50,26 +50,24 @@ fn bench_storage_service(criterion: &mut Criterion) {
5050
bencher
5151
.to_async(Runtime::new().expect("Failed to create Tokio runtime"))
5252
.iter_custom(|iterations| async move {
53-
let store = ServiceStoreClient::new_test_store().await.unwrap();
54-
performance::read_value_bytes(store, iterations, black_box).await
53+
performance::read_value_bytes::<ServiceStoreClient, _>(iterations, black_box).await
5554
})
5655
});
5756

5857
criterion.bench_function("store_storage_service_read_multi_values_bytes", |bencher| {
5958
bencher
6059
.to_async(Runtime::new().expect("Failed to create Tokio runtime"))
6160
.iter_custom(|iterations| async move {
62-
let store = ServiceStoreClient::new_test_store().await.unwrap();
63-
performance::read_multi_values_bytes(store, iterations, black_box).await
61+
performance::read_multi_values_bytes::<ServiceStoreClient, _>(iterations, black_box)
62+
.await
6463
})
6564
});
6665

6766
criterion.bench_function("store_storage_service_write_batch", |bencher| {
6867
bencher
6968
.to_async(Runtime::new().expect("Failed to create Tokio runtime"))
7069
.iter_custom(|iterations| async move {
71-
let store = ServiceStoreClient::new_test_store().await.unwrap();
72-
performance::write_batch(store, iterations).await
70+
performance::write_batch::<ServiceStoreClient>(iterations).await
7371
})
7472
});
7573
}

linera-views/benches/queue_view.rs

+16-27
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
// Copyright (c) Zefchain Labs, Inc.
22
// SPDX-License-Identifier: Apache-2.0
33

4-
use std::{
5-
fmt::Debug,
6-
time::{Duration, Instant},
7-
};
4+
use std::time::{Duration, Instant};
85

96
use criterion::{black_box, criterion_group, criterion_main, Criterion};
107
#[cfg(with_dynamodb)]
@@ -19,7 +16,7 @@ use linera_views::{
1916
memory::MemoryStore,
2017
queue_view::QueueView,
2118
random::{make_deterministic_rng, DeterministicRng},
22-
store::{KeyValueStore, TestKeyValueStore as _},
19+
store::TestKeyValueStore,
2320
views::{CryptoHashRootView, RootView, View},
2421
};
2522
use rand::Rng;
@@ -58,13 +55,13 @@ pub struct QueueStateView<C> {
5855
pub queue: QueueView<C, u8>,
5956
}
6057

61-
pub async fn performance_queue_view<S: KeyValueStore + Clone + Sync + 'static>(
62-
store: S,
58+
pub async fn performance_queue_view<S: TestKeyValueStore + Clone + Sync + 'static>(
6359
iterations: u64,
6460
) -> Duration
6561
where
66-
S::Error: Debug + Send + Sync + 'static,
62+
S::Error: Send + Sync,
6763
{
64+
let store = S::new_test_store().await.unwrap();
6865
let context = ViewContext::<(), S>::create_root_context(store, ())
6966
.await
7067
.unwrap();
@@ -101,8 +98,7 @@ fn bench_queue_view(criterion: &mut Criterion) {
10198
bencher
10299
.to_async(Runtime::new().expect("Failed to create Tokio runtime"))
103100
.iter_custom(|iterations| async move {
104-
let store = MemoryStore::new_test_store().await.unwrap();
105-
performance_queue_view(store, iterations).await
101+
performance_queue_view::<MemoryStore>(iterations).await
106102
})
107103
});
108104

@@ -111,8 +107,7 @@ fn bench_queue_view(criterion: &mut Criterion) {
111107
bencher
112108
.to_async(Runtime::new().expect("Failed to create Tokio runtime"))
113109
.iter_custom(|iterations| async move {
114-
let store = RocksDbStore::new_test_store().await.unwrap();
115-
performance_queue_view(store, iterations).await
110+
performance_queue_view::<RocksDbStore>(iterations).await
116111
})
117112
});
118113

@@ -121,8 +116,7 @@ fn bench_queue_view(criterion: &mut Criterion) {
121116
bencher
122117
.to_async(Runtime::new().expect("Failed to create Tokio runtime"))
123118
.iter_custom(|iterations| async move {
124-
let store = DynamoDbStore::new_test_store().await.unwrap();
125-
performance_queue_view(store, iterations).await
119+
performance_queue_view::<DynamoDbStore>(iterations).await
126120
})
127121
});
128122

@@ -131,8 +125,7 @@ fn bench_queue_view(criterion: &mut Criterion) {
131125
bencher
132126
.to_async(Runtime::new().expect("Failed to create Tokio runtime"))
133127
.iter_custom(|iterations| async move {
134-
let store = ScyllaDbStore::new_test_store().await.unwrap();
135-
performance_queue_view(store, iterations).await
128+
performance_queue_view::<ScyllaDbStore>(iterations).await
136129
})
137130
});
138131
}
@@ -142,13 +135,13 @@ pub struct BucketQueueStateView<C> {
142135
pub queue: BucketQueueView<C, u8, 100>,
143136
}
144137

145-
pub async fn performance_bucket_queue_view<S: KeyValueStore + Clone + Sync + 'static>(
146-
store: S,
138+
pub async fn performance_bucket_queue_view<S: TestKeyValueStore + Clone + Sync + 'static>(
147139
iterations: u64,
148140
) -> Duration
149141
where
150-
S::Error: Debug + Send + Sync + 'static,
142+
S::Error: Send + Sync,
151143
{
144+
let store = S::new_test_store().await.unwrap();
152145
let context = ViewContext::<(), S>::create_root_context(store, ())
153146
.await
154147
.unwrap();
@@ -186,8 +179,7 @@ fn bench_bucket_queue_view(criterion: &mut Criterion) {
186179
bencher
187180
.to_async(Runtime::new().expect("Failed to create Tokio runtime"))
188181
.iter_custom(|iterations| async move {
189-
let store = MemoryStore::new_test_store().await.unwrap();
190-
performance_bucket_queue_view(store, iterations).await
182+
performance_bucket_queue_view::<MemoryStore>(iterations).await
191183
})
192184
});
193185

@@ -196,8 +188,7 @@ fn bench_bucket_queue_view(criterion: &mut Criterion) {
196188
bencher
197189
.to_async(Runtime::new().expect("Failed to create Tokio runtime"))
198190
.iter_custom(|iterations| async move {
199-
let store = RocksDbStore::new_test_store().await.unwrap();
200-
performance_bucket_queue_view(store, iterations).await
191+
performance_bucket_queue_view::<RocksDbStore>(iterations).await
201192
})
202193
});
203194

@@ -206,8 +197,7 @@ fn bench_bucket_queue_view(criterion: &mut Criterion) {
206197
bencher
207198
.to_async(Runtime::new().expect("Failed to create Tokio runtime"))
208199
.iter_custom(|iterations| async move {
209-
let store = DynamoDbStore::new_test_store().await.unwrap();
210-
performance_bucket_queue_view(store, iterations).await
200+
performance_bucket_queue_view::<DynamoDbStore>(iterations).await
211201
})
212202
});
213203

@@ -216,8 +206,7 @@ fn bench_bucket_queue_view(criterion: &mut Criterion) {
216206
bencher
217207
.to_async(Runtime::new().expect("Failed to create Tokio runtime"))
218208
.iter_custom(|iterations| async move {
219-
let store = ScyllaDbStore::new_test_store().await.unwrap();
220-
performance_bucket_queue_view(store, iterations).await
209+
performance_bucket_queue_view::<ScyllaDbStore>(iterations).await
221210
})
222211
});
223212
}

0 commit comments

Comments
 (0)