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

Add http/ipc jsonrpc testing to harness #148

Merged
merged 3 commits into from
Oct 21, 2021

Conversation

njgheorghita
Copy link
Collaborator

@njgheorghita njgheorghita commented Oct 19, 2021

First steps towards a more robust test harness. For some reason, the overlay network pings seem to be broken. I dug into it a bit, but couldn't quite figure out the solution. It also seems like either #141 might help the situation, or at least help with debugging the situation. Tracking that in this issue #147

Fixes #4

@njgheorghita njgheorghita requested review from ogenev, jacobkaufmann and carver and removed request for ogenev and jacobkaufmann October 20, 2021 14:13
Comment on lines 128 to 129
let result = body_json.get("result").unwrap();
validate_endpoint_response(endpoint.method, result);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we add some check for an error member on the JSON-RPC response here? If there's an error, result may be empty, and the validation failure would not give us visibility into some possible error. Maybe we ought to change the signature of validate_endpoint_response to take the body of the response and check for an error, logging it and failing if one is present.

#[derive(Copy, Clone)]
pub struct JsonRpcEndpoint {
pub method: &'static str,
pub id: &'static u8,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is the id just a convenience field so that we do not need to generate a unique id for each JSON-RPC request that we test?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yup, exactly. Not strictly necessary to do here, but since params will also soon be added to the struct, seemed harmless to stick these in there as well

Comment on lines 115 to 118
let json_string = format!(
r#"{{"jsonrpc":"2.0","id":0,"method":"{}","params":[]}}"#,
endpoint.method
);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why not use endpoint.to_jsonrpc() here?

@jacobkaufmann
Copy link
Collaborator

Good start! I am concerned that this may get cumbersome as we continue to add endpoints. Is it possible to leverage the endpoint types that we have defined in trin-core to aid the validation/pattern matching?

@njgheorghita
Copy link
Collaborator Author

Is it possible to leverage the endpoint types that we have defined in trin-core to aid the validation/pattern matching?

@jacobkaufmann For sure, that's how this pr started out. But I punted it down the road to avoid dealing with wrapped types. One alternative option is to put all the testing properties on the original object definition, but I wanted to avoid bloating trin-core with mostly-unrelated test properties. But, yeah I strongly agree that some connection to the original endpoint types would be useful, especially so we don't forget to update the tests as we add new types. If you're ok with it, I'll track it in an issue for now. If you feel strongly that it should happen here, just lmk

@jacobkaufmann
Copy link
Collaborator

@njgheorghita Gotcha. Maybe we can do something similar to the validate attribute that we use in trin-core/jsonrpc. I'll do some exploring. I think it's okay to track separately for now. I do think we should add it before or along with the next set of endpoints that we introduce to the test harness, before the set of endpoints gets much larger.

@njgheorghita njgheorghita force-pushed the testharness branch 3 times, most recently from ef67a82 to b733133 Compare October 21, 2021 15:01
Copy link
Member

@ogenev ogenev left a comment

Choose a reason for hiding this comment

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

Looks good to me 👍

CONTRIBUTING.md Outdated
@@ -22,8 +22,10 @@ through github via pull requests.
* Mark unfinished pull requests with the "Work in Progress" label.
* Before submitting a pr for review, you should run the following commands
locally and make sure they are passing, otherwise CI will raise an error.
* `cargo fmt` and `cargo clippy` for linting checks
* `cargo test --workspace` to run all tests
* `cargo fmt -- --check` and `cargo clippy -- --deny warnings` for linting checks
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* `cargo fmt -- --check` and `cargo clippy -- --deny warnings` for linting checks
* `cargo fmt --all` and `cargo clippy --all -- --deny warnings` for linting checks

Ok(val) => val,
Err(msg) => {
warn!("Error parsing http request: {:?}", msg);
break;
Copy link
Member

Choose a reason for hiding this comment

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

Shall we write an error message to the stream instead of a break?

pub async fn test_jsonrpc_endpoints_over_ipc() {
for endpoint in JsonRpcEndpoint::all_endpoints() {
info!("Testing over IPC: {:?}", endpoint.method);
let mut stream = UnixStream::connect("/tmp/trin-jsonrpc.ipc").unwrap();
Copy link
Member

Choose a reason for hiding this comment

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

If we want to keep the direction to support cross-client testing in this crate, probably it is worth including the socket path as a parameter to CLI. I guess we can keep the default value as /tmp/trin-jsonrpc.ipc.

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.

Initial Integration tests for HTTP / IPC servers
3 participants