Skip to content

Commit

Permalink
fix: ensure the core.grpc is nil under vanilla OpenResty (apache#8007)
Browse files Browse the repository at this point in the history
  • Loading branch information
spacewander authored and Liu-Junlin committed Nov 4, 2022
1 parent 3672125 commit a3650d0
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
4 changes: 4 additions & 0 deletions apisix/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ local re_split = require("ngx.re").split
local str_byte = string.byte
local str_sub = string.sub
local tonumber = tonumber
local type = type
local pairs = pairs
local control_api_router

Expand Down Expand Up @@ -112,6 +113,9 @@ function _M.http_init_worker()
-- Because go's scheduler doesn't work after fork, we have to load the gRPC module
-- in each worker.
core.grpc = require("apisix.core.grpc")
if type(core.grpc) ~= "table" then
core.grpc = nil
end

local we = require("resty.worker.events")
local ok, err = we.configure({shm = "worker-events", interval = 0.1})
Expand Down
54 changes: 54 additions & 0 deletions t/core/grpc-openresty.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You 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.
#
use t::APISIX;

my $nginx_binary = $ENV{'TEST_NGINX_BINARY'} || 'nginx';
my $version = eval { `$nginx_binary -V 2>&1` };

if ($version =~ m/\/apisix-nginx-module/) {
plan(skip_all => "for vanilla OpenResty only");
} else {
plan('no_plan');
}

add_block_preprocessor(sub {
my ($block) = @_;

if (!$block->request) {
$block->set_value("request", "GET /t");
}

if ((!defined $block->error_log) && (!defined $block->no_error_log)) {
$block->set_value("no_error_log", "[error]");
}
});

run_tests;

__DATA__
=== TEST 1: ensure the core.grpc is nil under vanilla OpenResty
--- config
location /t {
content_by_lua_block {
local core = require "apisix.core"
local gcli = core.grpc
ngx.say(gcli)
}
}
--- response_body
nil

0 comments on commit a3650d0

Please sign in to comment.