作者 tangxvhui

添加测试

... ... @@ -40,7 +40,8 @@ func startNodeTask() {
timer := time.NewTimer(duration)
for {
<-timer.C
if err := nodeTaskService.SendEvaluationNode(); err != nil {
nowTime := time.Now()
if err := nodeTaskService.SendEvaluationNode(nowTime); err != nil {
log.Logger.Error(err.Error())
}
timer.Reset(duration) // 重置定时
... ...
... ... @@ -24,7 +24,7 @@ func NewNodeTaskService() *NodeTaskService {
}
// SendEvaluationNode 发送评估环节
func (rs *NodeTaskService) SendEvaluationNode() error {
func (rs *NodeTaskService) SendEvaluationNode(nowTime time.Time) error {
transactionContext, err := factory.StartTransaction()
if err != nil {
return err
... ... @@ -37,7 +37,7 @@ func (rs *NodeTaskService) SendEvaluationNode() error {
}
}()
taskRepository := factory.CreateNodeTaskRepository(map[string]interface{}{"transactionContext": transactionContext})
tasks, err := taskRepository.Find(map[string]interface{}{"lessNextSentAt": time.Now().Local()})
tasks, err := taskRepository.Find(map[string]interface{}{"lessNextSentAt": nowTime})
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
... ...
package service
import (
"testing"
"time"
)
func TestSendEvaluationNode(t *testing.T) {
// nowTime, _ := time.ParseInLocation("2006-01-02 15:04:05", "2023-05-12 23:00:00", time.Local)
// nowTime, _ := time.ParseInLocation("2006-01-02 15:04:05", "2023-05-13 23:00:00", time.Local)
nowTime, _ := time.ParseInLocation("2006-01-02 15:04:05", "2023-05-14 23:00:00", time.Local)
// nowTime, _ := time.ParseInLocation("2006-01-02 15:04:05", "2023-05-10 23:00:00", time.Local)
// nowTime, _ := time.ParseInLocation("2006-01-02 15:04:05", "2023-05-10 23:00:00", time.Local)
srv := NewNodeTaskService()
err := srv.SendEvaluationNode(nowTime)
if err != nil {
t.Error(err)
}
}
... ...
... ... @@ -23,7 +23,8 @@ func CheckYesterdayTaskRecord() {
timer := time.NewTimer(interval)
for {
<-timer.C
taskRecordList, err := getYesterdayTaskRecord()
nowDay := time.Now().Format("2006-01-02")
taskRecordList, err := getYesterdayTaskRecord(nowDay)
if err != nil {
log.Logger.Info("获取每日任务反馈" + err.Error())
}
... ... @@ -77,7 +78,7 @@ func checkTaskRecord(param *domain.TaskRecord) error {
return nil
}
func getYesterdayTaskRecord() ([]*domain.TaskRecord, error) {
func getYesterdayTaskRecord(nowDay string) ([]*domain.TaskRecord, error) {
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, err
... ... @@ -89,7 +90,7 @@ func getYesterdayTaskRecord() ([]*domain.TaskRecord, error) {
_ = transactionContext.RollbackTransaction()
}()
nowDay := time.Now().Format("2006-01-02")
// nowDay := time.Now().Format("2006-01-02")
nowDayTime, _ := time.ParseInLocation("2006-01-02", nowDay, time.Local)
yesterday := nowDayTime.Add(-23 * time.Hour).Format("2006-01-02")
... ...
package service
import (
"testing"
)
func TestCheckYesterdayTaskRecord(t *testing.T) {
// nowDay := "2023-05-10"
// nowDay := "2023-05-11"
// nowDay := "2023-05-12"
// nowDay := "2023-05-13"
nowDay := "2023-05-14"
taskRecordList, err := getYesterdayTaskRecord(nowDay)
if err != nil {
t.Log("获取每日任务反馈" + err.Error())
}
for _, val := range taskRecordList {
err = checkTaskRecord(val)
if err != nil {
t.Log("检查每日任务反馈" + err.Error())
}
}
}
... ...