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

Added ruby wrapper for grpc_compression_options #7216

Merged
merged 6 commits into from
Jul 15, 2016

Conversation

apolcyn
Copy link
Contributor

@apolcyn apolcyn commented Jul 1, 2016

This adds a ruby class wraps a grpc_compression_options. The ruby wrapper has optional constructor args but is immutable.

Right now, it could be added to the ruby server_args or channel_args hashes with #merge, for example.

It's #to_hash and #to_channel_args_hash methods return compression-related key-values that can be passed to the core.

@googlebot
Copy link

We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for the commit author(s). If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google.

@apolcyn apolcyn force-pushed the add_ruby_compression_options_wrapper branch from 9666f93 to b95b428 Compare July 1, 2016 22:46
@googlebot
Copy link

CLAs look good, thanks!

@googlebot googlebot added cla: yes and removed cla: no labels Jul 1, 2016
@murgatroid99
Copy link
Member

Why are the internal C functions written as Ruby functions with VALUE inputs and outputs, instead of regular C functions that work with regular C types?

@apolcyn
Copy link
Contributor Author

apolcyn commented Jul 1, 2016

My main idea with that was just so that I could test them with rspec.

I defined all of the internal C functions as private methods on the ruby
class, expect for #to_hash. They get called in the rspec tests with the
#send(:private_method_name, args..)

Was also thinking it would make it easy to make them public though too in case we wanted to.

On Fri, Jul 1, 2016 at 3:49 PM, Michael Lumish notifications@github.com
wrote:

Why are the internal C functions written as Ruby functions with VALUE
inputs and outputs, instead of regular C functions that work with regular C
types?


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#7216 (comment), or mute
the thread
https://github.com/notifications/unsubscribe/AJH4LijHbzvlwkPBzveS-989HSaOuvivks5qRZl2gaJpZM4JDhWF
.

@murgatroid99
Copy link
Member

I think you should not have tests for private methods. They are, by definition, implementation details of the class, and they should not be required to be stable. The units that you test should be your public interface, and most of those functions appear to be true helper methods that wouldn't be useful to a Ruby user.

&grpc_rb_compression_options_data_type, wrapper);

/* Take both string and symbol parameters */
ruby_str = rb_funcall(new_level, rb_intern("to_s"), 0);
Copy link
Member

Choose a reason for hiding this comment

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

I think it would make sense for this function to accept only symbol parameters. We are dealing with a predefined set of values that are unlikely to change in the foreseeable future, and symbols work well in that case. Plus, if you do it that way, you can predefine the symbols and compare against them directly, instead of doing string comparisons.

@apolcyn apolcyn force-pushed the add_ruby_compression_options_wrapper branch from c7c4769 to ab9bdf5 Compare July 11, 2016 02:40
@apolcyn apolcyn force-pushed the add_ruby_compression_options_wrapper branch from ab9bdf5 to b72cc3d Compare July 11, 2016 03:19

/* Ruby symbols for the names of the different compression levels. */
rb_define_const(grpc_rb_cCompressionOptions, "COMPRESS_NONE_SYM",
ID2SYM(rb_intern("none")));
Copy link
Member

Choose a reason for hiding this comment

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

You shouldn't need constants that hold symbols. The symbol itself should be a suitable constant for referring to a level. And if you get rid of the constants, you can just store the ID directly, like in the channel code (https://github.com/grpc/grpc/blob/master/src/ruby/ext/grpc/rb_channel.c#L377).


rb_raise(rb_eArgError,
"Unrecognized compression level name."
"Valid compression level names are none, low, medium, and high.");
Copy link
Member

Choose a reason for hiding this comment

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

I think you still need a return statement here.

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 can add it still, but I saw this compile on OSX and linux.
I think it's building here, but certain interop tests that should be unaffected seem to be failing right now.

@murgatroid99
Copy link
Member

Actually, I noticed that you have disabled_algorithms and is_algorithm_enabled method. I think you can use those for the tests you have without exposing any of the bitset information at all.

@apolcyn
Copy link
Contributor Author

apolcyn commented Jul 12, 2016

The latest updates remove testing of non-API methods and shrink the API too. The tests still use compression algorithm names like gzip and deflate, but should no longer test for internal enum values.

@murgatroid99
Copy link
Member

LGTM

@apolcyn
Copy link
Contributor Author

apolcyn commented Jul 14, 2016

test this please

1 similar comment
@apolcyn
Copy link
Contributor Author

apolcyn commented Jul 15, 2016

test this please

@kpayson64 kpayson64 merged commit 7c55ab0 into grpc:master Jul 15, 2016
@lock lock bot locked as resolved and limited conversation to collaborators Dec 10, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants