2023-08-03 10:34:20 +00:00
|
|
|
package fusenrender_test
|
|
|
|
|
|
|
|
import (
|
2023-08-16 06:04:08 +00:00
|
|
|
"encoding/json"
|
2023-08-03 10:34:20 +00:00
|
|
|
"fmt"
|
|
|
|
"fusenrender"
|
2023-08-04 10:59:53 +00:00
|
|
|
"io"
|
2023-08-03 10:34:20 +00:00
|
|
|
"log"
|
2023-08-04 10:59:53 +00:00
|
|
|
"net/http"
|
2023-08-03 10:34:20 +00:00
|
|
|
"testing"
|
2023-08-04 10:59:53 +00:00
|
|
|
"time"
|
2023-08-03 10:34:20 +00:00
|
|
|
|
2023-08-04 10:59:53 +00:00
|
|
|
"github.com/474420502/requests"
|
2023-08-03 10:34:20 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestWebsocketA(t *testing.T) {
|
|
|
|
svc, err := fusenrender.LoadConfig("etc/etc_a.yaml")
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
2023-08-05 20:26:57 +00:00
|
|
|
fusenrender.StartNode(svc)
|
2023-08-03 10:34:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestWebsocketB(t *testing.T) {
|
|
|
|
svc, err := fusenrender.LoadConfig("etc/etc_b.yaml")
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2023-08-05 20:26:57 +00:00
|
|
|
fusenrender.StartNode(svc)
|
2023-08-03 10:34:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestWebsocketC(t *testing.T) {
|
|
|
|
svc, err := fusenrender.LoadConfig("etc/etc_c.yaml")
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2023-08-05 20:26:57 +00:00
|
|
|
fusenrender.StartNode(svc)
|
2023-08-03 10:34:20 +00:00
|
|
|
}
|
|
|
|
|
2023-08-16 07:29:30 +00:00
|
|
|
var addr = "api.fusen.3718.cn:4050"
|
|
|
|
|
|
|
|
// var addr = "localhost:4050"
|
2023-08-03 10:34:20 +00:00
|
|
|
|
|
|
|
func TestWebsocketCient(t *testing.T) {
|
2023-08-04 10:59:53 +00:00
|
|
|
// u := url.URL{Scheme: "ws", Host: addr, Path: "/ws/pop/queue"}
|
|
|
|
// conn, _, err := websocket.DefaultDialer.Dial(u.String(), nil)
|
|
|
|
// log.Println(err)
|
|
|
|
// defer conn.Close()
|
2023-08-16 06:04:08 +00:00
|
|
|
var m any
|
|
|
|
err := json.Unmarshal([]byte(sendjson), &m)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2023-08-04 10:59:53 +00:00
|
|
|
|
|
|
|
go func() {
|
|
|
|
C := time.NewTicker(time.Second * 5)
|
|
|
|
for range C.C {
|
|
|
|
item := fusenrender.QueueItem{
|
2023-08-16 03:42:49 +00:00
|
|
|
Group: "unity3d",
|
|
|
|
|
2023-08-04 10:59:53 +00:00
|
|
|
CreateAt: time.Now(),
|
2023-08-16 06:04:08 +00:00
|
|
|
Data: m,
|
2023-08-04 10:59:53 +00:00
|
|
|
}
|
2023-08-16 03:42:49 +00:00
|
|
|
r, err := requests.Post(fmt.Sprintf("http://%s/api/render/queue/push", addr)).SetBodyJson(item).Execute()
|
2023-08-04 10:59:53 +00:00
|
|
|
log.Println(r, err)
|
2023-08-03 10:34:20 +00:00
|
|
|
}
|
2023-08-04 10:59:53 +00:00
|
|
|
}()
|
2023-08-03 10:34:20 +00:00
|
|
|
|
2023-08-04 10:59:53 +00:00
|
|
|
select {}
|
|
|
|
|
|
|
|
// for {
|
|
|
|
|
|
|
|
// // err = conn.WriteMessage(websocket.PingMessage, nil)
|
|
|
|
// // log.Println("write ping")
|
|
|
|
// // if err != nil {
|
|
|
|
// // log.Println(err)
|
|
|
|
// // return
|
|
|
|
// // }
|
|
|
|
|
|
|
|
// mt, msg, err := conn.ReadMessage()
|
|
|
|
// fmt.Println(mt, err)
|
|
|
|
// if mt == websocket.CloseMessage {
|
|
|
|
// return
|
|
|
|
// }
|
|
|
|
// fmt.Printf("Received: %s\n", string(msg))
|
|
|
|
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCallback(t *testing.T) {
|
2023-08-07 11:03:22 +00:00
|
|
|
http.HandleFunc("/api/render/render_notify", func(w http.ResponseWriter, r *http.Request) {
|
2023-08-04 10:59:53 +00:00
|
|
|
data, _ := io.ReadAll(r.Body)
|
|
|
|
log.Println(string(data))
|
|
|
|
})
|
|
|
|
log.Println(fmt.Sprintf(":%d", 4444))
|
|
|
|
http.ListenAndServe(fmt.Sprintf(":%d", 4444), nil)
|
2023-08-03 10:34:20 +00:00
|
|
|
}
|