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

Upgrade to hyper v0.13; use async/await #85

Merged
merged 3 commits into from
Dec 11, 2019
Merged

Upgrade to hyper v0.13; use async/await #85

merged 3 commits into from
Dec 11, 2019

Conversation

tony-iqlusion
Copy link
Collaborator

The crate itself builds with these changes, but the tests don't.

I'm not sure how to write tests for this (it's my first time using async/await in Rust 😅)

@tony-iqlusion
Copy link
Collaborator Author

I tried the obvious thing (and what I'd do in TypeScript): add async to my tests. Unfortunately...

error: async functions cannot be used for tests

@tarcieri tarcieri force-pushed the rpc/async branch 2 times, most recently from a590a21 to ef96305 Compare December 11, 2019 02:10
@tony-iqlusion
Copy link
Collaborator Author

tony-iqlusion commented Dec 11, 2019

Well, I got it to compile locally, but the (ignored) tests don't work:

---- rpc::net_info stdout ----
thread 'rpc::net_info' panicked at 'no current reactor', /Users/bascule/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-0.2.4/src/io/driver/mod.rs:243:21

I think I need to use #[tokio::test]

@liamsi
Copy link
Member

liamsi commented Dec 11, 2019

I briefly looked into #[tokio::test] but it seams that the whole body of the test would needs to be async (which isn't the case for the current integration tests).

Instead I got sth like this working locally:

mod rpc_asyc {
    use tendermint::rpc::Client;
    use tokio::runtime::Builder;
    use core::future::Future;

    fn block_on<F: Future>(future: F) -> F::Output {
        Builder::new()
            .basic_scheduler()
            .enable_all()
            .build()
            .unwrap()
            .block_on(future)
    }
    
    #[test]
    fn my_test() {
        let cli = block_on(Client::new(&"tcp://127.0.0.1:26657".parse().unwrap())).unwrap();
        let net_info = block_on(cli.net_info()).unwrap();
        assert!(net_info.listening);
    }
}

@liamsi
Copy link
Member

liamsi commented Dec 11, 2019

FWIW I created a PR against your branch with minimal changes here: #87 (feel free to ignore/close it if you settle with another approach)

tony-iqlusion and others added 2 commits December 11, 2019 05:40
 - delete futures crate from Cargo.toml
 - add tokio as a dev dependency
@tarcieri tarcieri changed the title [WIP] Upgrade to hyper v0.13; use async/await Upgrade to hyper v0.13; use async/await Dec 11, 2019
@tarcieri
Copy link
Contributor

Cool, I merged #87 into this branch. It appears to be working 🎉

I think it might be worth fixing the HTTP error handling too, which I'll take a quick stab at

Adds a bogus error code for low-level HTTP errors, and at least captures
the error message from the `http` crate or `hyper`.
@tony-iqlusion
Copy link
Collaborator Author

Added some basic non-panicking HTTP error handling in a50b503.

Unfortunately I don't have a local Tendermint to test against at the moment so I'm not sure it actually works. @liamsi were the tests passing locally for you?

After cosmoshub-3 launches I'll give it a try against that.

@liamsi
Copy link
Member

liamsi commented Dec 11, 2019

@liamsi were the tests passing locally for you?

Most of the integration tests pass two didn't (abci_info, genesis).

  • genesis fails with: called Result::unwrap() on an Err value: Error { code: ParseError, message: "Parse error. Invalid JSON", data: Some("invalid digit found in string at line 11 column 26") }
  • abci_info with: called Result::unwrap() on an Err value: Error { code: ParseError, message: "Parse error. Invalid JSON", data: Some("missing field last_block_height at line 9 column 5") }

@tony-iqlusion
Copy link
Collaborator Author

tony-iqlusion commented Dec 11, 2019

@liamsi aah cool, well I'm guessing those weren't regressions then, so at least we're no worse off.

Can you approve this PR if you think it looks good? (I may almost be ready to attempt YubiKey-backed key storage for GPG)

Copy link
Member

@liamsi liamsi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! 👍

@liamsi
Copy link
Member

liamsi commented Dec 11, 2019

Yes, I think it's OK to fix those regressions in another PR.

@liamsi liamsi merged commit 0869914 into master Dec 11, 2019
@liamsi liamsi mentioned this pull request Dec 11, 2019
@ebuchman ebuchman deleted the rpc/async branch December 11, 2019 21:45
@ebuchman ebuchman restored the rpc/async branch December 11, 2019 21:45
@xla xla deleted the rpc/async branch January 18, 2020 15:10
@liamsi liamsi mentioned this pull request Mar 6, 2020
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants