Consumer’ı test etme
Macro, topology, lifecycle ve gerçek broker/DB senaryolarını ayrı doğrulama katmanlarıyla test edin.
Derlenen bir handler, broker bağlantısının veya DB transaction’ının çalıştığını tek başına kanıtlamaz. Testleri önce broker gerektirmeyen contract kontrolleriyle başlatın; gerçek delivery, retry, recovery ve transaction senaryolarını daha sonra ayrı ortamda çalıştırın. Her sonuçta neyin gerçekten çalıştırıldığını belirtin.
Feature profillerini ayrı derleyin#
cargo +1.96.1 check
cargo +1.96.1 test --test topology_testBu komutlar kendi uygulama projenizde çalışır. İlk komut seçili manifesti kontrol eder; ikinci komut aşağıdaki dosyanın tests/topology_test.rs yoluna eklenmesini ister. Single ve factory örneklerini ayrı uygulama profillerinde tutun. --all-features, aynı backend’in iki mode’unu birleştirip yanlış dependency graph oluşturabilir.
Broker olmadan topology contract testi#
[dependencies]
lilyrs = { version = "0.1.0", features = ["consumer", "config"] }
[dev-dependencies]
toml = "0.8"Mevcut serde gibi uygulama bağımlılıklarını koruyun. Test kendi TOML fixture’ını içerir; localhost credential değerleri yalnız deserialize edilen fixture’dır, bu testte ağ bağlantısı açılmaz. Üç kontrol; retry bucket’larının üretilmesini, eksik retention/exclusive queue reddini ve retry=0/finite jitter kurallarını doğrular.
use lilyrs::config::{LilyConfig, RabbitMqTopologyPlan};
fn config() -> LilyConfig { toml::from_str(r#"
[rabbitmq.consumer]
hostname = "127.0.0.1"
port = 5672
username = "guest"
password = "guest"
vhost = "/"
use_tls = false
pool_size = 1
[[rabbitmq.topology.queues]]
name = "orders.created"
exchange_name = "orders"
routing_key = "orders.created"
concurrency = 2
prefetch_count = 10
retry_attempts = 3
retry_backoff_millis = 1000
max_retry_backoff_millis = 60000
[rabbitmq.topology.queues.retention]
main_max_messages = 100000
main_max_bytes = 1073741824
retry_bucket_max_messages = 10000
retry_bucket_max_bytes = 268435456
dead_letter_max_messages = 10000
dead_letter_max_bytes = 268435456
"#).unwrap() }
#[test]
fn documented_topology_compiles_with_three_fixed_retry_buckets() {
let config = config();
let plan = RabbitMqTopologyPlan::compile(&config.rabbitmq.topology).unwrap();
let queue = plan.queue("orders.created").unwrap();
assert_eq!(queue.dead_letter_queue_name(), "orders.created.dlq.v2");
assert_eq!(queue.retry_buckets().iter().map(|b| b.delay_millis()).collect::<Vec<_>>(), vec![1000,2000,4000]);
}
#[test]
fn missing_retention_and_exclusive_queue_are_rejected_before_broker_io() {
let mut topology = config().rabbitmq.topology;
topology.queues[0].retention = None;
assert!(RabbitMqTopologyPlan::compile(&topology).is_err());
let mut topology = config().rabbitmq.topology;
topology.queues[0].exclusive = true;
assert!(RabbitMqTopologyPlan::compile(&topology).is_err());
}
#[test]
fn retry_zero_declares_no_delay_buckets_and_jitter_is_finite() {
let mut topology = config().rabbitmq.topology;
topology.queues[0].retry_attempts = 0;
assert!(RabbitMqTopologyPlan::compile(&topology).unwrap().queues()[0].retry_buckets().is_empty());
topology.queues[0].retry_jitter_ratio = f64::NAN;
assert!(RabbitMqTopologyPlan::compile(&topology).is_err());
}Tam topology_test.rs örneğini indirin.
Başlamadan iptal edilen lifecycle#
Configuration dosyasına veya broker’a erişmeden cancellation contract’ını da test edebilirsiniz. Aşağıdaki test için dev-dependency olarak Tokio’nun macros ve rt-multi-thread feature’larını açın. Önceden iptal edilmiş token, normal startup kaynakları edinilmeden gözlenir.
use lilyrs::consumer::{CancellationToken, Consumer};
#[tokio::test]
async fn cancellation_before_startup_needs_no_broker() {
let cancellation = CancellationToken::new();
cancellation.cancel();
Consumer::builder()
.run_with_cancellation(cancellation)
.await
.expect("pre-cancelled startup should finish cleanly");
}Canlı entegrasyon testlerinin kapsamı#
| Senaryo | Gereken ortam ve gözlem |
|---|---|
| Delivery ve retry/DLQ | İzole RabbitMQ; canonical mesaj, confirm, original ACK, retry ve DLQ sonucu |
| Recovery ve shutdown | Bağlantı kaybı, readiness geçişi, graceful/forced drain ve terminal report |
| PostgreSQL inbox/outbox | İzole DB; migration, duplicate, commit/ACK ve publish/mark crash pencereleri |
| MongoDB inbox/outbox | Transaction-capable deployment; session, lease, body replay ve ambiguous commit |
| AsyncAPI | Başarılı queue registration sonrasında belge attachment ve schema doğrulaması |
Kaynak repository’deki qualification/E2E testleri bu senaryoların örneklerini içerir. Bazıları disposable storage ve explicit opt-in ister; MongoDB fault senaryoları replica set ve test command desteği isteyebilir. Private test helper’larını uygulamanızın kanonik API’si olarak kopyalamayın. Üretim veritabanına bu fixture’ları yönlendirmeyin.
Bu dokümantasyonun doğrulama kapsamı#
18 Eylül 2026 tarihli dokümantasyon çalışmasında PostgreSQL ve MongoDB’nin ayrı single/factory modülleri ile AsyncAPI modülü, Rust 1.96.1 ve crates.io lilyrs = "=0.1.0" kullanılarak derlendi. Yerel framework path/patch dependency’si kullanılmadı. Yukarıdaki üç topology testi ve önceden iptal edilmiş Consumer testi başarıyla çalıştırıldı.
Bu sonuçlar canlı RabbitMQ/DB transaction testi değildir. Bu çalışma sırasında broker delivery, PostgreSQL/MongoDB migration, replica-set replay, TLS/mTLS, process-crash veya AsyncAPI attachment E2E’si çalıştırılmadı. Source qualification dosyalarının incelenmesi, o testlerin bu oturumda geçtiği iddiası olarak sunulmaz.
Site repository’sindeki registry checker ile seçili örneği yeniden kontrol edebilirsiniz. --mode check manifest/source/provenance kanıtını; --mode smoke yalnız runtime testi tanımlanmış profillerin test sonucunu kaydeder. --offline ancak dependency cache’i hazırsa eklenir.
python3 scripts/check-rust-examples.py --profile consumer-postgresql --mode check
python3 scripts/check-rust-examples.py --profile consumer-mongodb-factory --mode check
python3 scripts/check-rust-examples.py --profile consumer-topology-test --mode smokeBu sayfanın kaynakları v0.1.0
Anlatım, incelenen framework commit’ine dayanır.
- foundation/lily_config/src/topology_plan.rs
- framework/lily_consumer/src/consumer.rs
- framework/lily_consumer/src/consumer_runtime_qualification_tests.rs
- framework/lily_consumer/tests/asyncapi_facade.rs
- framework/lily_consumer/tests/postgresql_transactional_consumer_e2e.rs
- framework/lily_consumer/tests/mongodb_transactional_consumer_e2e.rs