Skip to content
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

transports/tcp: Unit test tokio feature #1820

Closed
mxinden opened this issue Nov 2, 2020 · 3 comments · Fixed by #1887
Closed

transports/tcp: Unit test tokio feature #1820

mxinden opened this issue Nov 2, 2020 · 3 comments · Fixed by #1887
Labels
difficulty:easy getting-started Issues that can be tackled if you don't know the internals of libp2p very well help wanted

Comments

@mxinden
Copy link
Member

mxinden commented Nov 2, 2020

As of today libp2p-tcp is only tested with the async-std feature. Make the unit tests test both the async-std and the tokio feature. Otherwise things like tokio-rs/tokio#3001 go unnoticed without testing the chat-tokioexample when upgrading (e.g. #1796).

@mxinden mxinden added difficulty:easy help wanted getting-started Issues that can be tackled if you don't know the internals of libp2p very well labels Nov 2, 2020
@ericjmiller
Copy link

ericjmiller commented Nov 11, 2020

Is there a simple way to make TokioTcpConfig and TcpConfig structs swap based on feature?

I was thinking of doing this:

    fn config() -> Result<Transport, io::Error> {
        if cfg!(feature = "tokio") {
            Ok(TokioTcpConfig::new())
        } else if cfg!(feature = "async-std") {
            Ok(TcpConfig::new())
        } else {
            io::Error("No Feature set.")
        }
    }

But returns:
help: specify the associated types: 'Transport<Output = Type, Error = Type, Listener = Type, ListenerUpgrade = Type, Dial = Type>'

I'm hoping the return object can be used in all tests. Then you wouldn't even really need to specify the feature for the unit tests. Thoughts?

@mxinden
Copy link
Member Author

mxinden commented Nov 17, 2020

@ericjmiller first of all, thanks for looking into this.

Cargo features have to be designed in an additive fashion. Say both the Tokio and the Async-std feature are enabled: In your example above, which transport should be returned?

I would suggest a similar approach to the one we follow in our mdns tests. Here we use a macro to template the unit tests, invoking that macro with the Tokio mdns service when the tokio feature is enabled and invoking the macro with the async std mdns service when the async-std feature is enabled. With both enabled, the macro is invoked twice.

What do you think @ericjmiller?

@ericjmiller
Copy link

Cargo features have to be designed in an additive fashion. Say both the Tokio and the Async-std feature are enabled: In your example above, which transport should be returned?

Ah, okay. Thanks.

regarding the mdns tests - that strategy makes sense to me. I'll shoot for that implementation. Stay tuned ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
difficulty:easy getting-started Issues that can be tackled if you don't know the internals of libp2p very well help wanted
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants