Skip to content

[Advanced]: Bug in tests/integration/topic_message_query_e2e_test.py #1796

Description

@exploreriii

🧠 Advanced Contributors

This issue is intended for contributors who are already very familiar with the
Hiero Python SDK codebase and its architectural patterns.

You should feel comfortable:

  • navigating multiple modules across src/
  • understanding and modifying core SDK abstractions
  • reasoning about API design and backwards compatibility
  • updating or extending tests, examples, and documentation as needed
  • making changes that may affect public-facing behavior

New developers should start with
Good First Issues or Intermediate Issues first.

🐞 Problem Description

TopicMessageQuery.subscribe() intermittently fails to deliver messages that have successfully reached consensus.
The submit transaction returns SUCCESS, but the subscription callback is never invoked, eventually causing a timeout.

This breaks multiple integration tests and suggests a race condition or incorrect timestamp / stream handling in the mirror subscription pipeline.

❌ Integration tests FAILED
→ Check the integration test logs above for details.
tests/integration/topic_message_query_e2e_test.py::test_topic_message_query_receives_messages FAILED [ 89%]
FAILED tests/integration/topic_message_query_e2e_test.py::test_topic_message_query_receives_messages - TimeoutError: TopicMessage was not received in time

https://github.com/hiero-ledger/hiero-sdk-python/actions/runs/21984284776/job/63514462825

This is happening frequently, with the same error, but not all the time

=================================== FAILURES ===================================
__________________ test_topic_message_query_receives_messages __________________

env = <tests.integration.utils.IntegrationTestEnv object at 0x7fc5013df8b0>

    @pytest.mark.integration
    def test_topic_message_query_receives_messages(env):
        """Test that topic message query receives a message."""
        topic_id = create_topic(env.client)
    
        time.sleep(3)
    
        messages: List[str] = []
    
        def get_message(m: TopicMessage):
            messages.append(m.contents.decode('utf-8'))
    
        def on_error_handler(e):
            raise RuntimeError(f"Subscription error: {e}")
    
        query = TopicMessageQuery(
            topic_id=topic_id,
            start_time=datetime.now(timezone.utc),
            limit=0
        )
    
        handle = query.subscribe(
            env.client,
            on_message=get_message,
            on_error=on_error_handler
        )
    
        time.sleep(3)
    
        message_receipt = (
            TopicMessageSubmitTransaction(
                topic_id=topic_id,
                message="Hello, Python SDK!"
            )
            .freeze_with(env.client)
            .execute(env.client)
        )
    
        assert (
            message_receipt.status == ResponseCode.SUCCESS
        ), f"Message submission failed with status: {ResponseCode(message_receipt.status).name}"
    
    
        start = datetime.now()
    
        while len(messages) == 0:
            if datetime.now() - start > timedelta(seconds=180):
>               raise TimeoutError("TopicMessage was not received in time")
E               TimeoutError: TopicMessage was not received in time

tests/integration/topic_message_query_e2e_test.py:104: TimeoutError
=========================== short test summary info ============================
FAILED tests/integration/topic_message_query_e2e_test.py::test_topic_message_query_receives_messages - TimeoutError: TopicMessage was not received in time
```yaml


Expected behavior

After:
1/creating a topic
2/opening a subscription
3/submitting a message
the SDK should deliver the message via on_message.

Actual behavior
1/topicMessageSubmitTransaction.execute() returns a receipt with ResponseCode.SUCCESS.
2/no error is raised from the subscription.
3/on_message is never called.
4/test times out after 180 seconds.

This makes the SDK unreliable for users

### 💡 Proposed / Expected Solution

Create a minimal script to reproduce the error, to confirm the cause - the problem is after consensus & on_error is not triggered. Ensure thorough logging to pin point the error


Fix the error, in the underlying source code and/or tests without introducing breaking changes
Only increase time out window if necessary or reasonable

### 🧠 Implementation & Design Notes

Add detailed implementation notes here.


### ✅ Acceptance Criteria

To merge this issue, the pull request must:

- [ ] Fully address the problem and design goals described above
- [ ] Maintain backwards compatibility unless explicitly approved otherwise
- [ ] Follow existing architectural and coding conventions
- [ ] Include comprehensive tests covering new and existing behavior
- [ ] Update relevant examples and documentation
- [ ] Pass all CI checks
- [ ] Include a valid changelog entry
- [ ] be a DCO and GPG key signed as `git commit -S -s -m "chore: my change"` with a GPG key set up


### 📚 Additional Context, Links, or Prior Art

Optional.

Metadata

Metadata

Assignees

Labels

scope: DLTinvolves engineering for distributed ledger technologyskill: advancedrequires knowledge of multiple areas in the codebase without defined steps to implement or examples

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions