Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Mock AMQP server cannot serve a link reattach

Aperta
#7,329 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
35/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Tranquilla
Stack tecnologico
cpp
Ambito
backend, testing

Direzione di ricerca

Inizia da sdk/core/azure-core-amqp/test/ut/mock_amqp_server.hpp, in particolare da OnLinkAttached, MessageLoop e OnConnectionStateChanged, quindi esamina reattach_policy_test.cpp e gli entry point di Event Hubs indicati nell’issue. Esegui i test offline esistenti in una build locale ENABLE_UAMQP. Il lavoro è completato quando il mock può forzare il distacco dei link, accettare i reattachments, mantenere isolati gli endpoint e supportare i test di rebuild proposti e la configurazione CI.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

needs-triage

Summary

The mock AMQP server in sdk/core/azure-core-amqp/test/ut/mock_amqp_server.hpp refuses a second attach on a link name that it holds. The server also leaves its message loop after the last link detaches, and it does not start the loop again. A test therefore cannot make the server detach a link and then accept a new attach from the client. The Event Hubs link rebuild code needs that sequence, so the rebuild code has no offline test today. The link rebuild work belongs to #7254.

Motivation

Four properties of the mock server block the sequence.

  • MockServiceEndpoint::OnLinkAttached refuses a duplicate link name, and the two roles fail in different ways. For an incoming receiver role, the method sends a detach with the condition EntityAlreadyExists and returns false (mock_amqp_server.hpp:99-108). For an incoming sender role, the method throws a std::runtime_error from the callback (mock_amqp_server.hpp:138-144).
  • MessageLoop leaves the loop when both link maps become empty (mock_amqp_server.hpp:343-347). OnLinkAttached starts the loop thread only when m_serverThread is not joinable (mock_amqp_server.hpp:155-161). A std::thread stays joinable after its function returns, so the loop never starts again. The message dispatch, the link removal, and the call to EnableLinkPolling all run in that loop (mock_amqp_server.hpp:298-351). A new link therefore gets no service after the loop stops.
  • The server offers no method that detaches a link on demand. The one call to Session::SendDetach is the duplicate name refusal (mock_amqp_server.hpp:106).
  • AmqpServerMock::OnConnectionStateChanged cancels m_listenerContext when a connection reaches End or Error (mock_amqp_server.hpp:699-704). Both constructors copy that context into every service endpoint (mock_amqp_server.hpp:552 and mock_amqp_server.hpp:563). A copy of Azure::Core::Context shares the cancellation state (sdk/core/azure-core/inc/azure/core/context.hpp:225), so one closed connection stops the whole server.

The Event Hubs client rebuilds a link after the service detaches it, and only a live namespace exercises that code today. PartitionClient::RebuildReceiver closes the faulted receiver, computes a new start position, and opens a new receiver with the same receiver name (sdk/eventhubs/azure-messaging-eventhubs/src/partition_client.cpp:230-262). PartitionClient::ReceiveEvents holds a per call rebuild counter, and a received message resets that counter (partition_client.cpp:298 and partition_client.cpp:309). The same method stores a pending error when the rebuild budget ends and the call already holds events (partition_client.cpp:326-336). The next call recovers from the pending error before it reads a message (partition_client.cpp:373-378). ProducerClient::EnsureSenderOrInvalidate discards the sender, the session, and the connection when an attach fails (sdk/eventhubs/azure-messaging-eventhubs/src/producer_client.cpp:318-352), and ProducerClient::InvalidateSender does that teardown (producer_client.cpp:362-389).

The offline tests cover only the decision functions. sdk/eventhubs/azure-messaging-eventhubs/test/ut/reattach_policy_test.cpp tests ShouldRebuildReceiver, ShouldInvalidateSender, and ResumeStartPosition. No offline test drives a rebuild sequence, because a rebuild needs a server that detaches a link and then accepts a new attach.

The build configuration makes the gap larger. sdk/core/azure-core-amqp/CMakeLists.txt:36 forces USE_RUST_AMQP on, and only DISABLE_RUST_IN_BUILD turns it off (sdk/core/azure-core-amqp/CMakeLists.txt:38-41). No file under eng/ sets DISABLE_RUST_IN_BUILD, and no pipeline matrix uses the no-rust-amqp presets (CMakePresets.json:333). No pipeline therefore builds uAMQP. The mock server compiles only under ENABLE_UAMQP (mock_amqp_server.hpp:25), so a new mock server test runs in a local uAMQP build until a pipeline builds that transport.

Proposal

Give the mock server the behaviour that a reattach test needs.

  • Add a method that detaches a named link on demand, with an AMQP error condition that the caller supplies. A test then makes the server send amqp:link:detach-forced to the client.
  • Remove the link from m_sender or m_receiver when the server detaches it, so a new attach with the same name does not hit the duplicate name refusal in OnLinkAttached.
  • Keep the message loop alive while the server listens, or start a new loop thread when a link attaches after the loop stopped. The joinable condition at mock_amqp_server.hpp:155 needs a state flag instead, because a finished std::thread stays joinable.
  • Report the duplicate name failure the same way for both roles. A throw from the callback thread ends the test process, so the sender role must send a detach with EntityAlreadyExists like the receiver role does.
  • Add a method that detaches every link and keeps the connection open, so a test can drive the pending error path in PartitionClient::ReceiveEvents.
  • Give each service endpoint a child context, so a closed connection stops that endpoint and not the whole server.
  • Add a pipeline configuration that builds the uAMQP transport, so the new tests run in CI.

Behaviours that become testable

  • PartitionClient::RebuildReceiver opens a new receiver with the same receiver name after a forced detach.
  • The rebuilt receiver starts after the last offset that the client received, through _detail::ResumeStartPosition.
  • The rebuild counter in ReceiveEvents resets after a received message, so a long lived consumer keeps a full budget.
  • ReceiveEvents returns the events that it holds, and it stores the pending error when the rebuild budget ends.
  • The next call to ReceiveEvents recovers from the pending error before it reads a message.
  • ReceiveEvents throws when the rebuild budget ends and the call holds no event.
  • ProducerClient::Send rebuilds the sender after a forced detach and sends the batch.
  • EnsureSenderOrInvalidate discards the session and the connection after a failed attach.
Lingua principale
C++
Stelle
206
Fork
177
Merge medio
2g 10h
PR unite (30g)
34

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di Azure/azure-sdk-for-cpp

Tutte le issue di Azure/azure-sdk-for-cpp

Issue simili

Altre issue su C++

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.