Skip to content

Commit

Permalink
Bump grpc to 1.43 (#292)
Browse files Browse the repository at this point in the history
* Bump grpc to 1.45 (latest point release is 1.45.2)

I also attempted to get the tests running in the build. Hopefully this will work in this PR, and not have to wait until after merging

* Scope tests to their own dir for CI

* Codacy suggestions

* More codacy suggestions

* Standardize test names

* Also run the gateway tests during builds

* Another codacy suggestion

* Update README.md

* Standardize test output

* Switch to 1.43 so we can release it in order

* PR feedback

* Print test failures to stderr

* Try to disable globbing in the tests
  • Loading branch information
Abraham Heidebrecht authored May 11, 2022
1 parent 0201e0d commit 7204bf1
Show file tree
Hide file tree
Showing 8 changed files with 178 additions and 92 deletions.
14 changes: 13 additions & 1 deletion .github/workflows/master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,17 @@ jobs:
- name: Build
if: success()
env:
BUILD_VERSION: ${{ steps.sha_short.outputs.SHA_SHORT }}
VERSION: ${{ steps.sha_short.outputs.SHA_SHORT }}
run: make build

- name: Test
if: success()
env:
CONTAINER: docker.io/namely/protoc-all:${{ steps.sha_short.outputs.SHA_SHORT }}
run: make test

- name: Test Gateway
if: success()
env:
CONTAINER: docker.io/namely/gen-grpc-gateway:${{ steps.sha_short.outputs.SHA_SHORT }}
run: make test-gwy
14 changes: 13 additions & 1 deletion .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,17 @@ jobs:
- name: Build
if: success()
env:
BUILD_VERSION: ${{ steps.sha_short.outputs.SHA_SHORT }}
VERSION: ${{ steps.sha_short.outputs.SHA_SHORT }}
run: make build

- name: Test
if: success()
env:
CONTAINER: docker.io/namely/protoc-all:${{ steps.sha_short.outputs.SHA_SHORT }}
run: make test

- name: Test Gateway
if: success()
env:
CONTAINER: docker.io/namely/gen-grpc-gateway:${{ steps.sha_short.outputs.SHA_SHORT }}
run: make test-gwy
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ build:
test:
bash ./all/test.sh

.PHONY: test-gwy
test-gwy:
bash ./gwy/test.sh

# Not for manual invocation.
.PHONY: push
push: build
Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,7 @@ demonstrate that your new image can successfully build containers for each langu

#### gRPC Gateway test
```sh
cd gwy
./test.sh namely/gen-grpc-gateway:VVV
CONTAINER=namely/gen-grpc-gateway:VVV make test-gwy
```

### Release
Expand Down
168 changes: 103 additions & 65 deletions all/test.sh

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion gwy/templates/go.mod.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ require (
github.com/sirupsen/logrus v1.7.0
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.7.1
google.golang.org/grpc v1.42.0
google.golang.org/grpc v1.43.0
google.golang.org/protobuf v1.27.1
)
61 changes: 41 additions & 20 deletions gwy/test.sh
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
#!/bin/bash
set -e
set -x
#!/bin/bash -ex

if [[ $# -ne 1 ]]; then
echo "Usage: test.sh container"
exit 1
fi
CONTAINER=${CONTAINER}

if [ -z "${CONTAINER}" ]; then
echo "You must specify a build container with \${CONTAINER} to test (see my README.md)"
exit 1
fi

CONTAINER=$1
HEADERS_FILE="./.headers"
SOME_RESP_HEADER="SOME-RESPONSE-HEADER"

pushd "gwy"

# Test building the gateway.
docker run --rm -v=`pwd`:/defs $CONTAINER -f test/test.proto -i . -s Message
docker run --rm -v="$PWD":/defs "$CONTAINER" -f /defs/test/test.proto -i /defs -s Message

# And make sure that we can build the test gateway too.
docker build -t $CONTAINER-test-gateway gen/grpc-gateway/
Expand All @@ -32,44 +32,54 @@ status=`curl -i -s -o $HEADERS_FILE -w "%{http_code}" localhost:8080/api/message
# running. In the future, if this was a real backend we should get a 200. However,
# here we can use the 503 to indicate that the gateway tried to send the request
# downstream.
echo ""
if [ "$status" -ne "503" ]; then
kill $!
echo "Invalid status: '$status' with /api/messages http request"
echo >&2 "[Fail] - Received expected response from gateway when no backend service running"
echo >&2 "Invalid status: '$status' with /api/messages http request"
exit 1
fi

if ! grep -qi "$SOME_RESP_HEADER" "$HEADERS_FILE"; then
kill $!
echo "header $SOME_RESP_HEADER was not found in response"
echo >&2 "[Fail] - Received expected response from gateway when no backend service running"
echo >&2 "header $SOME_RESP_HEADER was not found in response"
rm $HEADERS_FILE
exit 1
fi
echo "[Pass] - Received expected response from gateway when no backend service running"
rm $HEADERS_FILE

# If we call an endpoint that does not exist (say just messages), we should
# get a 404, since there's no handler for that endpoint.
status=`curl -s -o /dev/null -w "%{http_code}" localhost:8080/messages`

echo ""
if [ "$status" -ne "404" ]; then
kill $!
echo "Invalid status: '$status' with /messages http request"
echo >&2 "[Fail] - Received expected response from gateway when grpc method does not exist"
echo >&2 "Invalid status: '$status' with /messages http request"
exit 1
fi
echo "[Pass] - Received expected response from gateway when grpc method does not exist"

# UnboundUnary should not work
# Unbound methods require the request payload as request body (curl --data 'payload')
status=`curl -s -o /dev/null -w "%{http_code}" --data '{}' localhost:8080/api/Messages.Message/UnboundUnary`

echo ""
if [ "$status" -ne "404" ]; then
kill $!
echo "Invalid status: '$status' with /api/Messages.Message/UnboundUnary http request"
echo >&2 "[Fail] - Received expected response from gateway when expected payload not passed in the http request body"
echo >&2 "Invalid status: '$status' with /api/Messages.Message/UnboundUnary http request"
exit 1
fi
echo "[Pass] - Received expected response from gateway when expected payload not passed in the http request body"

kill $!



# Test building the gateway with unbound methods.
docker run --rm -v=`pwd`:/defs $CONTAINER -f test/test.proto -i . -s Message --generate-unbound-methods
docker run --rm -v="$PWD":/defs "$CONTAINER" -f test/test.proto -i . -s Message --generate-unbound-methods

# And make sure that we can build the test gateway too.
docker build -t $CONTAINER-test-gateway gen/grpc-gateway/
Expand All @@ -88,37 +98,48 @@ status=`curl -i -s -o $HEADERS_FILE -w "%{http_code}" localhost:8080/api/message
# running. In the future, if this was a real backend we should get a 200. However,
# here we can use the 503 to indicate that the gateway tried to send the request
# downstream.
echo ""
if [ "$status" -ne "503" ]; then
kill $!
echo "Invalid status: '$status' with /api/messages http request"
echo >&2 "[Fail] - Received expected response from gateway when no backend service running, and unbound methods are generated"
echo >&2 "Invalid status: '$status' with /api/messages http request"
exit 1
fi
echo "[Pass] - Received expected response from gateway when no backend service running, and unbound methods are generated"

# UnboundUnary should work
# Unbound methods require the request payload as request body (curl --data 'payload')
status=`curl -i -s -o $HEADERS_FILE -w "%{http_code}" --data '{}' localhost:8080/api/Messages.Message/UnboundUnary`

echo ""
if [ "$status" -ne "503" ]; then
kill $!
echo "Invalid status: '$status' with /api/Messages.Message/UnboundUnary http request"
echo >&2 "[Fail] - Received expected response from gateway when no backend service running and calling an unbound method, and unbound methods are generated"
echo >&2 "Invalid status: '$status' with /api/Messages.Message/UnboundUnary http request"
exit 1
fi

if ! grep -qi "$SOME_RESP_HEADER" "$HEADERS_FILE"; then
kill $!
echo "header $SOME_RESP_HEADER was not found in response"
echo >&2 "[Fail] - Received expected response from gateway when no backend service running and calling an unbound method, and unbound methods are generated"
echo >&2 "header $SOME_RESP_HEADER was not found in response"
rm $HEADERS_FILE
exit 1
fi
rm $HEADERS_FILE
echo "[Pass] - Received expected response from gateway when no backend service running and calling an unbound method, and unbound methods are generated"

# If we call an endpoint that does not exist (say just messages), we should
# get a 404, since there's no handler for that endpoint.
status=`curl -s -o /dev/null -w "%{http_code}" localhost:8080/messages`

echo ""
if [ "$status" -ne "404" ]; then
kill $!
echo "Invalid status: '$status' with /messages http request"
echo >&2 "[Fail] - Received expected response from gateway when grpc method does not exist, and unbound methods are generated"
echo >&2 "Invalid status: '$status' with /messages http request"
exit 1
fi
echo "[Pass] - Received expected response from gateway when grpc method does not exist, and unbound methods are generated"

kill $!
4 changes: 2 additions & 2 deletions variables.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ CONTAINER=${DOCKER_REPO}${NAMESPACE}
LATEST=${1:false}

GO_VERSION=${GO_VERSION:-1.17}
GRPC_VERSION=${GRPC_VERSION:-1.42}
GRPC_JAVA_VERSION=${GRPC_JAVA_VERSION:-1.42}
GRPC_VERSION=${GRPC_VERSION:-1.43}
GRPC_JAVA_VERSION=${GRPC_JAVA_VERSION:-1.43}
GRPC_WEB_VERSION=${GRPC_WEB_VERSION:-1.3.0}
GRPC_GATEWAY_VERSION=${GRPC_GATEWAY_VERSION:-2.0.1}
UBER_PROTOTOOL_VERSION=${UBER_PROTOTOOL_VERSION:-1.3.0}
Expand Down

0 comments on commit 7204bf1

Please sign in to comment.