1
0
mirror of https://github.com/schollz/croc.git synced 2024-11-28 09:35:14 +03:00

better cleaning of empty rooms

This commit is contained in:
Zack Scholl 2019-05-02 20:57:55 -07:00
parent 1802ebcd00
commit 7d91f8200c
2 changed files with 7 additions and 4 deletions

View File

@ -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)
}
}
}()

View File

@ -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)