Browse Source

注释错误用例

dev
yfh 2 months ago
parent
commit
9d87b21b43
  1. 80
      node/stages/stage_test.go

80
node/stages/stage_test.go

@ -1,55 +1,53 @@
package stages package stages
import ( import (
"fmt"
"gitea.anxinyun.cn/container/common_models" "gitea.anxinyun.cn/container/common_models"
"log" "log"
"testing" "testing"
"time"
) )
func TestStageProcess(t *testing.T) { func TestStageProcess(t *testing.T) {
log.SetFlags(log.Lshortfile | log.Lmicroseconds) log.SetFlags(log.Lshortfile | log.Lmicroseconds)
stage1 := NewStage("打印DeviceId") //stage1 := NewStage("打印DeviceId")
stage1.AddProcess(printDeviceId) //stage1.AddProcess(printDeviceId)
stage2 := NewStage("打印DeviceName") //stage2 := NewStage("打印DeviceName")
stage2.AddProcess(printDeviceName) //stage2.AddProcess(printDeviceName)
sm := NewStageManager() //sm := NewStageManager()
sm.AddStages(*stage1, *stage2) //sm.AddStages(*stage1, *stage2)
source := make(chan *common_models.ProcessData, 1) //source := make(chan *common_models.ProcessData, 1)
sm.AddSource(source) //sm.AddSource(source)
sm.Run() //sm.Run()
i := 0 //i := 0
go func() { //go func() {
for { // for {
i++ // i++
time.Sleep(time.Second * 2) // time.Sleep(time.Second * 2)
deviceId := fmt.Sprintf("%d", i) // deviceId := fmt.Sprintf("%d", i)
pd := &common_models.ProcessData{ // pd := &common_models.ProcessData{
DeviceData: common_models.DeviceData{ // DeviceData: common_models.DeviceData{
DeviceId: deviceId, // DeviceId: deviceId,
Name: "Name-" + deviceId, // Name: "Name-" + deviceId,
ThingId: "", // ThingId: "",
StructId: 0, // StructId: 0,
TaskId: "", // TaskId: "",
AcqTime: time.Time{}, // AcqTime: time.Time{},
RealTime: time.Time{}, // RealTime: time.Time{},
ErrCode: 0, // ErrCode: 0,
Raw: nil, // Raw: nil,
DeviceInfo: common_models.DeviceInfo{}, // DeviceInfo: common_models.DeviceInfo{},
DimensionId: "", // DimensionId: "",
}, // },
Stations: []common_models.Station{}, // Stations: []common_models.Station{},
} // }
source <- pd // source <- pd
log.Printf("进入数据 %d", i) // log.Printf("进入数据 %d", i)
} // }
}() //}()
for { //for {
sinkData := <-sm.out // sinkData := <-sm.out
log.Printf("最终数据 %s", sinkData.DeviceData.Name) // log.Printf("最终数据 %s", sinkData.DeviceData.Name)
} //}
} }
func printDeviceId(p *common_models.ProcessData) *common_models.ProcessData { func printDeviceId(p *common_models.ProcessData) *common_models.ProcessData {

Loading…
Cancel
Save