netpool test. wip
All checks were successful
Build and Publish / BuildAndDeployAmd64 (push) Successful in 32s
Build and Publish / BuildAndDeploy (push) Successful in 3m2s

This commit is contained in:
matst80
2024-11-21 21:23:38 +01:00
parent 1f7f161e62
commit 5348c33f3b
11 changed files with 140 additions and 89 deletions

View File

@@ -1,16 +1,27 @@
package main
import (
"fmt"
"net"
"testing"
"github.com/yudhasubki/netpool"
)
func TestGenericConnection(t *testing.T) {
conn := NewConnection("localhost:51337")
listener, err := conn.Listen()
listenConn := NewConnection("127.0.0.1:51337", nil)
listener, err := listenConn.Listen()
if err != nil {
t.Errorf("Error listening: %v\n", err)
}
pool, err := netpool.New(func() (net.Conn, error) {
return net.Dial("tcp", "127.0.0.1:51337")
}, netpool.WithMaxPool(512))
if err != nil {
t.Errorf("Error creating pool: %v\n", err)
}
conn := NewConnection("127.0.0.1:51337", pool)
datta := []byte("Hello, world!")
listener.AddHandler(Ping, func(input *FrameWithPayload, resultChan chan<- FrameWithPayload) error {
resultChan <- MakeFrameWithPayload(Pong, 200, nil)
@@ -21,7 +32,8 @@ func TestGenericConnection(t *testing.T) {
return nil
})
listener.AddHandler(3, func(input *FrameWithPayload, resultChan chan<- FrameWithPayload) error {
return fmt.Errorf("Error")
resultChan <- MakeFrameWithPayload(2, 200, datta)
return nil //fmt.Errorf("Error")
})
r, err := conn.Call(1, datta)
if err != nil {