mirror of
https://github.com/schollz/croc.git
synced 2025-10-11 13:21:00 +02:00
fix test
This commit is contained in:
parent
2414593c91
commit
9030aae880
2 changed files with 29 additions and 34 deletions
|
@ -1,6 +1,8 @@
|
||||||
package tcp
|
package tcp
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
@ -209,3 +211,30 @@ func pipe(conn1 net.Conn, conn2 net.Conn) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
func ConnectToTCPServer(address, room string) (c *comm.Comm, err error) {
|
||||||
|
c, err = comm.NewConnection("localhost:8081")
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
data, err := c.Receive()
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if !bytes.Equal(data, []byte("ok")) {
|
||||||
|
err = fmt.Errorf("got bad response: %s", data)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
err = c.Send([]byte(room))
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
data, err = c.Receive()
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if !bytes.Equal(data, []byte("ok")) {
|
||||||
|
err = fmt.Errorf("got bad response: %s", data)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
|
@ -1,12 +1,9 @@
|
||||||
package tcp
|
package tcp
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"fmt"
|
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/schollz/croc/src/comm"
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -34,35 +31,4 @@ func TestTCP(t *testing.T) {
|
||||||
|
|
||||||
c1.Close()
|
c1.Close()
|
||||||
assert.True(t, c1.IsClosed())
|
assert.True(t, c1.IsClosed())
|
||||||
|
|
||||||
time.Sleep(200 * time.Millisecond)
|
|
||||||
assert.True(t, c2.IsClosed())
|
|
||||||
}
|
|
||||||
|
|
||||||
func ConnectToTCPServer(address, room string) (c *comm.Comm, err error) {
|
|
||||||
c, err = comm.NewConnection("localhost:8081")
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
data, err := c.Receive()
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if !bytes.Equal(data, []byte("ok")) {
|
|
||||||
err = fmt.Errorf("got bad response: %s", data)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
err = c.Send([]byte(room))
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
data, err = c.Receive()
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if !bytes.Equal(data, []byte("ok")) {
|
|
||||||
err = fmt.Errorf("got bad response: %s", data)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue