def test_gc_connections_collecting(self, test_uuids):
     server_state = get_state()
     channel = Channel("test")
     server_state.channels[channel.name] = channel
     channel2 = Channel("test2")
     server_state.channels[channel2.name] = channel2
     user = User("test_user")
     server_state.users[user.username] = user
     user2 = User("test_user2")
     server_state.users[user2.username] = user2
     connection = Connection("test_user", test_uuids[1])
     server_state.connections[connection.id] = connection
     connection2 = Connection("test_user", test_uuids[2])
     connection2.mark_for_gc()
     server_state.connections[connection2.id] = connection2
     connection3 = Connection("test_user2", test_uuids[3])
     connection3.mark_for_gc()
     server_state.connections[connection3.id] = connection3
     connection4 = Connection("test_user2", test_uuids[4])
     server_state.connections[connection4.id] = connection4
     user.add_connection(connection)
     user.add_connection(connection2)
     channel.add_connection(connection)
     channel.add_connection(connection2)
     user2.add_connection(connection3)
     user2.add_connection(connection4)
     channel2.add_connection(connection3)
     channel2.add_connection(connection4)
     channelstream.gc.gc_conns()
     assert len(server_state.connections.items()) == 2
     conns = server_state.channels["test"].connections["test_user"]
     assert len(conns) == 1
     assert conns == [connection]
     conns = server_state.channels["test2"].connections["test_user2"]
     assert len(conns) == 1
     assert conns == [connection4]
     assert len(user.connections) == 1
     assert len(user2.connections) == 1
     connection.mark_for_gc()
     connection4.mark_for_gc()
     channelstream.gc.gc_conns()
     assert "test_user" not in server_state.channels["test"].connections
     assert "test_user2" not in server_state.channels["test2"].connections
     assert len(server_state.channels["test"].connections.items()) == 0
     assert len(server_state.channels["test2"].connections.items()) == 0
Exemple #2
0
 def test_gc_connections_collecting(self, test_uuids):
     server_state = get_state()
     channel = Channel("test")
     server_state.channels[channel.name] = channel
     channel2 = Channel("test2")
     server_state.channels[channel2.name] = channel2
     user = User("test_user")
     server_state.users[user.username] = user
     user2 = User("test_user2")
     server_state.users[user2.username] = user2
     connection = Connection("test_user", test_uuids[1])
     server_state.connections[connection.id] = connection
     connection2 = Connection("test_user", test_uuids[2])
     connection2.mark_for_gc()
     server_state.connections[connection2.id] = connection2
     connection3 = Connection("test_user2", test_uuids[3])
     connection3.mark_for_gc()
     server_state.connections[connection3.id] = connection3
     connection4 = Connection("test_user2", test_uuids[4])
     server_state.connections[connection4.id] = connection4
     user.add_connection(connection)
     user.add_connection(connection2)
     channel.add_connection(connection)
     channel.add_connection(connection2)
     user2.add_connection(connection3)
     user2.add_connection(connection4)
     channel2.add_connection(connection3)
     channel2.add_connection(connection4)
     channelstream.gc.gc_conns()
     assert len(server_state.connections.items()) == 2
     conns = server_state.channels["test"].connections["test_user"]
     assert len(conns) == 1
     assert conns == [connection]
     conns = server_state.channels["test2"].connections["test_user2"]
     assert len(conns) == 1
     assert conns == [connection4]
     assert len(user.connections) == 1
     assert len(user2.connections) == 1
     connection.mark_for_gc()
     connection4.mark_for_gc()
     channelstream.gc.gc_conns()
     assert "test_user" not in server_state.channels["test"].connections
     assert "test_user2" not in server_state.channels["test2"].connections
     assert len(server_state.channels["test"].connections.items()) == 0
     assert len(server_state.channels["test2"].connections.items()) == 0
 def test_mark_for_gc(self, test_uuids):
     long_time_ago = datetime.utcnow() - timedelta(days=50)
     connection = Connection("test", test_uuids[1])
     connection.mark_for_gc()
     assert connection.last_active < long_time_ago
Exemple #4
0
 def test_mark_for_gc(self, test_uuids):
     long_time_ago = datetime.utcnow() - timedelta(days=50)
     connection = Connection("test", test_uuids[1])
     connection.mark_for_gc()
     assert connection.last_active < long_time_ago