-
Notifications
You must be signed in to change notification settings - Fork 145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Calling Channel() on an empty connection panics #148
Comments
Please feel free to submit a pull request to address this issue. |
The root cause is our interpretation of "closed" in I don't think it's worth it changing the meaning of this field in all the codebase. |
I'd be happy to attempt a PR, if I can get some help figuring out the right place to check for this is (and what to check). One place would be around https://github.com/rabbitmq/amqp091-go/blob/v1.5.0/connection.go#L686, where we could notice that allocator is nil, and return an error. I was kind of hoping there'd be something more direct, but @Zerpet's comment makes me wonder. Is @Zerpet - you might be interested in why I'm doing this. I'm trying to test some behavior when an application receives an invalid (eg. closed) connection, but during my tests I don't currently have an available MQ instance to test on. So that |
Hey, I came back from holidays today and wanted to acknowledge your last message. Bear with me while I get back to speed. The topic on how to mock/fake a connection has come up a few times, and there was a concrete way, despite the lack of interfaces in this library. |
@jrubinator this comment streadway/amqp#164 (comment) from the original author of this library summarises how to unit test parts of this library. In your concrete case, you may need a connection factory, that returns an interface that you can mock. With regards to the panic, I'd like to keep this behaviour, as it is a mistake to use a zero-value |
Thanks! Re. the mocking, I'm not sure that solves my problem. I'll try not to get too into the weeds, here's a shot: We have a library that wraps
and we expect to have other developers call eg. I don't think it's the end of the world if we can't; just sharing my use-case. Let me know if you want any more details. And Re. the panicking: thanks for the consideration! Happy new year! |
Thanks for the context. I think you may need to abstract even further the AMQP primitives to accomplish what you described. I'm guessing that Re. the panic, I appreciate that panicking is not nice, however, I'm unsure that checking for nil allocator and returning an error will resolve your issue. We would have to return a specific error like Edit: Happy new year! ⭐ |
Precisely! Yeah, I think what you describe is indeed what we'd have to do. (They can also call non-Publish methods, which is why I was hoping for something magical here :))
I was actually looking to test on a subset of "closed" connections - just those that have never been open, so maybe a new error |
I agree with @Zerpet. Thanks for all of the interesting discussion. |
Calling Channel() on an uninitialized connection panics, rather than return an error.
Code:
Expected Behavior: prints out an error
Actual Behavior: panics
See https://go.dev/play/p/sseC5Beiapd
The text was updated successfully, but these errors were encountered: