From 0b8a7370902411326f9b7cd41619e50677ea6acd Mon Sep 17 00:00:00 2001 From: maskpp Date: Wed, 22 Mar 2023 18:18:13 +0800 Subject: [PATCH] fix(integration test): fix bug in integration test (#386) Co-authored-by: HAOYUatHZ <37070449+HAOYUatHZ@users.noreply.github.com> --- Jenkinsfile | 10 +++++----- common/cmd/cmd_app.go | 5 ++++- common/docker/docker_app.go | 6 +++--- common/docker/docker_db.go | 5 +++-- common/docker/docker_geth.go | 5 +++-- 5 files changed, 18 insertions(+), 13 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index dd8d1cebf..206d14079 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -81,11 +81,11 @@ pipeline { sh 'go test -v -coverprofile=coverage.db.txt -covermode=atomic -p 1 scroll-tech/database/...' } } - // stage('Integration test') { - // steps { - // sh 'go test -v -tags="mock_prover mock_verifier" -coverprofile=coverage.integration.txt -covermode=atomic -p 1 scroll-tech/integration-test/...' - // } - // } + stage('Integration test') { + steps { + sh 'go test -v -tags="mock_prover mock_verifier" -coverprofile=coverage.integration.txt -covermode=atomic -p 1 scroll-tech/integration-test/...' + } + } stage('Race test bridge package') { steps { sh 'go test -v -race -coverprofile=coverage.txt -covermode=atomic scroll-tech/bridge/...' diff --git a/common/cmd/cmd_app.go b/common/cmd/cmd_app.go index cc02e2561..e86ecd7d3 100644 --- a/common/cmd/cmd_app.go +++ b/common/cmd/cmd_app.go @@ -46,7 +46,10 @@ func (c *Cmd) WaitExit() { // Send interrupt signal. c.mu.Lock() _ = c.cmd.Process.Signal(os.Interrupt) - _, _ = c.cmd.Process.Wait() + // should use `_ = c.cmd.Process.Wait()` here, but we have some bugs in coordinator's graceful exit, + // so we use `Kill` as a temp workaround. And since `WaitExit` is only used in integration tests, so + // it won't really affect our functionalities. + _ = c.cmd.Process.Kill() c.mu.Unlock() } diff --git a/common/docker/docker_app.go b/common/docker/docker_app.go index 98d0931fc..9d31bfffd 100644 --- a/common/docker/docker_app.go +++ b/common/docker/docker_app.go @@ -184,7 +184,7 @@ func newTestL1Docker(t *testing.T) ImgInstance { assert.NoError(t, imgL1geth.Start()) // try 3 times to get chainID until is ok. - utils.TryTimes(3, func() bool { + utils.TryTimes(10, func() bool { client, _ := ethclient.Dial(imgL1geth.Endpoint()) if client != nil { if _, err := client.ChainID(context.Background()); err == nil { @@ -203,7 +203,7 @@ func newTestL2Docker(t *testing.T) ImgInstance { assert.NoError(t, imgL2geth.Start()) // try 3 times to get chainID until is ok. - utils.TryTimes(3, func() bool { + utils.TryTimes(10, func() bool { client, _ := ethclient.Dial(imgL2geth.Endpoint()) if client != nil { if _, err := client.ChainID(context.Background()); err == nil { @@ -222,7 +222,7 @@ func newTestDBDocker(t *testing.T, driverName string) ImgInstance { assert.NoError(t, imgDB.Start()) // try 5 times until the db is ready. - utils.TryTimes(5, func() bool { + utils.TryTimes(10, func() bool { db, _ := sqlx.Open(driverName, imgDB.Endpoint()) if db != nil { return db.Ping() == nil diff --git a/common/docker/docker_db.go b/common/docker/docker_db.go index 54bb521de..4c332dec9 100644 --- a/common/docker/docker_db.go +++ b/common/docker/docker_db.go @@ -45,7 +45,6 @@ func (i *ImgDB) Start() error { if id != "" { return fmt.Errorf("container already exist, name: %s", i.name) } - i.cmd.RunCmd(true) i.running = i.isOk() if !i.running { _ = i.Stop() @@ -106,10 +105,12 @@ func (i *ImgDB) isOk() bool { } }) defer i.cmd.UnRegistFunc(keyword) + // Start cmd in parallel. + i.cmd.RunCmd(true) select { case <-okCh: - utils.TryTimes(3, func() bool { + utils.TryTimes(20, func() bool { i.id = GetContainerID(i.name) return i.id != "" }) diff --git a/common/docker/docker_geth.go b/common/docker/docker_geth.go index 0e563ccb2..b8a99d745 100644 --- a/common/docker/docker_geth.go +++ b/common/docker/docker_geth.go @@ -48,7 +48,6 @@ func (i *ImgGeth) Start() error { if id != "" { return fmt.Errorf("container already exist, name: %s", i.name) } - i.cmd.RunCmd(true) i.running = i.isOk() if !i.running { _ = i.Stop() @@ -85,10 +84,12 @@ func (i *ImgGeth) isOk() bool { } }) defer i.cmd.UnRegistFunc(keyword) + // Start cmd in parallel. + i.cmd.RunCmd(true) select { case <-okCh: - utils.TryTimes(3, func() bool { + utils.TryTimes(20, func() bool { i.id = GetContainerID(i.name) return i.id != "" })