MCPcopy Create free account
hub / github.com/MaterializeInc/materialize / postgres_consensus

Function postgres_consensus

src/persist/src/postgres.rs:709–767  ·  view source on GitHub ↗

error: unsupported operation: can't call foreign function `TLS_client_method` on OS `linux`

()

Source from the content-addressed store, hash-verified

707 #[mz_ore::test(tokio::test(flavor = "multi_thread"))]
708 #[cfg_attr(miri, ignore)] // error: unsupported operation: can't call foreign function `TLS_client_method` on OS `linux`
709 async fn postgres_consensus() -> Result<(), ExternalError> {
710 let config = match PostgresConsensusConfig::new_for_test()? {
711 Some(config) => config,
712 None => {
713 info!(
714 "{} env not set: skipping test that uses external service",
715 PostgresConsensusConfig::EXTERNAL_TESTS_POSTGRES_URL
716 );
717 return Ok(());
718 }
719 };
720
721 consensus_impl_test(|| PostgresConsensus::open(config.clone())).await?;
722
723 // and now verify the implementation-specific `drop_and_recreate` works as intended
724 let consensus = PostgresConsensus::open(config.clone()).await?;
725 let key = Uuid::new_v4().to_string();
726 let state = VersionedData {
727 seqno: SeqNo(0),
728 data: Bytes::from("abc"),
729 };
730
731 assert_eq!(
732 consensus.compare_and_set(&key, state.clone()).await,
733 Ok(CaSResult::Committed),
734 );
735
736 assert_eq!(consensus.head(&key).await, Ok(Some(state.clone())));
737
738 consensus.drop_and_recreate().await?;
739
740 assert_eq!(consensus.head(&key).await, Ok(None));
741
742 // This should be a separate postgres_consensus_blocking test, but nextest makes it
743 // difficult since we can't specify that both tests touch the consensus table and thus
744 // interfere with each other.
745 let config = match PostgresConsensusConfig::new_for_test()? {
746 Some(config) => config,
747 None => {
748 info!(
749 "{} env not set: skipping test that uses external service",
750 PostgresConsensusConfig::EXTERNAL_TESTS_POSTGRES_URL
751 );
752 return Ok(());
753 }
754 };
755
756 let consensus: PostgresConsensus = PostgresConsensus::open(config.clone()).await?;
757 // Max size in test is 2... let's saturate the pool.
758 let _conn1 = consensus.get_connection().await?;
759 let _conn2 = consensus.get_connection().await?;
760
761 // And finally, we should see the next connect time out.
762 let conn3 = consensus.get_connection().await;
763
764 assert_err!(conn3);
765
766 Ok(())

Callers

nothing calls this directly

Calls 6

consensus_impl_testFunction · 0.85
SeqNoClass · 0.85
drop_and_recreateMethod · 0.80
cloneMethod · 0.45
to_stringMethod · 0.45
get_connectionMethod · 0.45

Tested by

no test coverage detected