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

Allow loading grpc/errors.rb before grpc.rb #19893

Merged
merged 1 commit into from
Aug 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions src/ruby/end2end/errors_load_before_grpc_lib.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env ruby

# Copyright 2018 gRPC authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

this_dir = File.expand_path(File.dirname(__FILE__))
grpc_lib_dir = File.join(File.dirname(this_dir), 'lib')
$LOAD_PATH.unshift(grpc_lib_dir) unless $LOAD_PATH.include?(grpc_lib_dir)

def main
fail('GRPC constant loaded before expected') if Object.const_defined?(:GRPC)
require 'grpc/errors'
fail('GRPC constant not loaded when expected') unless Object.const_defined?(:GRPC)
fail('GRPC BadStatus not loaded after required') unless GRPC.const_defined?(:BadStatus)
fail('GRPC library loaded before required') if GRPC::Core.const_defined?(:Channel)
require 'grpc'
fail('GRPC library not loaded after required') unless GRPC::Core.const_defined?(:Channel)
end

main
33 changes: 33 additions & 0 deletions src/ruby/end2end/logger_load_before_grpc_lib.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env ruby

# Copyright 2018 gRPC authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

this_dir = File.expand_path(File.dirname(__FILE__))
grpc_lib_dir = File.join(File.dirname(this_dir), 'lib')
$LOAD_PATH.unshift(grpc_lib_dir) unless $LOAD_PATH.include?(grpc_lib_dir)

def main
fail('GRPC constant loaded before expected') if Object.const_defined?(:GRPC)
require 'grpc/logconfig'
fail('GRPC constant not loaded when expected') unless Object.const_defined?(:GRPC)
fail('GRPC DefaultLogger not loaded after required') unless GRPC.const_defined?(:DefaultLogger)
fail('GRPC logger not included after required') unless GRPC.methods.include?(:logger)
fail('GRPC Core loaded before required') if GRPC.const_defined?(:Core)
require 'grpc'
fail('GRPC Core not loaded after required') unless GRPC.const_defined?(:Core)
fail('GRPC library not loaded after required') unless GRPC::Core.const_defined?(:Channel)
end

main
32 changes: 32 additions & 0 deletions src/ruby/end2end/status_codes_load_before_grpc_lib.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env ruby

# Copyright 2018 gRPC authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

this_dir = File.expand_path(File.dirname(__FILE__))
grpc_lib_dir = File.join(File.dirname(this_dir), 'lib')
$LOAD_PATH.unshift(grpc_lib_dir) unless $LOAD_PATH.include?(grpc_lib_dir)

def main
fail('GRPC constant loaded before expected') if Object.const_defined?(:GRPC)
require 'grpc/core/status_codes'
fail('GRPC constant not loaded when expected') unless Object.const_defined?(:GRPC)
fail('GRPC Core not loaded after required') unless GRPC.const_defined?(:Core)
fail('GRPC StatusCodes not loaded after required') unless GRPC::Core.const_defined?(:StatusCodes)
fail('GRPC library loaded before required') if GRPC::Core.const_defined?(:Channel)
require 'grpc'
fail('GRPC library not loaded after required') unless GRPC::Core.const_defined?(:Channel)
end

main
40 changes: 0 additions & 40 deletions src/ruby/ext/grpc/rb_grpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,45 +155,6 @@ gpr_timespec grpc_rb_time_timeval(VALUE time, int interval) {
return t;
}

