Repository navigation
Expand file tree
/
Copy pathrun-e2e-tests.sh
More file actions
executable file
·146 lines (131 loc) · 4.27 KB
/
Copy pathrun-e2e-tests.sh
File metadata and controls
executable file
·146 lines (131 loc) · 4.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/bin/bash
# Copyright (c) 2022-2026 Super Durable, Inc.
#
# 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 -euo pipefail
coverage=false
if [[ "${1:-}" == "--coverage" ]]; then
coverage=true
shift
fi
if [[ "$#" -ne 0 ]]; then
echo "usage: $0 [--coverage]" >&2
exit 2
fi
export DEX_INTEG_ENGINE="${DEX_INTEG_ENGINE:-zd}"
if [[ "$DEX_INTEG_ENGINE" != zd ]]; then
echo "DEX_INTEG_ENGINE must be zd" >&2
exit 2
fi
available_port() {
python3 -c 'import socket; s=socket.socket(); s.bind(("127.0.0.1", 0)); print(s.getsockname()[1]); s.close()'
}
script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
repo_root=$(cd "$script_dir/.." && pwd)
if [[ -n "${DEX_SERVER_ZD_BINARY:-}" && "$DEX_SERVER_ZD_BINARY" == */* ]]; then
DEX_SERVER_ZD_BINARY="$(cd "$(dirname "$DEX_SERVER_ZD_BINARY")" && pwd)/$(basename "$DEX_SERVER_ZD_BINARY")"
fi
cd "$script_dir"
dex_port="${DEX_INTEG_DEX_PORT:-$(available_port)}"
web_port="${DEX_INTEG_WEB_PORT:-$(available_port)}"
dex_address="127.0.0.1:${dex_port}"
log_file="/tmp/test-go-sdk-phase5-e2e-services.log"
test_dir=$(mktemp -d)
dexcli_pid=""
cover_dir=""
coverpkg="./dex/..."
: >"$log_file"
cleanup() {
status=$?
if [[ -n "$dexcli_pid" ]] && kill -0 "$dexcli_pid" 2>/dev/null; then
kill -TERM "$dexcli_pid"
wait "$dexcli_pid" || true
fi
if [[ "$status" -ne 0 ]]; then
cat "$log_file" >&2
fi
rm -r "$test_dir"
if [[ -n "$cover_dir" ]]; then
rm -rf "$cover_dir"
fi
}
trap cleanup EXIT
run_go_test() {
if $coverage; then
go test \
-covermode=atomic \
-coverpkg="$coverpkg" \
"$@" \
-args \
-test.gocoverdir="$cover_dir"
else
go test "$@"
fi
}
if $coverage; then
rm -rf coverage
cover_dir=$(mktemp -d "$script_dir/coverage-raw.XXXXXX")
run_go_test -count=1 -race -v ./dex -run '^TestClient'
run_go_test -count=1 -race -v ./dex -run '^TestWorker'
fi
make -C ../cli build
dev_args=(
-bind-address 127.0.0.1
-dex-port "$dex_port"
-web-port "$web_port"
-open=false
-flow-rendering-dir "$test_dir/definitions"
)
if [[ -z "${DEX_SERVER_ZD_BINARY:-}" ]]; then
(cd "$repo_root" && cargo build --release --locked --manifest-path server-zd/Cargo.toml -p dexzd-server --bin dex-server-zd)
DEX_SERVER_ZD_BINARY="$repo_root/server-zd/target/release/dex-server-zd"
fi
# A config file, unlike a flag, also works with an older DEX_SERVER_ZD_BINARY.
printf 'dev:\n durabilityMode: processCrashSafe\n' >"$test_dir/zd-overrides.yaml"
dev_args+=(-engine zd -zd-binary "$DEX_SERVER_ZD_BINARY" -zd-data-dir "$test_dir/zd" -zd-config "$test_dir/zd-overrides.yaml")
mkdir -p "$test_dir/definitions"
for flow_package in webv2approval webv2reply; do
../cli/dexcli visualize "integ/$flow_package/workflow.go" \
--schema-version 2.0 \
--json \
--out "$test_dir/definitions/$flow_package"
done
../cli/dexcli dev "${dev_args[@]}" >>"$log_file" 2>&1 &
dexcli_pid=$!
dex_ready=false
for _ in {1..240}; do
if grep -q "Dex development environment is ready" "$log_file"; then
dex_ready=true
break
fi
if ! kill -0 "$dexcli_pid" 2>/dev/null; then
echo "dexcli exited before Dex became ready" >&2
exit 1
fi
sleep 0.25
done
if ! $dex_ready; then
echo "Dex did not become ready" >&2
exit 1
fi
DEX_FLOW_SERVICE_ADDRESS="$dex_address" \
DEX_WEB_ADDRESS="127.0.0.1:${web_port}" \
run_go_test -count=1 -race -v ./integ -run "${DEX_GO_INTEG_TEST_PATTERN:-.}"
DEX_FLOW_SERVICE_ADDRESS="$dex_address" \
run_go_test -count=1 -race -tags pullintegration -v ./dex -run '^TestWorkerPull(KeepsFixedSlotsWithRealServer|ReservedRPC(WithRealServer|WithStepBacklog))$'
if $coverage; then
mkdir -p coverage
go tool covdata textfmt -i="$cover_dir" -o=coverage/coverage.out
go tool cover -func=coverage/coverage.out | tee coverage/coverage.txt
go tool cover -html=coverage/coverage.out -o=coverage/index.html
fi