[example] Move unix abstract domain sockets example (#33220)

A different scheme was decided upon for adding feature examples. This
moves the old UDS example and deletes the CI job.
pull/33227/head
AJ Heller 2 years ago committed by GitHub
parent c684409921
commit d58af7397f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 129
      examples/cpp/features/run_tests.sh
  2. 0
      examples/cpp/unix_abstract_sockets/BUILD
  3. 13
      examples/cpp/unix_abstract_sockets/README.md
  4. 0
      examples/cpp/unix_abstract_sockets/client.cc
  5. 0
      examples/cpp/unix_abstract_sockets/server.cc
  6. 29
      tools/internal_ci/linux/grpc_feature_example_tests.cfg
  7. 20
      tools/internal_ci/linux/grpc_feature_example_tests_in_docker.sh
  8. 29
      tools/internal_ci/linux/pull_request/grpc_feature_example_tests.cfg

@ -1,129 +0,0 @@
#!/usr/bin/env bash
# Copyright 2021 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.
# Test structure borrowed with gratitude from
# https://github.com/grpc/grpc-go/tree/master/examples/features
set -eux
# execute in root dir
SCRIPTPATH="$(
cd -- "$(dirname "$0")" >/dev/null 2>&1
pwd -P
)"
cd ${SCRIPTPATH}/../../..
SERVER_PORT=50051
export TMPDIR=$(mktemp -d)
trap "rm -rf ${TMPDIR}" EXIT
clean() {
# loop a handful of times in case job shutdown is not immediate
for i in {1..5}; do
# kill all jobs
jobs -p | xargs kill &>/dev/null || true
# wait for all jobs to exit
sleep 0.3
if ! jobs | read; then
return
fi
done
echo "ERROR: clean failed to kill tests"
jobs
exit 1
}
fail() {
echo "$@" >&2
clean
exit 1
}
pass() {
echo "SUCCESS: $1"
}
wait_for_server() {
feature=$1
wait_command=${SERVER_WAIT_COMMAND[$feature]:-${SERVER_WAIT_COMMAND["default"]}}
echo "INFO: waiting for server to start"
declare -i i=0
while ! eval "$wait_command"; do
((++i < 10)) || fail "cannot determine if server started"
lsof -U
sleep 1
done
pass "server started"
}
FEATURES=(
"unix_abstract"
)
declare -A SERVER_WAIT_COMMAND=(
["unix_abstract"]="lsof -U | grep '@grpc@abstract'"
["default"]="lsof -i :$SERVER_PORT | grep $SERVER_PORT"
)
declare -A EXPECTED_SERVER_OUTPUT=(
["unix_abstract"]="Server listening on unix-abstract:grpc%00abstract ... Echoing: arst"
)
declare -A EXPECTED_CLIENT_OUTPUT=(
["unix_abstract"]="Sending 'arst' to unix-abstract:grpc%00abstract ... Received: arst"
)
for feature in ${FEATURES[@]}; do
echo "TESTING: $feature"
bazel build --define=use_strict_warning=true //examples/cpp/features/${feature}:all || fail "failed to build $feature"
SERVER_LOG="$(mktemp)"
./bazel-bin/examples/cpp/features/$feature/server &>$SERVER_LOG &
wait_for_server $feature
# TODO(hork): add a timeout to abort client?
CLIENT_LOG="$(mktemp)"
./bazel-bin/examples/cpp/features/$feature/client &>$CLIENT_LOG
if [ -n "${EXPECTED_SERVER_OUTPUT[$feature]}" ]; then
if ! grep -q "${EXPECTED_SERVER_OUTPUT[$feature]}" $SERVER_LOG; then
fail "server log missing output: ${EXPECTED_SERVER_OUTPUT[$feature]}
got server log:
$(cat $SERVER_LOG)
got client log:
$(cat $CLIENT_LOG)
"
else
pass "server log contains expected output: ${EXPECTED_SERVER_OUTPUT[$feature]}"
fi
fi
if [ -n "${EXPECTED_CLIENT_OUTPUT[$feature]}" ]; then
if ! grep -q "${EXPECTED_CLIENT_OUTPUT[$feature]}" $CLIENT_LOG; then
fail "client log missing output: ${EXPECTED_CLIENT_OUTPUT[$feature]}
got server log:
$(cat $SERVER_LOG)
got client log:
$(cat $CLIENT_LOG)
"
else
pass "client log contains expected output: ${EXPECTED_CLIENT_OUTPUT[$feature]}"
fi
fi
clean
done

@ -0,0 +1,13 @@
gRPC Unix Abstract Socket Example
================
This example shows how to use gRPC with Unix domain sockets in the abstract namespace.
gRPC uses the [`unix-abstract:abstract_path`](https://github.com/grpc/grpc/blob/c6844099218b147b0e374843e0a26745adc61ddb/doc/naming.md?plain=1#L44-L50) URI scheme to support this.
In this example, an socket with an embedded null character `grpc%00abstract` is created.
## Build and run the example
Run `bazel run :server` in one terminal, and `bazel run :client` in another.
The client and server will confirm that a message was sent and received on both ends. The server will continue running until it is shut down.
While the server is still running, you can confirm that a unix domain socket is in use by running `lsof -U | grep '@grpc@abstract'`.

@ -1,29 +0,0 @@
# Copyright 2021 The 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.
# Config file for the internal CI (in protobuf text format)
# Location of the continuous shell script in repository.
build_file: "grpc/tools/internal_ci/linux/grpc_bazel.sh"
timeout_mins: 30
env_vars {
key: "BAZEL_SCRIPT"
value: "tools/internal_ci/linux/grpc_feature_example_tests_in_docker.sh"
}
action {
define_artifacts {
regex: "**/*sponge_log.*"
regex: "github/grpc/reports/**"
}
}

@ -1,20 +0,0 @@
#!/bin/bash
# Copyright 2021 The 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.
set -ex
apt-get install -y lsof
./examples/cpp/features/run_tests.sh

@ -1,29 +0,0 @@
# Copyright 2019 The 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.
# Config file for the internal CI (in protobuf text format)
# Location of the continuous shell script in repository.
build_file: "grpc/tools/internal_ci/linux/grpc_bazel.sh"
timeout_mins: 30
env_vars {
key: "BAZEL_SCRIPT"
value: "tools/internal_ci/linux/grpc_feature_example_tests_in_docker.sh"
}
action {
define_artifacts {
regex: "**/*sponge_log.*"
regex: "github/grpc/reports/**"
}
}
Loading…
Cancel
Save