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

Testkit to protobuf #1078

Merged
merged 11 commits into from Dec 5, 2018
Merged

Testkit to protobuf #1078

merged 11 commits into from Dec 5, 2018

Conversation

dvush
Copy link
Contributor

@dvush dvush commented Dec 4, 2018

Overview


Definition of Done

  • There are no TODOs left in the merged code
  • Change is covered by automated tests
  • Benchmark results are attached (if applicable)
  • The coding guidelines are followed
  • Public API has proper documentation
  • Changelog is updated if needed (in case of notable or breaking changes)
  • The continuous integration build passes

@codecov
Copy link

codecov bot commented Dec 5, 2018

Codecov Report

Merging #1078 into master will increase coverage by 0.01%.
The diff coverage is 88.88%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1078      +/-   ##
==========================================
+ Coverage   92.91%   92.93%   +0.01%     
==========================================
  Files         162      162              
  Lines       24242    24259      +17     
==========================================
+ Hits        22525    22544      +19     
+ Misses       1717     1715       -2
Impacted Files Coverage Δ
testkit/tests/counter/main.rs 93.63% <ø> (ø) ⬆️
testkit/tests/service_hooks/main.rs 95.23% <ø> (-0.42%) ⬇️
testkit/tests/inflating_currency/main.rs 99% <ø> (ø) ⬆️
testkit/src/lib.rs 95.42% <ø> (ø) ⬆️
testkit/tests/service_hooks/hooks.rs 100% <100%> (+5.26%) ⬆️
testkit/src/server.rs 87.96% <85.71%> (-0.19%) ⬇️
...sts/inflating_currency/inflating_cryptocurrency.rs 96.36% <87.09%> (-3.64%) ⬇️
testkit/tests/counter/counter.rs 98.8% <90.9%> (-1.2%) ⬇️
exonum/src/encoding/fields.rs 96.21% <0%> (+1.8%) ⬆️
... and 1 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e804b1b...7d42fcc. Read the comment docs.

&["examples/timestamping/proto"],
"timestamping_example_protobuf_mod.rs",
);
}
Copy link
Contributor

@aleksuss aleksuss Dec 5, 2018

Choose a reason for hiding this comment

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

What do you think about to change this repeated function calls for loop ?
For something like this

extern crate exonum_build;

use exonum_build::protobuf_generate;

fn main() {
    let exonum_protos = exonum_build::get_exonum_protobuf_files_path();
    let proto_data = [
        ("src/proto", vec!["src/proto"], "testkit_protobuf_mod.rs"),
        (
            "tests/inflating_currency/proto",
            vec!["tests/inflating_currency/proto", &exonum_protos],
            "currency_example_protobuf_mod.rs",
        ),
        (
            "tests/counter/proto",
            vec!["tests/counter/proto"],
            "counter_example_protobuf_mod.rs",
        ),
        (
            "tests/service_hooks/proto",
            vec!["tests/service_hooks/proto"],
            "hooks_example_protobuf_mod.rs",
        ),
        (
            "examples/timestamping/proto",
            vec!["examples/timestamping/proto"],
            "timestamping_example_protobuf_mod.rs",
        ),
    ];

    for (proto_path, includes, mod_file_name) in proto_data.iter() {
        protobuf_generate(proto_path, includes, mod_file_name);
    }
}

Copy link
Contributor

@aleksuss aleksuss Dec 5, 2018

Choose a reason for hiding this comment

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

Or even to create some structure in exonum_build crate for holding this data:

struct ProtoData {
    proto_path: String,
    includes: Vec<String>,
    mod_file_name: String
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think they are equivalent because there are no reduction in the code size.
To me current version looks more simple.

Copy link
Contributor

Choose a reason for hiding this comment

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

Really ? What about DRY ?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd support @dvush in that repeated function calls and repeated tuples/structures with a loop (or map) have the same readability. We have to repeat either function calls or struct/tuple constructors so it does not make any difference here, so I'm personally fine with function calls. Verbosity here comes from essential complexity of having 4 sets of 3 distinct paths that are not going anywhere.

There may be other considerations for choosing structs (and not tuples) because with something like this

Proto {
    proto_dir: "tests/service_hooks/proto",
    include_dirs: vec!["tests/service_hooks/proto"],
    rust_module: "hooks_example_protobuf_mod.rs",
}

it's easier to see what path stands for what, when compared to

(
    "tests/service_hooks/proto",
    vec!["tests/service_hooks/proto"],
    "hooks_example_protobuf_mod.rs",
)

Such 'named arguments' may actually improve readability.

ilammy
ilammy previously approved these changes Dec 5, 2018
Copy link
Contributor

@ilammy ilammy left a comment

Choose a reason for hiding this comment

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

👍

examples/cryptocurrency-advanced/backend/build.rs Outdated Show resolved Hide resolved

// For protobuf generated files.
#![allow(bare_trait_objects)]
#![allow(renamed_and_removed_lints)]
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it possible to teach rust-protobuf print this on its own? I'm not a fan of boilerplate that we have to keep forever in out files because someone else does something stupid. rust-protobuf seems to output quite a few clippy annotations, why don't we ask them nicely to add some more?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately no, it is known issue. Maybe it is even fixed, but not released yet.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think that we can patch generated protobuf file as workaround and later we should push fixes to the upstream protobuf repo.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why not just use current workaround without patching generated files? It seems simpler.

Unfortunately we cannot add this annotations to file which we import! for the same reason this workaround with import!ing piece of the mod file exists.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we should waste our limited resources, so current solution is preferable.

Copy link
Contributor

@ilammy ilammy Dec 5, 2018

Choose a reason for hiding this comment

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

This (PR) seems to be the tracking issue for this in rust-protobuf. It seems to be blocked by clippy's interface insanity instability w.r.t. stable vs. nighty and scoped vs. legacy attributes.

ilammy
ilammy previously approved these changes Dec 5, 2018
aleksuss
aleksuss previously approved these changes Dec 5, 2018
Copy link
Contributor

@aleksuss aleksuss left a comment

Choose a reason for hiding this comment

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

LGTM

exonum_build/src/lib.rs Outdated Show resolved Hide resolved

//! Module of the rust-protobuf generated files.

// For protobuf generated files.
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we add a few words about what it does for protobuf generated files? The meaning of this sentence is a bit unclear to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is comment attributed to next two lines - which are attributes that allow some bad style in code generated files.

I think since it is inner doc it is informative enough.

ilammy
ilammy previously approved these changes Dec 5, 2018
@dvush dvush dismissed stale reviews from ilammy and aleksuss via 7d42fcc December 5, 2018 13:25
@aleksuss aleksuss merged commit 5c82a19 into exonum:master Dec 5, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants