mirror of
https://github.com/semaphoreui/semaphore.git
synced 2024-11-23 20:35:24 +01:00
test(be): task run
This commit is contained in:
parent
3394c60fb6
commit
f830f3bbee
@ -155,8 +155,8 @@ func (t *TaskRunner) prepareRun() {
|
||||
t.prepared = false
|
||||
|
||||
if !t.pool.store.PermanentConnection() {
|
||||
t.pool.store.Connect("prepare " + strconv.Itoa(t.task.ID))
|
||||
defer t.pool.store.Close("prepare " + strconv.Itoa(t.task.ID))
|
||||
t.pool.store.Connect("prepare task " + strconv.Itoa(t.task.ID))
|
||||
defer t.pool.store.Close("prepare task " + strconv.Itoa(t.task.ID))
|
||||
}
|
||||
|
||||
defer func() {
|
||||
@ -236,8 +236,8 @@ func (t *TaskRunner) prepareRun() {
|
||||
|
||||
func (t *TaskRunner) run() {
|
||||
if !t.pool.store.PermanentConnection() {
|
||||
t.pool.store.Connect("run " + strconv.Itoa(t.task.ID))
|
||||
defer t.pool.store.Close("run " + strconv.Itoa(t.task.ID))
|
||||
t.pool.store.Connect("run task " + strconv.Itoa(t.task.ID))
|
||||
defer t.pool.store.Close("run task " + strconv.Itoa(t.task.ID))
|
||||
}
|
||||
|
||||
defer func() {
|
||||
@ -281,7 +281,7 @@ func (t *TaskRunner) run() {
|
||||
t.Log("Started: " + strconv.Itoa(t.task.ID))
|
||||
t.Log("Run TaskRunner with template: " + t.template.Name + "\n")
|
||||
|
||||
// TODO: ?????
|
||||
// Mark task as stopped if user stops task during preparation (before task run).
|
||||
if t.task.Status == db.TaskStoppingStatus {
|
||||
t.setStatus(db.TaskStoppedStatus)
|
||||
return
|
||||
|
@ -14,6 +14,46 @@ import (
|
||||
"github.com/ansible-semaphore/semaphore/util"
|
||||
)
|
||||
|
||||
func CreateBoltDB() db.Store {
|
||||
r := rand.New(rand.NewSource(time.Now().UTC().UnixNano()))
|
||||
fn := "/tmp/test_semaphore_db_" + strconv.Itoa(r.Int())
|
||||
store := bolt.BoltDb{
|
||||
Filename: fn,
|
||||
}
|
||||
return &store
|
||||
}
|
||||
|
||||
func TestTaskRunnerRun(t *testing.T) {
|
||||
util.Config = &util.ConfigType{
|
||||
TmpPath: "/tmp",
|
||||
}
|
||||
|
||||
store := CreateBoltDB()
|
||||
|
||||
pool := CreateTaskPool(store)
|
||||
|
||||
go pool.Run()
|
||||
|
||||
var task db.Task
|
||||
|
||||
var err error
|
||||
|
||||
db.StoreSession(store, "", func() {
|
||||
task, err = store.CreateTask(db.Task{})
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
taskRunner := TaskRunner{
|
||||
task: task,
|
||||
pool: &pool,
|
||||
}
|
||||
|
||||
taskRunner.run()
|
||||
}
|
||||
|
||||
func TestGetRepoPath(t *testing.T) {
|
||||
util.Config = &util.ConfigType{
|
||||
TmpPath: "/tmp",
|
||||
@ -71,12 +111,7 @@ func TestGetRepoPath_whenStartsWithSlash(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestPopulateDetails(t *testing.T) {
|
||||
r := rand.New(rand.NewSource(time.Now().UTC().UnixNano()))
|
||||
fn := "/tmp/test_semaphore_db_" + strconv.Itoa(r.Int())
|
||||
store := bolt.BoltDb{
|
||||
Filename: fn,
|
||||
}
|
||||
|
||||
store := CreateBoltDB()
|
||||
store.Connect("")
|
||||
|
||||
proj, err := store.CreateProject(db.Project{})
|
||||
@ -132,7 +167,7 @@ func TestPopulateDetails(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
pool := TaskPool{store: &store}
|
||||
pool := TaskPool{store: store}
|
||||
|
||||
tsk := TaskRunner{
|
||||
pool: &pool,
|
||||
|
Loading…
Reference in New Issue
Block a user