diff --git a/src/tcp/tcp.go b/src/tcp/tcp.go index 14a37fc..441367b 100644 --- a/src/tcp/tcp.go +++ b/src/tcp/tcp.go @@ -55,13 +55,18 @@ func (s *server) start() (err error) { go func() { for { time.Sleep(10 * time.Minute) + roomsToDelete := []string{} s.rooms.Lock() for room := range s.rooms.rooms { if time.Since(s.rooms.rooms[room].opened) > 3*time.Hour { - delete(s.rooms.rooms, room) + roomsToDelete = append(roomsToDelete,room) } } s.rooms.Unlock() + + for _, room := range roomsToDelete { + s.deleteRoom(room) + } } }() diff --git a/src/tcp/tcp_test.go b/src/tcp/tcp_test.go index 99dce45..46bcee1 100644 --- a/src/tcp/tcp_test.go +++ b/src/tcp/tcp_test.go @@ -1,7 +1,6 @@ package tcp import ( - "strings" "testing" "time" @@ -11,9 +10,8 @@ import ( func TestTCP(t *testing.T) { go Run("debug", "8081", "8082") time.Sleep(100 * time.Millisecond) - c1, banner, ipaddr, err := ConnectToTCPServer("localhost:8081", "testRoom") + c1, banner, _, err := ConnectToTCPServer("localhost:8081", "testRoom") assert.Equal(t, banner, "8082") - assert.True(t, strings.HasPrefix(ipaddr, "127.0.0.1")) assert.Nil(t, err) c2, _, _, err := ConnectToTCPServer("localhost:8081", "testRoom") assert.Nil(t, err)