Skip to content

Commit

Permalink
remove manual setup calls, use ctor to run before test setup
Browse files Browse the repository at this point in the history
  • Loading branch information
insipx committed Dec 7, 2023
1 parent 187eda9 commit 49ff22f
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 19 deletions.
11 changes: 11 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions xmtp_mls/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,4 @@ tempfile = "3.5.0"
tracing-subscriber = { version = "0.3.17", features = ["env-filter"] }
xmtp_api_grpc = { path = "../xmtp_api_grpc" }
flume = "0.11"
ctor = "0.2"
2 changes: 0 additions & 2 deletions xmtp_mls/src/api_client_wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -650,8 +650,6 @@ mod tests {

#[tokio::test]
async fn it_retries_twice_then_succeeds() {
crate::tests::setup();

let mut mock_api = MockApiClient::new();
let topic = "topic";
let start_time_ns = 10;
Expand Down
3 changes: 0 additions & 3 deletions xmtp_mls/src/groups/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -798,8 +798,6 @@ mod tests {

#[tokio::test]
async fn test_add_members() {
crate::tests::setup();

let client = ClientBuilder::new_test_client(generate_local_wallet().into()).await;
let client_2 = ClientBuilder::new_test_client(generate_local_wallet().into()).await;
client_2.register_identity().await.unwrap();
Expand All @@ -823,7 +821,6 @@ mod tests {

#[tokio::test]
async fn test_add_invalid_member() {
crate::tests::setup();
let client = ClientBuilder::new_test_client(generate_local_wallet().into()).await;
let group = client.create_group().expect("create group");

Expand Down
4 changes: 3 additions & 1 deletion xmtp_mls/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,12 @@ pub trait Delete<Model> {
#[cfg(test)]
mod tests {
use std::sync::Once;

static INIT: Once = Once::new();

/// Setup for tests
pub fn setup() {
#[ctor::ctor]
fn setup() {
INIT.call_once(|| {
tracing_subscriber::fmt::init();
})
Expand Down
12 changes: 0 additions & 12 deletions xmtp_mls/src/retry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,6 @@ mod tests {

#[test]
fn it_retries_twice_and_succeeds() {
crate::tests::setup();

let mut i = 0;
let mut test_fn = || -> Result<(), SomeError> {
if i == 2 {
Expand All @@ -309,8 +307,6 @@ mod tests {

#[test]
fn it_works_with_random_args() {
crate::tests::setup();

let mut i = 0;
let list = vec!["String".into(), "Foo".into()];
let mut test_fn = || -> Result<(), SomeError> {
Expand All @@ -326,8 +322,6 @@ mod tests {

#[test]
fn it_fails_on_three_retries() {
crate::tests::setup();

let result: Result<(), SomeError> = retry!(
Retry::default(),
(|| -> Result<(), SomeError> {
Expand All @@ -341,8 +335,6 @@ mod tests {

#[test]
fn it_only_runs_non_retryable_once() {
crate::tests::setup();

let mut attempts = 0;
let mut test_fn = || -> Result<(), SomeError> {
attempts += 1;
Expand All @@ -356,8 +348,6 @@ mod tests {

#[tokio::test]
async fn it_works_async() {
crate::tests::setup();

async fn retryable_async_fn(rx: &flume::Receiver<usize>) -> Result<(), SomeError> {
let val = rx.recv_async().await.unwrap();
if val == 2 {
Expand All @@ -383,8 +373,6 @@ mod tests {

#[tokio::test]
async fn it_works_async_mut() {
crate::tests::setup();

async fn retryable_async_fn(data: &mut usize) -> Result<(), SomeError> {
if *data == 2 {
return Ok(());
Expand Down
1 change: 0 additions & 1 deletion xmtp_mls/src/storage/encrypted_store/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,6 @@ mod tests {
where
F: FnOnce(&DbConnection) -> R,
{
crate::tests::setup();
let store = EncryptedMessageStore::new(
StorageOption::Ephemeral,
EncryptedMessageStore::generate_enc_key(),
Expand Down

0 comments on commit 49ff22f

Please sign in to comment.