mirror of https://github.com/schollz/croc.git
add more tests
This commit is contained in:
parent
cc728a1138
commit
5ad631e7b6
|
@ -33,6 +33,8 @@ type roomMap struct {
|
|||
sync.Mutex
|
||||
}
|
||||
|
||||
var timeToRoomDeletion = 10 * time.Minute
|
||||
|
||||
// Run starts a tcp listener, run async
|
||||
func Run(debugLevel, port string, banner ...string) (err error) {
|
||||
s := new(server)
|
||||
|
@ -53,7 +55,7 @@ func (s *server) start() (err error) {
|
|||
// delete old rooms
|
||||
go func() {
|
||||
for {
|
||||
time.Sleep(10 * time.Minute)
|
||||
time.Sleep(timeToRoomDeletion)
|
||||
roomsToDelete := []string{}
|
||||
s.rooms.Lock()
|
||||
for room := range s.rooms.rooms {
|
||||
|
|
|
@ -8,15 +8,18 @@ import (
|
|||
)
|
||||
|
||||
func TestTCP(t *testing.T) {
|
||||
timeToRoomDeletion = 100 * time.Millisecond
|
||||
go Run("debug", "8281", "8282")
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
c1, banner, _, err := ConnectToTCPServer("localhost:8281", "testRoom")
|
||||
c1, banner, _, err := ConnectToTCPServer("localhost:8281", "testRoom", 1*time.Minute)
|
||||
assert.Equal(t, banner, "8282")
|
||||
assert.Nil(t, err)
|
||||
c2, _, _, err := ConnectToTCPServer("localhost:8281", "testRoom")
|
||||
assert.Nil(t, err)
|
||||
_, _, _, err = ConnectToTCPServer("localhost:8281", "testRoom")
|
||||
assert.NotNil(t, err)
|
||||
_, _, _, err = ConnectToTCPServer("localhost:8281", "testRoom", 1*time.Nanosecond)
|
||||
assert.NotNil(t, err)
|
||||
|
||||
// try sending data
|
||||
assert.Nil(t, c1.Send([]byte("hello, c2")))
|
||||
|
|
Loading…
Reference in New Issue