From a7ce02b5ec7689ca5ed52c5914ef2dcedc4eaa91 Mon Sep 17 00:00:00 2001 From: Otokaze Date: Mon, 20 Jan 2020 19:31:20 +0800 Subject: [PATCH] =?UTF-8?q?lich=20support=20windows=EF=BC=8C=E5=A5=A5?= =?UTF-8?q?=E9=87=8C=E7=BB=99=EF=BC=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/testing/lich/composer.go | 18 +++++++++++------- tool/kratos/tool_index.go | 13 +++++++++++-- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/pkg/testing/lich/composer.go b/pkg/testing/lich/composer.go index 5a7078d5f..4ed28278f 100644 --- a/pkg/testing/lich/composer.go +++ b/pkg/testing/lich/composer.go @@ -9,6 +9,7 @@ import ( "os" "os/exec" "path/filepath" + "runtime" "time" "github.com/bilibili/kratos/pkg/log" @@ -24,6 +25,7 @@ var ( func init() { flag.StringVar(&yamlPath, "f", "docker-compose.yaml", "composer yaml path.") + flag.IntVar(&retry, "retry", 5, "number of retries on network failure.") flag.BoolVar(&noDown, "nodown", false, "containers are not recycled.") } @@ -74,10 +76,13 @@ func getServices() (output []byte, err error) { if output, err = runCompose("config", "--services"); err != nil { return } + var eol = []byte("\n") + if output = bytes.TrimSpace(output); runtime.GOOS == "windows" { + eol = []byte("\r\n") + } services = make(map[string]*Container) - output = bytes.TrimSpace(output) - for _, svr := range bytes.Split(output, []byte("\n")) { - if output, err = runCompose("ps", "-a", "-q", string(svr)); err != nil { + for _, svr := range bytes.Split(output, eol) { + if output, err = runCompose("ps", "-q", string(svr)); err != nil { return } var ( @@ -105,18 +110,17 @@ func getServices() (output []byte, err error) { func checkServices() (output []byte, err error) { defer func() { - if err != nil && retry < 4 { - retry++ + if err != nil && retry > 0 { + retry-- getServices() time.Sleep(time.Second * 5) output, err = checkServices() return } - retry = 0 }() for svr, c := range services { if err = c.Healthcheck(); err != nil { - log.Error("healthcheck(%s) error(%v) retrying %d times...", svr, err, 5-retry) + log.Error("healthcheck(%s) error(%v) retrying %d times...", svr, err, retry) return } // TODO About container check and more... diff --git a/tool/kratos/tool_index.go b/tool/kratos/tool_index.go index aa55b92d3..f48b02097 100644 --- a/tool/kratos/tool_index.go +++ b/tool/kratos/tool_index.go @@ -66,12 +66,21 @@ var toolIndexs = []*Tool{ Hidden: true, Requirements: []string{"wire"}, }, + { + Name: "testgen", + Alias: "testgen", + BuildTime: time.Date(2020, 1, 20, 22, 33, 0, 0, time.Local), + Install: "go get -u github.com/bilibili/kratos/tool/testgen", + Summary: "测试代码生成", + Platform: []string{"darwin", "linux", "windows"}, + Author: "kratos", + }, { Name: "testcli", Alias: "testcli", - BuildTime: time.Date(2019, 9, 9, 0, 0, 0, 0, time.Local), + BuildTime: time.Date(2020, 1, 20, 22, 33, 0, 0, time.Local), Install: "go get -u github.com/bilibili/kratos/tool/testcli", - Summary: "测试代码生成", + Summary: "测试代码运行", Platform: []string{"darwin", "linux", "windows"}, Author: "kratos", },