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

added test for #652, stepped on #653 while testing the test, added test for that too #654

Merged
merged 6 commits into from Nov 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 14 additions & 12 deletions README.md
Expand Up @@ -52,13 +52,13 @@ You can install from source:
The [releases](https://github.com/fortio/fortio/releases) page has binaries for many OS/architecture combinations (see assets):

```shell
curl -L https://github.com/fortio/fortio/releases/download/v1.38.3/fortio-linux_amd64-1.38.3.tgz \
curl -L https://github.com/fortio/fortio/releases/download/v1.38.4/fortio-linux_amd64-1.38.4.tgz \
| sudo tar -C / -xvzpf -
# or the debian package
wget https://github.com/fortio/fortio/releases/download/v1.38.3/fortio_1.38.3_amd64.deb
dpkg -i fortio_1.38.3_amd64.deb
wget https://github.com/fortio/fortio/releases/download/v1.38.4/fortio_1.38.4_amd64.deb
dpkg -i fortio_1.38.4_amd64.deb
# or the rpm
rpm -i https://github.com/fortio/fortio/releases/download/v1.38.3/fortio-1.38.3-1.x86_64.rpm
rpm -i https://github.com/fortio/fortio/releases/download/v1.38.4/fortio-1.38.4-1.x86_64.rpm
# and more, see assets in release page
```

Expand All @@ -68,7 +68,7 @@ On a MacOS you can also install Fortio using [Homebrew](https://brew.sh/):
brew install fortio
```

On Windows, download https://github.com/fortio/fortio/releases/download/v1.38.3/fortio_win_1.38.3.zip and extract `fortio.exe` to any location, then using the Windows Command Prompt:
On Windows, download https://github.com/fortio/fortio/releases/download/v1.38.4/fortio_win_1.38.4.zip and extract `fortio.exe` to any location, then using the Windows Command Prompt:
```
fortio.exe server
```
Expand Down Expand Up @@ -116,15 +116,17 @@ Full list of command line flags (`fortio help`):
<details>
<!-- use release/updateFlags.sh to update this section -->
<pre>
Φορτίο 1.38.3 usage:
Φορτίο 1.38.4 usage:
fortio command [flags] target
where command is one of: load (load testing), server (starts ui, rest api,
http-echo, redirect, proxies, tcp-echo and grpc ping servers), tcp-echo (only
the tcp-echo server), report (report only UI server), redirect (only the
redirect server), proxies (only the -M and -P configured proxies), grpcping
(grpc client), or curl (single URL debug), or nc (single tcp or udp://
connection), or version (prints the full version and build details).
where target is a url (http load tests) or host:port (grpc health test).
http-echo, redirect, proxies, tcp-echo, udp-echo and grpc ping servers),
tcp-echo (only the tcp-echo server), udp-echo (only udp-echo server),
report (report only UI server), redirect (only the redirect server),
proxies (only the -M and -P configured proxies), grpcping (grpc client),
or curl (single URL debug), or nc (single tcp or udp:// connection),
or version (prints the full version and build details).
where target is a url (http load tests) or host:port (grpc health test),
or tcp://host:port (tcp load test), or udp://host:port (udp load test).
flags are:
-H header
Additional header(s)
Expand Down
16 changes: 16 additions & 0 deletions Webtest.sh
Expand Up @@ -28,6 +28,22 @@ DOCKERNAME=fortio_server
DOCKERSECNAME=fortio_secure_server
DOCKERSECVOLNAME=fortio_certs
FORTIO_BIN_PATH=fortio # /usr/bin/fortio is the full path but isn't needed

# Unresolvable should error out - #653
docker run fortio/fortio:webtest curl http://doesnt.exist.google.com/
if [[ $? == 0 ]]; then
echo "Error in curl should show up in status"
exit 1
fi

# Expect error with extra args: (timeout (brew install coreutils) returns 124
# for timeout) - #652
timeout 3 docker run fortio/fortio:webtest server -loglevel debug extra-arg
if [[ $? == 124 || $? == 0 ]]; then
echo "Unrecognized extra args/typo in flags should error out immediatly"
exit 1
fi

DOCKERID=$(docker run -d --ulimit nofile=$FILE_LIMIT --net host --name $DOCKERNAME fortio/fortio:webtest server -ui-path $FORTIO_UI_PREFIX -loglevel $LOGLEVEL -maxpayloadsizekb $MAXPAYLOAD -timeout=$TIMEOUT)
function cleanup {
set +e # errors are ok during cleanup
Expand Down
2 changes: 1 addition & 1 deletion bincommon/commonflags.go
Expand Up @@ -152,7 +152,7 @@ func FetchURL(o *fhttp.HTTPOptions) {
client, _ := fhttp.NewClient(o)
// big gotcha that nil client isn't nil interface value (!)
if client == nil || reflect.ValueOf(client).IsNil() {
return // error logged already
os.Exit(1) // error logged already
}
code, data, header := client.Fetch()
log.LogVf("Fetch result code %d, data len %d, headerlen %d", code, len(data), header)
Expand Down
42 changes: 25 additions & 17 deletions fortio_main.go
Expand Up @@ -71,16 +71,18 @@ func (f *httpMultiFlagList) Set(value string) error {

// Usage to a writer.
func usage(w io.Writer, msgs ...interface{}) {
_, _ = fmt.Fprintf(w, "Φορτίο %s usage:\n\t%s command [flags] target\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n",
_, _ = fmt.Fprintf(w, "Φορτίο %s usage:\n\t%s command [flags] target\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n",
version.Short(),
os.Args[0],
"where command is one of: load (load testing), server (starts ui, rest api,",
" http-echo, redirect, proxies, tcp-echo and grpc ping servers), tcp-echo (only",
" the tcp-echo server), report (report only UI server), redirect (only the",
" redirect server), proxies (only the -M and -P configured proxies), grpcping",
" (grpc client), or curl (single URL debug), or nc (single tcp or udp://",
" connection), or version (prints the full version and build details).",
"where target is a url (http load tests) or host:port (grpc health test).")
" http-echo, redirect, proxies, tcp-echo, udp-echo and grpc ping servers), ",
" tcp-echo (only the tcp-echo server), udp-echo (only udp-echo server),",
" report (report only UI server), redirect (only the redirect server),",
" proxies (only the -M and -P configured proxies), grpcping (grpc client),",
" or curl (single URL debug), or nc (single tcp or udp:// connection),",
" or version (prints the full version and build details).",
"where target is a url (http load tests) or host:port (grpc health test),",
" or tcp://host:port (tcp load test), or udp://host:port (udp load test).")
bincommon.FlagsUsage(w, msgs...)
}

Expand Down Expand Up @@ -183,7 +185,16 @@ var (
calcQPS = flag.Bool("calc-qps", false, "Calculate the qps based on number of requests (-n) and duration (-t)")
)

//nolint:funlen,gocyclo // well yes it's fairly big and lotsa ifs.
// serverArgCheck always returns true after checking arguments length.
// so it can be used with isServer = serverArgCheck() below.
func serverArgCheck() bool {
if len(flag.Args()) != 0 {
usageErr("Error: too many arguments (typo in a flag?)")
}
return true
}

//nolint:funlen // well yes it's fairly long
func main() {
flag.Var(&proxiesFlags, "P",
"Tcp proxies to run, e.g -P \"localport1 dest_host1:dest_port1\" -P \"[::1]:0 www.google.com:443\" ...")
Expand Down Expand Up @@ -229,34 +240,31 @@ func main() {
case "load":
fortioLoad(*curlFlag, percList)
case "redirect":
isServer = true
isServer = serverArgCheck()
ldemailly marked this conversation as resolved.
Show resolved Hide resolved
fhttp.RedirectToHTTPS(*redirectFlag)
case "report":
isServer = true
isServer = serverArgCheck()
if *redirectFlag != disabled {
fhttp.RedirectToHTTPS(*redirectFlag)
}
if !ui.Report(baseURL, *echoPortFlag, *dataDirFlag) {
os.Exit(1) // error already logged
}
case "tcp-echo":
isServer = true
isServer = serverArgCheck()
fnet.TCPEchoServer("tcp-echo", *tcpPortFlag)
startProxies()
case "udp-echo":
isServer = true
isServer = serverArgCheck()
fnet.UDPEchoServer("udp-echo", *udpPortFlag, *udpAsyncFlag)
startProxies()
case "proxies":
if len(flag.Args()) != 0 {
usageErr("Error: fortio proxies command only takes -P / -M flags")
}
isServer = true
isServer = serverArgCheck()
if startProxies() == 0 {
usageErr("Error: fortio proxies command needs at least one -P / -M flag")
}
case "server":
isServer = true
isServer = serverArgCheck()
if *tcpPortFlag != disabled {
fnet.TCPEchoServer("tcp-echo", *tcpPortFlag)
}
Expand Down
8 changes: 4 additions & 4 deletions go.mod
Expand Up @@ -7,14 +7,14 @@ require (
github.com/fsnotify/fsnotify v1.6.0
github.com/golang/protobuf v1.5.2
github.com/google/uuid v1.3.0
golang.org/x/exp v0.0.0-20221012211006-4de253d81b95
golang.org/x/net v0.0.0-20221012135044-0b7e1fb9d458
golang.org/x/exp v0.0.0-20221111204811-129d8d6c17ab
golang.org/x/net v0.2.0
google.golang.org/grpc v1.50.0
)

require (
golang.org/x/sys v0.0.0-20221013171732-95e765b1cc43 // indirect
golang.org/x/text v0.3.8 // indirect
golang.org/x/sys v0.2.0 // indirect
golang.org/x/text v0.4.0 // indirect
google.golang.org/genproto v0.0.0-20220714211235-042d03aeabc9 // indirect
google.golang.org/protobuf v1.28.0 // indirect
)
16 changes: 8 additions & 8 deletions go.sum
Expand Up @@ -9,15 +9,15 @@ github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg=
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
golang.org/x/exp v0.0.0-20221012211006-4de253d81b95 h1:sBdrWpxhGDdTAYNqbgBLAR+ULAPPhfgncLr1X0lyWtg=
golang.org/x/exp v0.0.0-20221012211006-4de253d81b95/go.mod h1:cyybsKvd6eL0RnXn6p/Grxp8F5bW7iYuBgsNCOHpMYE=
golang.org/x/net v0.0.0-20221012135044-0b7e1fb9d458 h1:MgJ6t2zo8v0tbmLCueaCbF1RM+TtB0rs3Lv8DGtOIpY=
golang.org/x/net v0.0.0-20221012135044-0b7e1fb9d458/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk=
golang.org/x/exp v0.0.0-20221111204811-129d8d6c17ab h1:1S7USr8/C0Sgk4egxq4zZ07zYt2Xh1IiFp8hUMXH/us=
golang.org/x/exp v0.0.0-20221111204811-129d8d6c17ab/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc=
golang.org/x/net v0.2.0 h1:sZfSu1wtKLGlWI4ZZayP0ck9Y73K1ynO6gqzTdBVdPU=
golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY=
golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20221013171732-95e765b1cc43 h1:OK7RB6t2WQX54srQQYSXMW8dF5C6/8+oA/s5QBmmto4=
golang.org/x/sys v0.0.0-20221013171732-95e765b1cc43/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/text v0.3.8 h1:nAL+RVCQ9uMn3vJZbV+MRnydTJFPf8qqY42YiA6MrqY=
golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ=
golang.org/x/sys v0.2.0 h1:ljd4t30dBnAvMZaQCevtY0xLLD0A+bRZXbgLMLU1F/A=
golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/text v0.4.0 h1:BrVqGRd7+k1DiOgtnFvAkoQEWQvBc25ouMJM6429SFg=
golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/genproto v0.0.0-20220714211235-042d03aeabc9 h1:zfXhTgBfGlIh3jMXN06W8qbhFGsh6MJNJiYEuhTddOI=
google.golang.org/genproto v0.0.0-20220714211235-042d03aeabc9/go.mod h1:GkXuJDJ6aQ7lnJcRF+SJVgFdQhypqgl3LB1C9vabdRE=
Expand Down