static void Init_grpc_status_codes() {
/* Constants representing the status codes or grpc_status_code in status.h */
VALUE grpc_rb_mStatusCodes =
rb_define_module_under(grpc_rb_mGrpcCore, "StatusCodes");
rb_define_const(grpc_rb_mStatusCodes, "OK", INT2NUM(GRPC_STATUS_OK));
rb_define_const(grpc_rb_mStatusCodes, "CANCELLED",
INT2NUM(GRPC_STATUS_CANCELLED));
rb_define_const(grpc_rb_mStatusCodes, "UNKNOWN",
INT2NUM(GRPC_STATUS_UNKNOWN));
rb_define_const(grpc_rb_mStatusCodes, "INVALID_ARGUMENT",
INT2NUM(GRPC_STATUS_INVALID_ARGUMENT));
rb_define_const(grpc_rb_mStatusCodes, "DEADLINE_EXCEEDED",
INT2NUM(GRPC_STATUS_DEADLINE_EXCEEDED));
rb_define_const(grpc_rb_mStatusCodes, "NOT_FOUND",
INT2NUM(GRPC_STATUS_NOT_FOUND));
rb_define_const(grpc_rb_mStatusCodes, "ALREADY_EXISTS",
INT2NUM(GRPC_STATUS_ALREADY_EXISTS));
rb_define_const(grpc_rb_mStatusCodes, "PERMISSION_DENIED",
INT2NUM(GRPC_STATUS_PERMISSION_DENIED));
rb_define_const(grpc_rb_mStatusCodes, "UNAUTHENTICATED",
INT2NUM(GRPC_STATUS_UNAUTHENTICATED));
rb_define_const(grpc_rb_mStatusCodes, "RESOURCE_EXHAUSTED",
INT2NUM(GRPC_STATUS_RESOURCE_EXHAUSTED));
rb_define_const(grpc_rb_mStatusCodes, "FAILED_PRECONDITION",
INT2NUM(GRPC_STATUS_FAILED_PRECONDITION));
rb_define_const(grpc_rb_mStatusCodes, "ABORTED",
INT2NUM(GRPC_STATUS_ABORTED));
rb_define_const(grpc_rb_mStatusCodes, "OUT_OF_RANGE",
INT2NUM(GRPC_STATUS_OUT_OF_RANGE));
rb_define_const(grpc_rb_mStatusCodes, "UNIMPLEMENTED",
INT2NUM(GRPC_STATUS_UNIMPLEMENTED));
rb_define_const(grpc_rb_mStatusCodes, "INTERNAL",
INT2NUM(GRPC_STATUS_INTERNAL));
rb_define_const(grpc_rb_mStatusCodes, "UNAVAILABLE",
INT2NUM(GRPC_STATUS_UNAVAILABLE));
rb_define_const(grpc_rb_mStatusCodes, "DATA_LOSS",
INT2NUM(GRPC_STATUS_DATA_LOSS));
}

/* id_at is the constructor method of the ruby standard Time class. */
static ID id_at;

Expand Down Expand Up @@ -363,7 +324,6 @@ void Init_grpc_c() {
Init_grpc_channel_credentials();
Init_grpc_server();
Init_grpc_server_credentials();
Init_grpc_status_codes();
Init_grpc_time_consts();
Init_grpc_compression_options();
}
1 change: 1 addition & 0 deletions src/ruby/lib/grpc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
require_relative 'grpc/logconfig'
require_relative 'grpc/notifier'
require_relative 'grpc/version'
require_relative 'grpc/core/status_codes'
require_relative 'grpc/core/time_consts'
require_relative 'grpc/generic/active_call'
require_relative 'grpc/generic/client_stub'
Expand Down
135 changes: 135 additions & 0 deletions src/ruby/lib/grpc/core/status_codes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
# Copyright 2015 gRPC authors.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Now that I've fixed the copyright failure, should these new files all use 2019?

#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# GRPC contains the General RPC module.
module GRPC
module Core
# StatusCodes defines the canonical error codes used by gRPC for the RPC
# API.
module StatusCodes
# OK is returned on success.
OK = 0

# Canceled indicates the operation was canceled (typically by the caller).
CANCELLED = 1

# Unknown error. An example of where this error may be returned is if a
# Status value received from another address space belongs to an
# error-space that is not known in this address space. Also errors raised
# by APIs that do not return enough error information may be converted to
# this error.
UNKNOWN = 2

# InvalidArgument indicates client specified an invalid argument. Note
# that this differs from FailedPrecondition. It indicates arguments that
# are problematic regardless of the state of the system (e.g., a malformed
# file name).
INVALID_ARGUMENT = 3

# DeadlineExceeded means operation expired before completion. For
# operations that change the state of the system, this error may be
# returned even if the operation has completed successfully. For example,
# a successful response from a server could have been delayed long enough
# for the deadline to expire.
DEADLINE_EXCEEDED = 4

# NotFound means some requested entity (e.g., file or directory) was not
# found.
NOT_FOUND = 5

# AlreadyExists means an attempt to create an entity failed because one
# already exists.
ALREADY_EXISTS = 6

# PermissionDenied indicates the caller does not have permission to
# execute the specified operation. It must not be used for rejections
# caused by exhausting some resource (use ResourceExhausted instead for
# those errors). It must not be used if the caller cannot be identified
# (use Unauthenticated instead for those errors).
PERMISSION_DENIED = 7

# ResourceExhausted indicates some resource has been exhausted, perhaps a
# per-user quota, or perhaps the entire file system is out of space.
RESOURCE_EXHAUSTED = 8

# FailedPrecondition indicates operation was rejected because the system
# is not in a state required for the operation's execution. For example,
# directory to be deleted may be non-empty, an rmdir operation is applied
# to a non-directory, etc.
#
# A litmus test that may help a service implementor in deciding between
# FailedPrecondition, Aborted, and Unavailable:
# (a) Use Unavailable if the client can retry just the failing call.
# (b) Use Aborted if the client should retry at a higher-level (e.g.,
# restarting a read-modify-write sequence).
# (c) Use FailedPrecondition if the client should not retry until the
# system state has been explicitly fixed. E.g., if an "rmdir" fails
# because the directory is non-empty, FailedPrecondition should be
# returned since the client should not retry unless they have first
# fixed up the directory by deleting files from it.
# (d) Use FailedPrecondition if the client performs conditional REST
# Get/Update/Delete on a resource and the resource on the server does
# not match the condition. E.g., conflicting read-modify-write on the
# same resource.
FAILED_PRECONDITION = 9

# Aborted indicates the operation was aborted, typically due to a
# concurrency issue like sequencer check failures, transaction aborts,
# etc.
#
# See litmus test above for deciding between FailedPrecondition, Aborted,
# and Unavailable.
ABORTED = 10

# OutOfRange means operation was attempted past the valid range. E.g.,
# seeking or reading past end of file.
#
# Unlike InvalidArgument, this error indicates a problem that may be fixed
# if the system state changes. For example, a 32-bit file system will
# generate InvalidArgument if asked to read at an offset that is not in
# the range [0,2^32-1], but it will generate OutOfRange if asked to read
# from an offset past the current file size.
#
# There is a fair bit of overlap between FailedPrecondition and
# OutOfRange. We recommend using OutOfRange (the more specific error) when
# it applies so that callers who are iterating through a space can easily
# look for an OutOfRange error to detect when they are done.
OUT_OF_RANGE = 11

# Unimplemented indicates operation is not implemented or not
# supported/enabled in this service.
UNIMPLEMENTED = 12

# Internal errors. Means some invariants expected by underlying system has
# been broken. If you see one of these errors, something is very broken.
INTERNAL = 13

# Unavailable indicates the service is currently unavailable. This is a
# most likely a transient condition and may be corrected by retrying with
# a backoff. Note that it is not always safe to retry non-idempotent
# operations.
#
# See litmus test above for deciding between FailedPrecondition, Aborted,
# and Unavailable.
UNAVAILABLE = 14

# DataLoss indicates unrecoverable data loss or corruption.
DATA_LOSS = 15

# Unauthenticated indicates the request does not have valid authentication
# credentials for the operation.
UNAUTHENTICATED = 16
end
end
end
2 changes: 1 addition & 1 deletion src/ruby/lib/grpc/errors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

require_relative './grpc'
require_relative './core/status_codes'

# GRPC contains the General RPC module.
module GRPC
Expand Down
3 changes: 3 additions & 0 deletions tools/run_tests/helper_scripts/run_ruby_end2end_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,7 @@ time ruby src/ruby/end2end/client_memory_usage_driver.rb || EXIT_CODE=1
time ruby src/ruby/end2end/package_with_underscore_checker.rb || EXIT_CODE=1
time ruby src/ruby/end2end/graceful_sig_handling_driver.rb || EXIT_CODE=1
time ruby src/ruby/end2end/graceful_sig_stop_driver.rb || EXIT_CODE=1
time ruby src/ruby/end2end/errors_load_before_grpc_lib.rb || EXIT_CODE=1
time ruby src/ruby/end2end/logger_load_before_grpc_lib.rb || EXIT_CODE=1
time ruby src/ruby/end2end/status_codes_load_before_grpc_lib.rb || EXIT_CODE=1
exit $EXIT_CODE