netpool test. wip
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user