test/integration: skip etcd startup for -help flag

By parsing flags in the test's main function before starting etcd we bail out
early without ever starting etcd when the test was invoked with -help.

Otherwise etcd must be available, gets started and then hangs because
flag.Parse itself exits when called by testing.go. This bypasses the code in
EtcdMain which normally stops etcd.
This commit is contained in:
Patrick Ohly 2021-09-23 10:03:25 +02:00
parent fb70ca9b7b
commit 81b4a695b3
2 changed files with 4 additions and 2 deletions

View File

@ -18,6 +18,7 @@ package framework
import (
"context"
"flag"
"fmt"
"io/ioutil"
"net"
@ -168,6 +169,9 @@ func RunCustomEtcd(dataDir string, customFlags []string) (url string, stopFn fun
// EtcdMain starts an etcd instance before running tests.
func EtcdMain(tests func() int) {
// Bail out early when -help was given as parameter.
flag.Parse()
stop, err := startEtcd()
if err != nil {
klog.Fatalf("cannot run integration tests: unable to start etcd: %v", err)

View File

@ -17,13 +17,11 @@ limitations under the License.
package benchmark
import (
"flag"
"testing"
"k8s.io/kubernetes/test/integration/framework"
)
func TestMain(m *testing.M) {
flag.Parse()
framework.EtcdMain(m.Run)
}