major refactor
This commit is contained in:
@@ -2,37 +2,19 @@ package main
|
||||
|
||||
import "testing"
|
||||
|
||||
type StringData string
|
||||
|
||||
func (s StringData) ToBytes() []byte {
|
||||
return []byte(s)
|
||||
}
|
||||
|
||||
func (s StringData) FromBytes(data []byte) error {
|
||||
s = StringData(data)
|
||||
return nil
|
||||
}
|
||||
|
||||
func TestGenericConnection(t *testing.T) {
|
||||
conn := NewConnection("localhost:51337")
|
||||
listener, err := conn.Listen()
|
||||
if err != nil {
|
||||
t.Errorf("Error listening: %v\n", err)
|
||||
}
|
||||
listener.AddHandler(1, func(input *FrameWithPayload, resultChan chan<- *FrameWithPayload) error {
|
||||
payload := []byte("Hello, world!")
|
||||
resultChan <- &FrameWithPayload{
|
||||
Frame: Frame{
|
||||
Type: 2,
|
||||
Id: input.Id,
|
||||
StatusCode: 200,
|
||||
Length: uint32(len("Hello, world!")),
|
||||
},
|
||||
Payload: payload,
|
||||
}
|
||||
datta := []byte("Hello, world!")
|
||||
listener.AddHandler(1, func(input *FrameWithPayload, resultChan chan<- FrameWithPayload) error {
|
||||
|
||||
resultChan <- MakeFrameWithPayload(2, 200, datta)
|
||||
return nil
|
||||
})
|
||||
r, err := conn.Call(1, StringData("Hello, world!"))
|
||||
r, err := conn.Call(1, datta)
|
||||
if err != nil {
|
||||
t.Errorf("Error calling: %v\n", err)
|
||||
}
|
||||
@@ -40,9 +22,9 @@ func TestGenericConnection(t *testing.T) {
|
||||
t.Errorf("Expected type 2, got %d\n", r.Type)
|
||||
}
|
||||
i := 100
|
||||
results := make(chan *FrameWithPayload, i)
|
||||
results := make(chan FrameWithPayload, i)
|
||||
for i > 0 {
|
||||
conn.CallAsync(1, StringData("Hello, world!"), results)
|
||||
go conn.CallAsync(1, datta, results)
|
||||
i--
|
||||
}
|
||||
for i < 100 {
|
||||
|
||||
Reference in New Issue
Block a user