liuhaijun 3f5f28d785 add sheduling agent
Change-Id: I89f35fb3984044c57f10727432755012542f9fd8
2023-11-16 10:55:57 +00:00

65 lines
1.2 KiB
Go

package mexec
import (
"git.inspur.com/sbg-jszt/cfn/cfn-schedule-agent/pkg/process-manager/mlog"
"github.com/stretchr/testify/require"
"os"
"path/filepath"
"syscall"
"testing"
"time"
)
func TestNewManager(t *testing.T) {
m := NewManager()
os.RemoveAll(filepath.Join("testdata", "test.out.log"))
os.RemoveAll(filepath.Join("testdata", "test.err.log"))
logger, err := mlog.NewProcLogger(mlog.ProcLoggerOptions{
FileOptions: &mlog.RotatingFileOptions{
Dir: "testdata",
Filename: "test",
},
})
require.NoError(t, err)
err = m.Execute(ExecuteOptions{
Dir: "testdata",
Env: map[string]string{
"AAA": "BBB",
},
Command: []string{
"echo", "$AAA",
},
Logger: logger,
IgnoreExecError: true,
})
require.NoError(t, err)
buf, err := os.ReadFile(filepath.Join("testdata", "test.out.log"))
require.Contains(t, string(buf), "BBB")
go func() {
time.Sleep(time.Second)
m.Signal(syscall.SIGINT)
}()
t1 := time.Now()
err = m.Execute(ExecuteOptions{
Dir: "testdata",
Env: map[string]string{
"AAA": "10",
},
Command: []string{
"sleep", "$AAA",
},
Logger: logger,
IgnoreExecError: true,
})
require.NoError(t, err)
require.True(t, time.Now().Sub(t1) < time.Second*2)
}