Skip to content

Commit f061dc1

Browse files
committed
fixup! feat: add request body size configuration
move postgres-specific test from KvStoreTestSuite
1 parent ac2171e commit f061dc1

2 files changed

Lines changed: 71 additions & 24 deletions

File tree

rust/api/src/kv_store_tests.rs

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ macro_rules! define_kv_store_tests {
4444
create_test!(put_should_fail_when_global_version_mismatched);
4545
create_test!(put_should_succeed_when_no_global_version_is_given);
4646
create_test!(put_and_delete_should_succeed_as_atomic_transaction);
47-
create_test!(put_should_succeed_with_maximum_supported_value_size);
4847
create_test!(delete_should_succeed_when_item_exists);
4948
create_test!(delete_should_succeed_when_item_does_not_exist);
5049
create_test!(delete_should_be_idempotent);
@@ -267,29 +266,6 @@ pub trait KvStoreTestSuite {
267266
Ok(())
268267
}
269268

270-
async fn put_should_succeed_with_maximum_supported_value_size() -> Result<(), VssError> {
271-
const MAXIMUM_SUPPORTED_VALUE_SIZE: usize = 1024 * 1024 * 1024;
272-
const PROTOCOL_OVERHEAD_MARGIN: usize = 150;
273-
let kv_store = Self::create_store().await;
274-
let ctx = TestContext::new(&kv_store);
275-
276-
// Construct entry that's for a field that's the maximum size of a non-"large_object" object
277-
let large_value = vec![0u8; MAXIMUM_SUPPORTED_VALUE_SIZE - PROTOCOL_OVERHEAD_MARGIN];
278-
let kv = KeyValue { key: "k1".into(), version: 0, value: Bytes::from(large_value) };
279-
280-
// Put succeeds
281-
ctx.put_objects(None, vec![kv]).await?;
282-
283-
// Retrieval succeeds
284-
let result = ctx.get_object("k1").await?;
285-
assert_eq!(result.value.len(), MAXIMUM_SUPPORTED_VALUE_SIZE - PROTOCOL_OVERHEAD_MARGIN);
286-
assert!(result.value.iter().all(|&b| b == 0));
287-
288-
ctx.delete_object(result).await?;
289-
290-
Ok(())
291-
}
292-
293269
async fn delete_should_succeed_when_item_exists() -> Result<(), VssError> {
294270
let kv_store = Self::create_store().await;
295271
let ctx = TestContext::new(&kv_store);

rust/impls/src/postgres_store.rs

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -660,10 +660,15 @@ where
660660
}
661661

662662
#[cfg(test)]
663+
663664
mod tests {
664665
use super::{drop_database, DUMMY_MIGRATION, MIGRATIONS};
665666
use crate::postgres_store::PostgresPlaintextBackend;
666667
use api::define_kv_store_tests;
668+
use api::kv_store::KvStore;
669+
use api::types::{DeleteObjectRequest, GetObjectRequest, KeyValue, PutObjectRequest};
670+
671+
use bytes::Bytes;
667672
use tokio::sync::OnceCell;
668673
use tokio_postgres::NoTls;
669674

@@ -779,4 +784,70 @@ mod tests {
779784

780785
drop_database(POSTGRES_ENDPOINT, DEFAULT_DB, vss_db, NoTls).await.unwrap();
781786
}
787+
788+
#[tokio::test]
789+
async fn supports_objects_up_to_non_large_object_threshold() {
790+
let vss_db = "supports_objects_up_to_non_large_object_threshold";
791+
let _ = drop_database(POSTGRES_ENDPOINT, DEFAULT_DB, vss_db, NoTls).await;
792+
793+
const MAXIMUM_SUPPORTED_VALUE_SIZE: usize = 1024 * 1024 * 1024;
794+
const PROTOCOL_OVERHEAD_MARGIN: usize = 150;
795+
796+
// Construct entry that's for a field that's the maximum size of a non-"large_object" object
797+
let large_value = vec![0u8; MAXIMUM_SUPPORTED_VALUE_SIZE - PROTOCOL_OVERHEAD_MARGIN];
798+
let kv = KeyValue { key: "k1".into(), version: 0, value: Bytes::from(large_value) };
799+
800+
{
801+
let store =
802+
PostgresPlaintextBackend::new(POSTGRES_ENDPOINT, DEFAULT_DB, vss_db).await.unwrap();
803+
let (start, end) = store.migrate_vss_database(MIGRATIONS).await.unwrap();
804+
assert_eq!(start, MIGRATIONS_START);
805+
assert_eq!(end, MIGRATIONS_END);
806+
assert_eq!(store.get_upgrades_list().await, [MIGRATIONS_START]);
807+
assert_eq!(store.get_schema_version().await, MIGRATIONS_END);
808+
809+
// Round trip with non-large_object of threshold size
810+
811+
store
812+
.put(
813+
"token".to_string(),
814+
PutObjectRequest {
815+
store_id: "store_id".to_string(),
816+
global_version: None,
817+
transaction_items: vec![kv],
818+
delete_items: vec![],
819+
},
820+
)
821+
.await
822+
.unwrap();
823+
824+
let resp_kv = store
825+
.get(
826+
"token".to_string(),
827+
GetObjectRequest { store_id: "store_id".to_string(), key: "k1".to_string() },
828+
)
829+
.await
830+
.unwrap()
831+
.value
832+
.unwrap();
833+
assert_eq!(
834+
resp_kv.value.len(),
835+
MAXIMUM_SUPPORTED_VALUE_SIZE - PROTOCOL_OVERHEAD_MARGIN
836+
);
837+
assert!(resp_kv.value.iter().all(|&b| b == 0));
838+
839+
store
840+
.delete(
841+
"token".to_string(),
842+
DeleteObjectRequest {
843+
store_id: "store_id".to_string(),
844+
key_value: Some(resp_kv),
845+
},
846+
)
847+
.await
848+
.unwrap();
849+
};
850+
851+
drop_database(POSTGRES_ENDPOINT, DEFAULT_DB, vss_db, NoTls).await.unwrap();
852+
}
782853
}

0 commit comments

Comments
 (0)