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

[Windows] Fix thrift proxy tests #13220

Merged
merged 24 commits into from
Nov 28, 2020
Merged
Show file tree
Hide file tree
Changes from 21 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
2 changes: 0 additions & 2 deletions test/extensions/filters/network/thrift_proxy/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,6 @@ envoy_extension_cc_test(
"//test/extensions/filters/network/thrift_proxy/driver:generate_fixture",
],
extension_name = "envoy.filters.network.thrift_proxy",
tags = ["fails_on_windows"],
deps = [
":integration_lib",
":utility_lib",
Expand All @@ -350,7 +349,6 @@ envoy_extension_cc_test(
"//test/extensions/filters/network/thrift_proxy/driver:generate_fixture",
],
extension_name = "envoy.filters.network.thrift_proxy",
tags = ["fails_on_windows"],
deps = [
":integration_lib",
":utility_lib",
Expand Down
3 changes: 3 additions & 0 deletions test/extensions/filters/network/thrift_proxy/driver/BUILD
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
load("@rules_python//python:defs.bzl", "py_binary")
load("//bazel:envoy_build_system.bzl", "envoy_package")
load("@thrift_pip3//:requirements.bzl", "requirement")

licenses(["notice"]) # Apache 2

Expand All @@ -23,6 +24,7 @@ py_binary(
"//test/extensions/filters/network/thrift_proxy/driver/finagle:finagle_lib",
"//test/extensions/filters/network/thrift_proxy/driver/generated/example:example_lib",
"@com_github_twitter_common_rpc//:twitter_common_rpc",
requirement("six"),
],
)

Expand All @@ -35,5 +37,6 @@ py_binary(
"//test/extensions/filters/network/thrift_proxy/driver/finagle:finagle_lib",
"//test/extensions/filters/network/thrift_proxy/driver/generated/example:example_lib",
"@com_github_twitter_common_rpc//:twitter_common_rpc",
requirement("six"),
],
)
5 changes: 5 additions & 0 deletions test/extensions/filters/network/thrift_proxy/driver/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
from fbthrift import THeaderTransport
from twitter.common.rpc.finagle.protocol import TFinagleProtocol

# On Windows we run this test on Python3
if sys.version_info[0] != 2:
sys.stdin.reconfigure(encoding='utf-8')
sys.stdout.reconfigure(encoding='utf-8')


class TRecordingTransport(TTransport.TTransportBase):

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,11 @@
set -e

function usage() {
echo "Usage: $0 <mode> <transport> <protocol> -s [multiplex-service] -H [headers] method [param...]"
echo "Usage: $0 <mode> <transport> <protocol> -s [multiplex-service] -H [headers] -T [TempPath] method [param...]"
echo "where mode is success, exception, or idl-exception"
exit 1
}

FIXTURE_DIR="${TEST_TMPDIR}"
mkdir -p "${FIXTURE_DIR}"

DRIVER_DIR="${TEST_SRCDIR}/envoy/test/extensions/filters/network/thrift_proxy/driver"

if [[ -z "${TEST_UDSDIR}" ]]; then
TEST_UDSDIR=$(mktemp -d /tmp/envoy_test_thrift.XXXXXX)
fi

MODE="$1"
TRANSPORT="$2"
PROTOCOL="$3"
Expand All @@ -35,15 +26,18 @@ fi

MULTIPLEX=
HEADERS=
while getopts ":s:H:" opt; do
TEST_TMPDIR=
while getopts ":s:H:T:" opt; do
case ${opt} in
s)
MULTIPLEX=$OPTARG
;;
H)
HEADERS=$OPTARG
;;

T)
TEST_TMPDIR=$OPTARG
;;
\?)
echo "Invalid Option: -$OPTARG" >&2
exit 1
Expand All @@ -62,11 +56,33 @@ if [[ "${METHOD}" == "" ]]; then
fi
shift

SOCKET="${TEST_UDSDIR}/fixture.sock"
rm -f "${SOCKET}"
FIXTURE_DIR="${TEST_TMPDIR}"
mkdir -p "${FIXTURE_DIR}"

DRIVER_DIR="${TEST_SRCDIR}/envoy/test/extensions/filters/network/thrift_proxy/driver"

# On UNIX python supports AF_UNIX socket which are more reliable and efficient for communication
# between the client and the server, so we use it. On Windows, we find a random unused port
# on and let the communication happen via TCP.
SOCKET=""
if [[ "$OSTYPE" == "msys" ]]; then
while
port=$(shuf -n 1 -i 49152-65535)
netstat -atn | grep -q "$port" >> /dev/null
do
continue
done
SOCKET="127.0.0.1:${port}"
else
if [[ -z "${TEST_UDSDIR}" ]]; then
TEST_UDSDIR=$(mktemp -d /tmp/envoy_test_thrift.XXXXXX)
fi
SOCKET="${TEST_UDSDIR}/fixture.sock"
rm -f "${SOCKET}"
fi

echo "Using address ${SOCKET}"
SERVICE_FLAGS=("--addr" "${SOCKET}"
"--unix"
"--response" "${MODE}"
"--transport" "${TRANSPORT}"
"--protocol" "${PROTOCOL}")
Expand All @@ -83,26 +99,41 @@ else
fi

# start server
"${DRIVER_DIR}/server" "${SERVICE_FLAGS[@]}" &
SERVER_PID="$!"
if [[ "$OSTYPE" == "msys" ]]; then
echo "${SERVICE_FLAGS[@]}"
"${DRIVER_DIR}/server.exe" "${SERVICE_FLAGS[@]}" &
SERVER_PID="$!"
else
SERVICE_FLAGS+=("--unix")
"${DRIVER_DIR}/server" "${SERVICE_FLAGS[@]}" &
SERVER_PID="$!"
while [[ ! -a "${SOCKET}" ]]; do
sleep 0.1

if ! kill -0 "${SERVER_PID}"; then
echo "server failed to start"
exit 1
fi
done
fi

trap 'kill ${SERVER_PID}' EXIT;

while [[ ! -a "${SOCKET}" ]]; do
sleep 0.1

if ! kill -0 "${SERVER_PID}"; then
echo "server failed to start"
exit 1
fi
done
CLIENT_COMMAND=""
if [[ "$OSTYPE" == "msys" ]]; then
CLIENT_COMMAND="${DRIVER_DIR}/client.exe"
else
CLIENT_COMMAND="${DRIVER_DIR}/client"
fi

if [[ -n "$HEADERS" ]]; then
SERVICE_FLAGS+=("--headers")
SERVICE_FLAGS+=("$HEADERS")
if [[ -n "$HEADERS" ]]; then
SERVICE_FLAGS+=("--headers")
SERVICE_FLAGS+=("$HEADERS")
davinci26 marked this conversation as resolved.
Show resolved Hide resolved
fi

"${DRIVER_DIR}/client" "${SERVICE_FLAGS[@]}" \
davinci26 marked this conversation as resolved.
Show resolved Hide resolved
--request "${REQUEST_FILE}" \
--response "${RESPONSE_FILE}" \
"${METHOD}" "$@"
echo "${METHOD}" "$@"

$CLIENT_COMMAND "${SERVICE_FLAGS[@]}" \
--request "${REQUEST_FILE}" \
--response "${RESPONSE_FILE}" \
"${METHOD}" "$@"
davinci26 marked this conversation as resolved.
Show resolved Hide resolved
5 changes: 5 additions & 0 deletions test/extensions/filters/network/thrift_proxy/driver/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
from fbthrift import THeaderTransport
from finagle import TFinagleServerProcessor, TFinagleServerProtocol

# On Windows we run this test on Python3
if sys.version_info[0] != 2:
sys.stdin.reconfigure(encoding='utf-8')
sys.stdout.reconfigure(encoding='utf-8')


class SuccessHandler:

Expand Down
4 changes: 4 additions & 0 deletions test/extensions/filters/network/thrift_proxy/integration.cc
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ void BaseThriftIntegrationTest::preparePayloads(const PayloadOptions& options,
args.push_back(absl::StrJoin(headers, ","));
}

auto temp_path = TestEnvironment::temporaryDirectory();
args.push_back("-T");
args.push_back(temp_path);
davinci26 marked this conversation as resolved.
Show resolved Hide resolved

args.push_back(options.method_name_);
std::copy(options.method_args_.begin(), options.method_args_.end(), std::back_inserter(args));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,9 @@ INSTANTIATE_TEST_SUITE_P(FramedTwitter, ThriftTwitterConnManagerIntegrationTest,
// Because of the protocol upgrade requests and the difficulty of separating them, we test this
// protocol independently.
TEST_P(ThriftTwitterConnManagerIntegrationTest, Success) {
// This test relies on an old Apache Thrift Python package
// that is only available in Python2. Disabling the test on Windows.
#ifndef WIN32
initializeCall(DriverMode::Success);

uint32_t upgrade_request_size = request_bytes_.peekBEInt<uint32_t>() + 4;
Expand Down Expand Up @@ -457,6 +460,7 @@ TEST_P(ThriftTwitterConnManagerIntegrationTest, Success) {
EXPECT_EQ(2U, counter->value());
counter = test_server_->counter("thrift.thrift_stats.response_success");
EXPECT_EQ(2U, counter->value());
#endif
}

} // namespace ThriftProxy
Expand Down