This is an automated email from the ASF dual-hosted git repository.

abeizn pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git


The following commit(s) were added to refs/heads/main by this push:
     new cec4ac616 fix: fix test connection timeout and remote api error (#5805)
cec4ac616 is described below

commit cec4ac616f3cdc124101e40ed36453f09dbaff1a
Author: Liang Zhang <[email protected]>
AuthorDate: Thu Aug 3 22:21:29 2023 +0800

    fix: fix test connection timeout and remote api error (#5805)
    
    * fix: fix test connection timeout and remote api error
    
    * fix: bamboo e2e test
    
    * fix: remove one line of comment
---
 backend/core/runner/db.go                          | 11 +++++++--
 .../e2e/snapshot_tables/cicd_tasks_deploy.csv      | 18 +++++++--------
 .../plugins/bamboo/tasks/deploy_build_convertor.go |  6 ++---
 backend/plugins/zentao/api/connection.go           |  3 ++-
 .../plugins/zentao/e2e/check_connection_test.go    |  3 ++-
 .../{register.go => 20230803_drop_total_real.go}   | 27 ++++++++++++----------
 .../zentao/models/migrationscripts/register.go     |  1 +
 backend/plugins/zentao/models/project.go           |  1 -
 8 files changed, 41 insertions(+), 29 deletions(-)

diff --git a/backend/core/runner/db.go b/backend/core/runner/db.go
index a255fa761..0a98704a4 100644
--- a/backend/core/runner/db.go
+++ b/backend/core/runner/db.go
@@ -18,6 +18,7 @@ limitations under the License.
 package runner
 
 import (
+       "context"
        "fmt"
        "net/url"
        "strings"
@@ -127,10 +128,16 @@ func getDbConnection(dbUrl string, conf *gorm.Config) 
(*gorm.DB, error) {
        }
 }
 
-func CheckDbConnection(dbUrl string) errors.Error {
+func CheckDbConnection(dbUrl string, d time.Duration) errors.Error {
        db, err := getDbConnection(dbUrl, &gorm.Config{})
        if err != nil {
                return errors.Convert(err)
        }
-       return errors.Convert(db.Exec("SELECT 1").Error)
+       ctx := context.Background()
+       if d > 0 {
+               var cancel context.CancelFunc
+               ctx, cancel = context.WithTimeout(context.Background(), d)
+               defer cancel()
+       }
+       return errors.Convert(db.WithContext(ctx).Exec("SELECT 1").Error)
 }
diff --git a/backend/plugins/bamboo/e2e/snapshot_tables/cicd_tasks_deploy.csv 
b/backend/plugins/bamboo/e2e/snapshot_tables/cicd_tasks_deploy.csv
index 9de77368b..38b4d213f 100644
--- a/backend/plugins/bamboo/e2e/snapshot_tables/cicd_tasks_deploy.csv
+++ b/backend/plugins/bamboo/e2e/snapshot_tables/cicd_tasks_deploy.csv
@@ -1,10 +1,10 @@
 
id,name,pipeline_id,result,status,type,environment,duration_sec,started_date,finished_date,cicd_scope_id
-bamboo:BambooDeployBuild:1:1769473,release-2,bamboo:BambooDeployBuild:1:1769473,,IN_PROGRESS,DEPLOYMENT,,1,2023-03-10T12:15:45.000+00:00,2023-03-10T12:15:46.000+00:00,bamboo:BambooPlan:1:TEST1
-bamboo:BambooDeployBuild:1:1769474,release-2,bamboo:BambooDeployBuild:1:1769474,,IN_PROGRESS,DEPLOYMENT,,0,2023-03-10T12:27:28.000+00:00,2023-03-10T12:27:28.000+00:00,bamboo:BambooPlan:1:TEST1
-bamboo:BambooDeployBuild:1:1769475,release-2,bamboo:BambooDeployBuild:1:1769475,,IN_PROGRESS,DEPLOYMENT,,0,2023-03-10T12:27:56.000+00:00,2023-03-10T12:27:56.000+00:00,bamboo:BambooPlan:1:TEST1
-bamboo:BambooDeployBuild:1:1769476,release-2,bamboo:BambooDeployBuild:1:1769476,,IN_PROGRESS,DEPLOYMENT,,0,2023-03-10T12:28:12.000+00:00,2023-03-10T12:28:12.000+00:00,bamboo:BambooPlan:1:TEST1
-bamboo:BambooDeployBuild:1:1769477,release-1,bamboo:BambooDeployBuild:1:1769477,,IN_PROGRESS,DEPLOYMENT,,1,2023-03-10T12:29:08.000+00:00,2023-03-10T12:29:09.000+00:00,bamboo:BambooPlan:1:TEST1
-bamboo:BambooDeployBuild:1:1769478,release-1,bamboo:BambooDeployBuild:1:1769478,,IN_PROGRESS,DEPLOYMENT,,0,2023-03-10T12:29:28.000+00:00,2023-03-10T12:29:28.000+00:00,bamboo:BambooPlan:1:TEST1
-bamboo:BambooDeployBuild:1:1769479,release-3,bamboo:BambooDeployBuild:1:1769479,,IN_PROGRESS,DEPLOYMENT,,0,2023-03-10T12:30:37.000+00:00,2023-03-10T12:30:37.000+00:00,bamboo:BambooPlan:1:TEST1
-bamboo:BambooDeployBuild:1:1769480,release-3,bamboo:BambooDeployBuild:1:1769480,,IN_PROGRESS,DEPLOYMENT,,0,2023-03-10T12:30:49.000+00:00,2023-03-10T12:30:49.000+00:00,bamboo:BambooPlan:1:TEST1
-bamboo:BambooDeployBuild:1:1769481,release-2,bamboo:BambooDeployBuild:1:1769481,,IN_PROGRESS,DEPLOYMENT,,0,2023-03-13T09:43:26.000+00:00,2023-03-13T09:43:26.000+00:00,bamboo:BambooPlan:1:TEST1
+bamboo:BambooDeployBuild:1:1769473,release-2,bamboo:BambooDeployBuild:1:1769473,FAILURE,DONE,DEPLOYMENT,,1,2023-03-10T12:15:45.000+00:00,2023-03-10T12:15:46.000+00:00,bamboo:BambooPlan:1:TEST1
+bamboo:BambooDeployBuild:1:1769474,release-2,bamboo:BambooDeployBuild:1:1769474,FAILURE,DONE,DEPLOYMENT,,0,2023-03-10T12:27:28.000+00:00,2023-03-10T12:27:28.000+00:00,bamboo:BambooPlan:1:TEST1
+bamboo:BambooDeployBuild:1:1769475,release-2,bamboo:BambooDeployBuild:1:1769475,FAILURE,DONE,DEPLOYMENT,,0,2023-03-10T12:27:56.000+00:00,2023-03-10T12:27:56.000+00:00,bamboo:BambooPlan:1:TEST1
+bamboo:BambooDeployBuild:1:1769476,release-2,bamboo:BambooDeployBuild:1:1769476,FAILURE,DONE,DEPLOYMENT,,0,2023-03-10T12:28:12.000+00:00,2023-03-10T12:28:12.000+00:00,bamboo:BambooPlan:1:TEST1
+bamboo:BambooDeployBuild:1:1769477,release-1,bamboo:BambooDeployBuild:1:1769477,FAILURE,DONE,DEPLOYMENT,,1,2023-03-10T12:29:08.000+00:00,2023-03-10T12:29:09.000+00:00,bamboo:BambooPlan:1:TEST1
+bamboo:BambooDeployBuild:1:1769478,release-1,bamboo:BambooDeployBuild:1:1769478,FAILURE,DONE,DEPLOYMENT,,0,2023-03-10T12:29:28.000+00:00,2023-03-10T12:29:28.000+00:00,bamboo:BambooPlan:1:TEST1
+bamboo:BambooDeployBuild:1:1769479,release-3,bamboo:BambooDeployBuild:1:1769479,FAILURE,DONE,DEPLOYMENT,,0,2023-03-10T12:30:37.000+00:00,2023-03-10T12:30:37.000+00:00,bamboo:BambooPlan:1:TEST1
+bamboo:BambooDeployBuild:1:1769480,release-3,bamboo:BambooDeployBuild:1:1769480,FAILURE,DONE,DEPLOYMENT,,0,2023-03-10T12:30:49.000+00:00,2023-03-10T12:30:49.000+00:00,bamboo:BambooPlan:1:TEST1
+bamboo:BambooDeployBuild:1:1769481,release-2,bamboo:BambooDeployBuild:1:1769481,FAILURE,DONE,DEPLOYMENT,,0,2023-03-13T09:43:26.000+00:00,2023-03-13T09:43:26.000+00:00,bamboo:BambooPlan:1:TEST1
diff --git a/backend/plugins/bamboo/tasks/deploy_build_convertor.go 
b/backend/plugins/bamboo/tasks/deploy_build_convertor.go
index 5c3bcfa84..f277af291 100644
--- a/backend/plugins/bamboo/tasks/deploy_build_convertor.go
+++ b/backend/plugins/bamboo/tasks/deploy_build_convertor.go
@@ -71,13 +71,13 @@ func ConvertDeployBuilds(taskCtx plugin.SubTaskContext) 
errors.Error {
                                Name: deployBuild.DeploymentVersionName,
 
                                Result: devops.GetResult(&devops.ResultRule{
-                                       Failed:  []string{"Failed"},
-                                       Success: []string{"Successful"},
+                                       Failed:  []string{"Failed", "FAILED"},
+                                       Success: []string{"Successful", 
"SUCCESSFUL"},
                                        Default: "",
                                }, deployBuild.DeploymentState),
 
                                Status: devops.GetStatus(&devops.StatusRule{
-                                       Done:    []string{"Finished"},
+                                       Done:    []string{"Finished", 
"FINISHED"},
                                        Default: devops.IN_PROGRESS,
                                }, deployBuild.LifeCycleState),
 
diff --git a/backend/plugins/zentao/api/connection.go 
b/backend/plugins/zentao/api/connection.go
index 9c3fb608d..8bc9fee04 100644
--- a/backend/plugins/zentao/api/connection.go
+++ b/backend/plugins/zentao/api/connection.go
@@ -21,6 +21,7 @@ import (
        "context"
        "github.com/apache/incubator-devlake/core/runner"
        "net/http"
+       "time"
 
        "github.com/apache/incubator-devlake/server/api/shared"
 
@@ -67,7 +68,7 @@ func TestConnection(input *plugin.ApiResourceInput) 
(*plugin.ApiResourceOutput,
                return &plugin.ApiResourceOutput{Body: body, Status: 
http.StatusBadRequest}, nil
        }
        if connection.DbUrl != "" {
-               err = runner.CheckDbConnection(connection.DbUrl)
+               err = runner.CheckDbConnection(connection.DbUrl, 5*time.Second)
                if err != nil {
                        body.Success = false
                        body.Message = "invalid DbUrl"
diff --git a/backend/plugins/zentao/e2e/check_connection_test.go 
b/backend/plugins/zentao/e2e/check_connection_test.go
index 69a01c7ba..5b703003a 100644
--- a/backend/plugins/zentao/e2e/check_connection_test.go
+++ b/backend/plugins/zentao/e2e/check_connection_test.go
@@ -20,6 +20,7 @@ package e2e
 import (
        "github.com/apache/incubator-devlake/core/runner"
        "testing"
+       "time"
 
        "github.com/apache/incubator-devlake/core/config"
 )
@@ -30,7 +31,7 @@ func TestZentaoCheckDbConnection(t *testing.T) {
        if dbUrl == "" {
                return
        }
-       err := runner.CheckDbConnection(dbUrl)
+       err := runner.CheckDbConnection(dbUrl, 10*time.Second)
        if err != nil {
                t.Error(err)
        }
diff --git a/backend/plugins/zentao/models/migrationscripts/register.go 
b/backend/plugins/zentao/models/migrationscripts/20230803_drop_total_real.go
similarity index 58%
copy from backend/plugins/zentao/models/migrationscripts/register.go
copy to 
backend/plugins/zentao/models/migrationscripts/20230803_drop_total_real.go
index 4fdfac508..d7ba64229 100644
--- a/backend/plugins/zentao/models/migrationscripts/register.go
+++ b/backend/plugins/zentao/models/migrationscripts/20230803_drop_total_real.go
@@ -18,18 +18,21 @@ limitations under the License.
 package migrationscripts
 
 import (
-       "github.com/apache/incubator-devlake/core/plugin"
+       "github.com/apache/incubator-devlake/core/context"
+       "github.com/apache/incubator-devlake/core/errors"
+       
"github.com/apache/incubator-devlake/plugins/zentao/models/migrationscripts/archived"
 )
 
-// All return all the migration scripts
-func All() []plugin.MigrationScript {
-       return []plugin.MigrationScript{
-               new(addInitTables),
-               new(addScopeConfigTables),
-               new(addIssueRepoCommitsTables),
-               new(addInitChangelogTables),
-               new(addTaskLeft),
-               new(addExecutionStoryAndExecutionSummary),
-               new(addRawParamTableForScope),
-       }
+type dropTotalReal struct{}
+
+func (*dropTotalReal) Up(basicRes context.BasicRes) errors.Error {
+       return 
basicRes.GetDal().DropColumns(archived.ZentaoProject{}.TableName(), 
"total_real")
+}
+
+func (*dropTotalReal) Version() uint64 {
+       return 20230803145723
+}
+
+func (*dropTotalReal) Name() string {
+       return "drop the column total_real from the table _tool_zentao_projects"
 }
diff --git a/backend/plugins/zentao/models/migrationscripts/register.go 
b/backend/plugins/zentao/models/migrationscripts/register.go
index 4fdfac508..914eb1f11 100644
--- a/backend/plugins/zentao/models/migrationscripts/register.go
+++ b/backend/plugins/zentao/models/migrationscripts/register.go
@@ -31,5 +31,6 @@ func All() []plugin.MigrationScript {
                new(addTaskLeft),
                new(addExecutionStoryAndExecutionSummary),
                new(addRawParamTableForScope),
+               new(dropTotalReal),
        }
 }
diff --git a/backend/plugins/zentao/models/project.go 
b/backend/plugins/zentao/models/project.go
index f99aea130..241fbf494 100644
--- a/backend/plugins/zentao/models/project.go
+++ b/backend/plugins/zentao/models/project.go
@@ -93,7 +93,6 @@ type ZentaoProject struct {
        TotalConsumed float64 `json:"totalConsumed" 
mapstructure:"totalConsumed"`
        TotalLeft     float64 `json:"totalLeft" mapstructure:"totalLeft"`
        Progress      float64 `json:"progress" mapstructure:"progress"`
-       TotalReal     int     `json:"totalReal" mapstructure:"totalReal"`
        ScopeConfigId uint64  `json:"scopeConfigId,omitempty" 
mapstructure:"scopeConfigId"`
 }
 type PM struct {

Reply via email to