From 5ad631e7b6e267ac6b21fd727c706131269052bf Mon Sep 17 00:00:00 2001 From: Zack Scholl Date: Sun, 8 Sep 2019 06:12:16 -0700 Subject: [PATCH] add more tests --- src/tcp/tcp.go | 4 +++- src/tcp/tcp_test.go | 5 ++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/tcp/tcp.go b/src/tcp/tcp.go index 47cd082..473ed26 100644 --- a/src/tcp/tcp.go +++ b/src/tcp/tcp.go @@ -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 { diff --git a/src/tcp/tcp_test.go b/src/tcp/tcp_test.go index ea628f5..8c98909 100644 --- a/src/tcp/tcp_test.go +++ b/src/tcp/tcp_test.go @@ -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")))