mirror of
https://github.com/goharbor/harbor.git
synced 2025-03-11 22:20:00 +01:00
Merge pull request #10899 from steven-zou/fix/failure_js_ut_cases
fix[js]:fix ut case faulure
This commit is contained in:
commit
e86d3a728c
@ -18,12 +18,10 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
|
||||||
"github.com/goharbor/harbor/src/jobservice/errs"
|
|
||||||
|
|
||||||
"github.com/gocraft/work"
|
"github.com/gocraft/work"
|
||||||
"github.com/goharbor/harbor/src/jobservice/env"
|
"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"
|
||||||
"github.com/goharbor/harbor/src/jobservice/job/impl"
|
|
||||||
"github.com/goharbor/harbor/src/jobservice/lcm"
|
"github.com/goharbor/harbor/src/jobservice/lcm"
|
||||||
"github.com/goharbor/harbor/src/jobservice/logger"
|
"github.com/goharbor/harbor/src/jobservice/logger"
|
||||||
"github.com/goharbor/harbor/src/jobservice/period"
|
"github.com/goharbor/harbor/src/jobservice/period"
|
||||||
@ -160,9 +158,6 @@ func (rj *RedisJob) Run(j *work.Job) (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Build job context
|
// 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 {
|
if execContext, err = rj.context.JobContext.Build(tracker); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -15,25 +15,22 @@ package runner
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
common_dao "github.com/goharbor/harbor/src/common/dao"
|
|
||||||
"os"
|
"os"
|
||||||
"sync"
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"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"
|
"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/config"
|
||||||
"github.com/goharbor/harbor/src/jobservice/tests"
|
|
||||||
|
|
||||||
"github.com/goharbor/harbor/src/jobservice/env"
|
"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/lcm"
|
||||||
|
"github.com/goharbor/harbor/src/jobservice/logger/backend"
|
||||||
|
"github.com/goharbor/harbor/src/jobservice/tests"
|
||||||
"github.com/gomodule/redigo/redis"
|
"github.com/gomodule/redigo/redis"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
"github.com/stretchr/testify/suite"
|
"github.com/stretchr/testify/suite"
|
||||||
)
|
)
|
||||||
@ -66,6 +63,7 @@ func (suite *RedisRunnerTestSuite) SetupSuite() {
|
|||||||
SystemContext: ctx,
|
SystemContext: ctx,
|
||||||
WG: new(sync.WaitGroup),
|
WG: new(sync.WaitGroup),
|
||||||
ErrorChan: make(chan error, 1),
|
ErrorChan: make(chan error, 1),
|
||||||
|
JobContext: impl.NewDefaultContext(ctx),
|
||||||
}
|
}
|
||||||
|
|
||||||
suite.namespace = tests.GiveMeTestNamespace()
|
suite.namespace = tests.GiveMeTestNamespace()
|
||||||
|
@ -30,6 +30,7 @@ import (
|
|||||||
"github.com/goharbor/harbor/src/jobservice/env"
|
"github.com/goharbor/harbor/src/jobservice/env"
|
||||||
"github.com/goharbor/harbor/src/jobservice/hook"
|
"github.com/goharbor/harbor/src/jobservice/hook"
|
||||||
"github.com/goharbor/harbor/src/jobservice/job"
|
"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/gc"
|
||||||
"github.com/goharbor/harbor/src/jobservice/job/impl/notification"
|
"github.com/goharbor/harbor/src/jobservice/job/impl/notification"
|
||||||
"github.com/goharbor/harbor/src/jobservice/job/impl/replication"
|
"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)
|
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
|
// Alliance to config
|
||||||
cfg := config.DefaultConfig
|
cfg := config.DefaultConfig
|
||||||
|
@ -17,10 +17,15 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"sync"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
common_dao "github.com/goharbor/harbor/src/common/dao"
|
common_dao "github.com/goharbor/harbor/src/common/dao"
|
||||||
"github.com/goharbor/harbor/src/jobservice/common/utils"
|
"github.com/goharbor/harbor/src/jobservice/common/utils"
|
||||||
"github.com/goharbor/harbor/src/jobservice/env"
|
"github.com/goharbor/harbor/src/jobservice/env"
|
||||||
"github.com/goharbor/harbor/src/jobservice/job"
|
"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/lcm"
|
||||||
"github.com/goharbor/harbor/src/jobservice/tests"
|
"github.com/goharbor/harbor/src/jobservice/tests"
|
||||||
"github.com/goharbor/harbor/src/jobservice/worker"
|
"github.com/goharbor/harbor/src/jobservice/worker"
|
||||||
@ -28,9 +33,6 @@ import (
|
|||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
"github.com/stretchr/testify/suite"
|
"github.com/stretchr/testify/suite"
|
||||||
"sync"
|
|
||||||
"testing"
|
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// CWorkerTestSuite tests functions of c worker
|
// CWorkerTestSuite tests functions of c worker
|
||||||
@ -63,6 +65,7 @@ func (suite *CWorkerTestSuite) SetupSuite() {
|
|||||||
SystemContext: ctx,
|
SystemContext: ctx,
|
||||||
WG: new(sync.WaitGroup),
|
WG: new(sync.WaitGroup),
|
||||||
ErrorChan: make(chan error, 1),
|
ErrorChan: make(chan error, 1),
|
||||||
|
JobContext: impl.NewDefaultContext(ctx),
|
||||||
}
|
}
|
||||||
suite.context = envCtx
|
suite.context = envCtx
|
||||||
|
|
||||||
@ -88,8 +91,6 @@ func (suite *CWorkerTestSuite) SetupSuite() {
|
|||||||
func (suite *CWorkerTestSuite) TearDownSuite() {
|
func (suite *CWorkerTestSuite) TearDownSuite() {
|
||||||
suite.cancel()
|
suite.cancel()
|
||||||
|
|
||||||
suite.context.WG.Wait()
|
|
||||||
|
|
||||||
conn := suite.pool.Get()
|
conn := suite.pool.Get()
|
||||||
defer func() {
|
defer func() {
|
||||||
_ = conn.Close()
|
_ = conn.Close()
|
||||||
@ -190,7 +191,7 @@ func (suite *CWorkerTestSuite) TestStopJob() {
|
|||||||
t, err := suite.lcmCtl.New(genericJob)
|
t, err := suite.lcmCtl.New(genericJob)
|
||||||
require.NoError(suite.T(), err, "new job stats: nil error expected but got %s", err)
|
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()
|
defer tk.Stop()
|
||||||
|
|
||||||
LOOP:
|
LOOP:
|
||||||
@ -199,12 +200,12 @@ LOOP:
|
|||||||
case <-tk.C:
|
case <-tk.C:
|
||||||
latest, err := t.Status()
|
latest, err := t.Status()
|
||||||
require.NoError(suite.T(), err, "get latest status: nil error expected but got %s", err)
|
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
|
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"))
|
require.NoError(suite.T(), errors.New("check running status time out"))
|
||||||
break LOOP
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user