96 lines
1.8 KiB
Go
96 lines
1.8 KiB
Go
package fusenrender_test
|
|
|
|
import (
|
|
"fmt"
|
|
"fusenrender"
|
|
"io"
|
|
"log"
|
|
"net/http"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/474420502/requests"
|
|
)
|
|
|
|
func TestWebsocketA(t *testing.T) {
|
|
svc, err := fusenrender.LoadConfig("etc/etc_a.yaml")
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
fusenrender.StartNode(svc)
|
|
|
|
}
|
|
|
|
func TestWebsocketB(t *testing.T) {
|
|
svc, err := fusenrender.LoadConfig("etc/etc_b.yaml")
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
fusenrender.StartNode(svc)
|
|
|
|
}
|
|
|
|
func TestWebsocketC(t *testing.T) {
|
|
svc, err := fusenrender.LoadConfig("etc/etc_c.yaml")
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
fusenrender.StartNode(svc)
|
|
|
|
}
|
|
|
|
var addr = "localhost:4052"
|
|
|
|
func TestWebsocketCient(t *testing.T) {
|
|
// 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()
|
|
|
|
go func() {
|
|
C := time.NewTicker(time.Second * 5)
|
|
for range C.C {
|
|
item := fusenrender.QueueItem{
|
|
Group: "test",
|
|
Wid: fusenrender.UidCreater.Get(),
|
|
CreateAt: time.Now(),
|
|
Data: sendjson,
|
|
}
|
|
r, err := requests.Post(fmt.Sprintf("http://%s/api/queue/push", addr)).SetBodyJson(item).Execute()
|
|
log.Println(r, err)
|
|
}
|
|
}()
|
|
|
|
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) {
|
|
http.HandleFunc("/api/websocket/render_notify", func(w http.ResponseWriter, r *http.Request) {
|
|
data, _ := io.ReadAll(r.Body)
|
|
log.Println(string(data))
|
|
})
|
|
log.Println(fmt.Sprintf(":%d", 4444))
|
|
http.ListenAndServe(fmt.Sprintf(":%d", 4444), nil)
|
|
}
|