Skip to content

Commit

Permalink
chore: fix byzantine failures on functional tests (#206)
Browse files Browse the repository at this point in the history
  • Loading branch information
geekbrother committed Sep 21, 2023
1 parent 87ea075 commit e0d8a39
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 63 deletions.
4 changes: 2 additions & 2 deletions tests/functional/multitenant/apns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ async fn tenant_update_apns_bad_token(ctx: &mut EchoServerContext) {

// Register tenant
let client = reqwest::Client::new();
let response = client
client
.post(format!("http://{}/tenants", ctx.server.public_addr))
.json(&payload)
.send()
Expand Down Expand Up @@ -92,7 +92,7 @@ async fn tenant_update_apns_bad_certificate(ctx: &mut EchoServerContext) {

// Register tenant
let client = reqwest::Client::new();
let response = client
client
.post(format!("http://{}/tenants", ctx.server.public_addr))
.json(&payload)
.send()
Expand Down
4 changes: 2 additions & 2 deletions tests/functional/multitenant/fcm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ async fn tenant_update_fcm(ctx: &mut EchoServerContext) {

// Register tenant
let client = reqwest::Client::new();
let response = client
client
.post(format!("http://{}/tenants", ctx.server.public_addr))
.json(&payload)
.send()
Expand Down Expand Up @@ -56,7 +56,7 @@ async fn tenant_update_fcm_bad(ctx: &mut EchoServerContext) {

// Register tenant
let client = reqwest::Client::new();
let response = client
client
.post(format!("http://{}/tenants", ctx.server.public_addr))
.json(&payload)
.send()
Expand Down
112 changes: 56 additions & 56 deletions tests/functional/stores/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,72 +7,77 @@ use {
test_context::test_context,
};

pub const TOKEN: &str = "noop-111-222-333";

#[test_context(StoreContext)]
#[tokio::test]
async fn client_creation(ctx: &mut StoreContext) {
let res = ctx
.clients
.create_client(TENANT_ID, &gen_id(), Client {
let id = format!("id-{}", gen_id());
let token = format!("token-{}", gen_id());
ctx.clients
.create_client(TENANT_ID, &id, Client {
tenant_id: TENANT_ID.to_string(),
push_type: ProviderKind::Noop,
token: TOKEN.to_string(),
token,
})
.await;

assert!(res.is_ok())
.await
.unwrap();
// Cleaning up records
ctx.clients.delete_client(TENANT_ID, &id).await.unwrap();
}

#[test_context(StoreContext)]
#[tokio::test]
async fn client_creation_fcm(ctx: &mut StoreContext) {
let res = ctx
.clients
.create_client(TENANT_ID, &gen_id(), Client {
let id = format!("id-{}", gen_id());
let token = format!("token-{}", gen_id());
ctx.clients
.create_client(TENANT_ID, &id, Client {
tenant_id: TENANT_ID.to_string(),
push_type: ProviderKind::Fcm,
token: TOKEN.to_string(),
token,
})
.await;

assert!(res.is_ok())
.await
.unwrap();
// Cleaning up records
ctx.clients.delete_client(TENANT_ID, &id).await.unwrap();
}

#[test_context(StoreContext)]
#[tokio::test]
async fn client_creation_apns(ctx: &mut StoreContext) {
let res = ctx
.clients
.create_client(TENANT_ID, &gen_id(), Client {
let id = format!("id-{}", gen_id());
let token = format!("token-{}", gen_id());
ctx.clients
.create_client(TENANT_ID, &id, Client {
tenant_id: TENANT_ID.to_string(),
push_type: ProviderKind::Apns,
token: TOKEN.to_string(),
token,
})
.await;

assert!(res.is_ok())
.await
.unwrap();
// Cleaning up records
ctx.clients.delete_client(TENANT_ID, &id).await.unwrap();
}

#[test_context(StoreContext)]
#[tokio::test]
async fn client_upsert_token(ctx: &mut StoreContext) {
let id = gen_id();
let id = format!("id-{}", gen_id());
let token = format!("token-{}", gen_id());

// Initial Client creation
ctx.clients
.create_client(TENANT_ID, &id, Client {
tenant_id: TENANT_ID.to_string(),
push_type: ProviderKind::Fcm,
token: TOKEN.to_string(),
token: token.clone(),
})
.await
.unwrap();
let insert_result = ctx.clients.get_client(TENANT_ID, &id).await.unwrap();
assert_eq!(insert_result.token, TOKEN);
assert_eq!(insert_result.token, token);

// Updating token for the same id
let updated_token = gen_id();
let updated_token = format!("token-{}", gen_id());
ctx.clients
.create_client(TENANT_ID, &id, Client {
tenant_id: TENANT_ID.to_string(),
Expand All @@ -91,27 +96,28 @@ async fn client_upsert_token(ctx: &mut StoreContext) {
#[test_context(StoreContext)]
#[tokio::test]
async fn client_upsert_id(ctx: &mut StoreContext) {
let id = gen_id();
let id = format!("id-{}", gen_id());
let token = format!("token-{}", gen_id());

// Initial Client creation
ctx.clients
.create_client(TENANT_ID, &id, Client {
tenant_id: TENANT_ID.to_string(),
push_type: ProviderKind::Fcm,
token: TOKEN.to_string(),
token: token.clone(),
})
.await
.unwrap();
let insert_result = ctx.clients.get_client(TENANT_ID, &id).await.unwrap();
assert_eq!(insert_result.token, TOKEN);
assert_eq!(insert_result.token, token.clone());

// Updating id for the same token
let updated_id = gen_id();
ctx.clients
.create_client(TENANT_ID, &updated_id, Client {
tenant_id: TENANT_ID.to_string(),
push_type: ProviderKind::Fcm,
token: TOKEN.to_string(),
token: token.clone(),
})
.await
.unwrap();
Expand All @@ -120,7 +126,7 @@ async fn client_upsert_id(ctx: &mut StoreContext) {
.get_client(TENANT_ID, &updated_id)
.await
.unwrap();
assert_eq!(updated_id_result.token, TOKEN);
assert_eq!(updated_id_result.token, token);

// Cleaning up records
ctx.clients
Expand All @@ -132,46 +138,40 @@ async fn client_upsert_id(ctx: &mut StoreContext) {
#[test_context(StoreContext)]
#[tokio::test]
async fn client_deletion(ctx: &mut StoreContext) {
let id = gen_id();
let id = format!("id-{}", gen_id());
let token = format!("token-{}", gen_id());

let res = ctx
.clients
ctx.clients
.create_client(TENANT_ID, &id, Client {
tenant_id: TENANT_ID.to_string(),
push_type: ProviderKind::Noop,
token: TOKEN.to_string(),
token,
})
.await;

assert!(res.is_ok());

let delete_res = ctx.clients.delete_client(TENANT_ID, &id).await;

assert!(delete_res.is_ok());
.await
.unwrap();
ctx.clients.delete_client(TENANT_ID, &id).await.unwrap();
}

#[test_context(StoreContext)]
#[tokio::test]
async fn client_fetch(ctx: &mut StoreContext) {
let id = gen_id();
let id = format!("id-{}", gen_id());
let token = format!("token-{}", gen_id());

let res = ctx
.clients
ctx.clients
.create_client(TENANT_ID, &id, Client {
tenant_id: TENANT_ID.to_string(),
push_type: ProviderKind::Noop,
token: TOKEN.to_string(),
token: token.clone(),
})
.await;

assert!(res.is_ok());

let client_res = ctx.clients.get_client(TENANT_ID, &id).await;

assert!(client_res.is_ok());
.await
.unwrap();

let client = client_res.expect("failed to unwrap client");
let client = ctx.clients.get_client(TENANT_ID, &id).await.unwrap();

assert_eq!(client.token, TOKEN.to_string());
assert_eq!(client.token, token);
assert_eq!(client.push_type, ProviderKind::Noop);

// Cleaning up records
ctx.clients.delete_client(TENANT_ID, &id).await.unwrap();
}
7 changes: 4 additions & 3 deletions tests/functional/stores/notification.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use {
crate::{
context::StoreContext,
functional::stores::{client::TOKEN, gen_id, TENANT_ID},
functional::stores::{gen_id, TENANT_ID},
},
echo_server::{
handlers::push_message::MessagePayload,
Expand All @@ -13,13 +13,14 @@ use {
};

pub async fn get_client(client_store: &ClientStoreArc) -> String {
let id = gen_id();
let id = format!("id-{}", gen_id());
let token = format!("token-{}", gen_id());

client_store
.create_client(TENANT_ID, &id, Client {
tenant_id: TENANT_ID.to_string(),
push_type: ProviderKind::Noop,
token: TOKEN.to_string(),
token,
})
.await
.expect("failed to create client for notification test");
Expand Down

0 comments on commit e0d8a39

Please sign in to comment.