MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / consumer_group_round_robin

Function consumer_group_round_robin

nodedb/src/control/pubsub.rs:441–471  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

439
440 #[tokio::test]
441 async fn consumer_group_round_robin() {
442 let registry = TopicRegistry::new(1000);
443 registry.create_topic("tasks").unwrap();
444
445 // Two members in the same consumer group.
446 let (_id1, mut rx1, _) = registry.subscribe_group("tasks", "workers", 0).unwrap();
447 let (_id2, mut rx2, _) = registry.subscribe_group("tasks", "workers", 0).unwrap();
448
449 // Publish 4 messages.
450 registry.publish("tasks", "a".into(), "system").unwrap();
451 registry.publish("tasks", "b".into(), "system").unwrap();
452 registry.publish("tasks", "c".into(), "system").unwrap();
453 registry.publish("tasks", "d".into(), "system").unwrap();
454
455 // Each member should get ~2 messages (round-robin).
456 let mut count1 = 0;
457 let mut count2 = 0;
458 while let Ok(msg) = rx1.try_recv() {
459 count1 += 1;
460 let _ = msg;
461 }
462 while let Ok(msg) = rx2.try_recv() {
463 count2 += 1;
464 let _ = msg;
465 }
466 assert_eq!(count1 + count2, 4);
467 assert!(
468 count1 >= 1 && count2 >= 1,
469 "both members should get messages: c1={count1}, c2={count2}"
470 );
471 }
472
473 #[test]
474 fn consumer_group_stats() {

Callers

nothing calls this directly

Calls 4

create_topicMethod · 0.80
subscribe_groupMethod · 0.80
try_recvMethod · 0.80
publishMethod · 0.45

Tested by

no test coverage detected