-
Notifications
You must be signed in to change notification settings - Fork 271
/
server_test.go
61 lines (54 loc) · 1.19 KB
/
server_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package main
import (
"testing"
"time"
"fmt"
"encoding/json"
"strings"
"io/ioutil"
"github.com/EndlessCheng/mahjong-helper/util/debug"
)
func Test_mjHandler_runAnalysisMajsoulMessageTask(t *testing.T) {
debugMode = true
logFile := "log/gamedata.log"
startLo := 33020
endLo := 33369
h := &mjHandler{
majsoulMessageQueue: make(chan []byte, 10000),
majsoulRoundData: &majsoulRoundData{},
majsoulRecordMap: map[string]*majsoulRecordBaseInfo{},
}
h.majsoulRoundData.roundData = newGame(h.majsoulRoundData)
s := struct {
Level string `json:"level"`
Message string `json:"message"`
}{}
logData, err := ioutil.ReadFile(logFile)
if err != nil {
t.Fatal(err)
}
lines := strings.Split(string(logData), "\n")
for i, line := range lines[startLo-1 : endLo] {
debug.Lo = i + 1
if line == "" {
continue
}
if err := json.Unmarshal([]byte(line), &s); err != nil {
fmt.Println(err)
continue
}
if s.Level != "INFO" {
fmt.Println(s.Level, s.Message)
//t.Fatal(s.Message)
break
}
h.majsoulMessageQueue <- []byte([]byte(s.Message))
}
go h.runAnalysisMajsoulMessageTask()
for {
if len(h.majsoulMessageQueue) == 0 {
break
}
time.Sleep(time.Second)
}
}