Skip to content

Commit 7726fe8

Browse files
Add a test for #1121 (#1125)
# Description of Changes While working on #1111 I realised that we have a bug with subscriptions not being unique when multiple clients with the same identity are connected. I fixed the bug and only then realised it was already fixed yesterday in #1121. When working on my changes I created a test for the issue, so I guess it doesn't hurt to at least submit it. # Expected complexity level and risk 1 --------- Co-authored-by: clockwork-labs-bot <clockwork-labs-bot@users.noreply.github.com>
1 parent dea509b commit 7726fe8

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

crates/core/src/subscription/module_subscription_actor.rs

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4357,4 +4357,65 @@ mod tests {
43574357

43584358
Ok(())
43594359
}
4360+
4361+
#[tokio::test]
4362+
async fn test_subscriptions_for_the_same_client_identity() -> anyhow::Result<()> {
4363+
let db = relational_db()?;
4364+
4365+
let identity = identity_from_u8(7);
4366+
let client_id_for_a = ClientActorId {
4367+
identity,
4368+
connection_id: connection_id_from_u8(1),
4369+
name: ClientName(1),
4370+
};
4371+
let client_id_for_b = ClientActorId {
4372+
identity,
4373+
connection_id: connection_id_from_u8(2),
4374+
name: ClientName(2),
4375+
};
4376+
4377+
let (tx_for_a, mut rx_for_a) = client_connection(client_id_for_a, &db);
4378+
let (tx_for_b, mut rx_for_b) = client_connection(client_id_for_b, &db);
4379+
4380+
let auth_for_a = AuthCtx::new(db.owner_identity(), client_id_for_a.identity);
4381+
let auth_for_b = AuthCtx::new(db.owner_identity(), client_id_for_b.identity);
4382+
4383+
let subs = ModuleSubscriptions::for_test_enclosing_runtime(db.clone());
4384+
let table_id = db.create_table_for_test("t", &[("a", AlgebraicType::U8)], &[])?;
4385+
let schema = ProductType::from([AlgebraicType::U8]);
4386+
4387+
let mut query_ids = 0;
4388+
subscribe_multi(
4389+
&subs,
4390+
auth_for_a,
4391+
&["select * from t where a = 1"],
4392+
tx_for_a,
4393+
&mut query_ids,
4394+
)
4395+
.await?;
4396+
subscribe_multi(
4397+
&subs,
4398+
auth_for_b,
4399+
&["select * from t where a = 2"],
4400+
tx_for_b,
4401+
&mut query_ids,
4402+
)
4403+
.await?;
4404+
4405+
assert!(matches!(
4406+
rx_for_a.recv().await,
4407+
Some(OutboundMessage::V1(SerializableMessage::Subscription(_)))
4408+
));
4409+
assert!(matches!(
4410+
rx_for_b.recv().await,
4411+
Some(OutboundMessage::V1(SerializableMessage::Subscription(_)))
4412+
));
4413+
4414+
commit_tx(&db, &subs, [], [(table_id, product![1_u8]), (table_id, product![2_u8])])?;
4415+
4416+
assert_tx_update_for_table(rx_for_a.recv(), table_id, &schema, [product![1_u8]], []).await;
4417+
assert_tx_update_for_table(rx_for_b.recv(), table_id, &schema, [product![2_u8]], []).await;
4418+
4419+
Ok(())
4420+
}
43604421
}

0 commit comments

Comments
 (0)