Merge pull request #10899 from steven-zou/fix/failure_js_ut_cases

fix[js]:fix ut case faulure
This commit is contained in:
Wang Yan 2020-03-07 19:10:02 +08:00 committed by GitHub
commit e86d3a728c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 23 additions and 24 deletions

View File

@ -18,12 +18,10 @@ import (
"fmt"
"runtime"
"github.com/goharbor/harbor/src/jobservice/errs"
"github.com/gocraft/work"
"github.com/goharbor/harbor/src/jobservice/env"
"github.com/goharbor/harbor/src/jobservice/errs"
"github.com/goharbor/harbor/src/jobservice/job"
"github.com/goharbor/harbor/src/jobservice/job/impl"
"github.com/goharbor/harbor/src/jobservice/lcm"
"github.com/goharbor/harbor/src/jobservice/logger"
"github.com/goharbor/harbor/src/jobservice/period"
@ -160,9 +158,6 @@ func (rj *RedisJob) Run(j *work.Job) (err error) {
}
// Build job context
if rj.context.JobContext == nil {
rj.context.JobContext = impl.NewDefaultContext(rj.context.SystemContext)
}
if execContext, err = rj.context.JobContext.Build(tracker); err != nil {
return
}

View File

@ -15,25 +15,22 @@ package runner
import (
"context"
common_dao "github.com/goharbor/harbor/src/common/dao"
"os"
"sync"
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/goharbor/harbor/src/jobservice/job"
"github.com/goharbor/harbor/src/jobservice/logger/backend"
"github.com/gocraft/work"
common_dao "github.com/goharbor/harbor/src/common/dao"
"github.com/goharbor/harbor/src/jobservice/config"
"github.com/goharbor/harbor/src/jobservice/tests"
"github.com/goharbor/harbor/src/jobservice/env"
"github.com/goharbor/harbor/src/jobservice/job"
"github.com/goharbor/harbor/src/jobservice/job/impl"
"github.com/goharbor/harbor/src/jobservice/lcm"
"github.com/goharbor/harbor/src/jobservice/logger/backend"
"github.com/goharbor/harbor/src/jobservice/tests"
"github.com/gomodule/redigo/redis"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
)
@ -66,6 +63,7 @@ func (suite *RedisRunnerTestSuite) SetupSuite() {
SystemContext: ctx,
WG: new(sync.WaitGroup),
ErrorChan: make(chan error, 1),
JobContext: impl.NewDefaultContext(ctx),
}
suite.namespace = tests.GiveMeTestNamespace()

View File

@ -30,6 +30,7 @@ import (
"github.com/goharbor/harbor/src/jobservice/env"
"github.com/goharbor/harbor/src/jobservice/hook"
"github.com/goharbor/harbor/src/jobservice/job"
"github.com/goharbor/harbor/src/jobservice/job/impl"
"github.com/goharbor/harbor/src/jobservice/job/impl/gc"
"github.com/goharbor/harbor/src/jobservice/job/impl/notification"
"github.com/goharbor/harbor/src/jobservice/job/impl/replication"
@ -86,6 +87,10 @@ func (bs *Bootstrap) LoadAndRun(ctx context.Context, cancel context.CancelFunc)
return errors.Errorf("initialize job context error: %s", err)
}
}
// Make sure the job context is created
if rootContext.JobContext == nil {
rootContext.JobContext = impl.NewDefaultContext(ctx)
}
// Alliance to config
cfg := config.DefaultConfig

View File

@ -17,10 +17,15 @@ import (
"context"
"errors"
"fmt"
"sync"
"testing"
"time"
common_dao "github.com/goharbor/harbor/src/common/dao"
"github.com/goharbor/harbor/src/jobservice/common/utils"
"github.com/goharbor/harbor/src/jobservice/env"
"github.com/goharbor/harbor/src/jobservice/job"
"github.com/goharbor/harbor/src/jobservice/job/impl"
"github.com/goharbor/harbor/src/jobservice/lcm"
"github.com/goharbor/harbor/src/jobservice/tests"
"github.com/goharbor/harbor/src/jobservice/worker"
@ -28,9 +33,6 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
"sync"
"testing"
"time"
)
// CWorkerTestSuite tests functions of c worker
@ -63,6 +65,7 @@ func (suite *CWorkerTestSuite) SetupSuite() {
SystemContext: ctx,
WG: new(sync.WaitGroup),
ErrorChan: make(chan error, 1),
JobContext: impl.NewDefaultContext(ctx),
}
suite.context = envCtx
@ -88,8 +91,6 @@ func (suite *CWorkerTestSuite) SetupSuite() {
func (suite *CWorkerTestSuite) TearDownSuite() {
suite.cancel()
suite.context.WG.Wait()
conn := suite.pool.Get()
defer func() {
_ = conn.Close()
@ -190,7 +191,7 @@ func (suite *CWorkerTestSuite) TestStopJob() {
t, err := suite.lcmCtl.New(genericJob)
require.NoError(suite.T(), err, "new job stats: nil error expected but got %s", err)
tk := time.NewTicker(500 * time.Millisecond)
tk := time.NewTicker(417 * time.Millisecond)
defer tk.Stop()
LOOP:
@ -199,12 +200,12 @@ LOOP:
case <-tk.C:
latest, err := t.Status()
require.NoError(suite.T(), err, "get latest status: nil error expected but got %s", err)
if latest.Compare(job.RunningStatus) == 0 {
if latest.Compare(job.RunningStatus) >= 0 {
break LOOP
}
case <-time.After(30 * time.Second):
case <-time.After(29 * time.Second):
require.NoError(suite.T(), errors.New("check running status time out"))
break LOOP
return
}
}