<commit_before># -*- coding: utf-8 -*-

import pytest
import time
import functools
import zmq
from ..client import Client
from zeeko.conftest import assert_canrecv

def test_client_attributes(context, address):
    """Test client attributes defaults."""
    c = Client(context, address)
    assert c.counter == 0
    assert c.delay == 0
    assert c.maxlag == 10.0
    c.maxlag = 20
    assert c.maxlag == 20.0
    
def test_client_run(context, address, Publisher):
    """Test a client."""
    push = context.socket(zmq.PUSH)
    push.bind(address)
    
    c = Client(context, address, zmq.PULL)
    c.start()
    try:
        time.sleep(0.1)
        Publisher.publish(push)
        Publisher.publish(push)
        Publisher.publish(push)
        time.sleep(1.0)
    finally:
        c.stop()
    assert c.counter == 3
    assert len(c) == 3<commit_msg>Tests for snail death in client<commit_after># -*- coding: utf-8 -*-

import pytest
import time
import functools
import zmq
from ..client import Client
from zeeko.conftest import assert_canrecv

def test_client_attributes(context, address):
    """Test client attributes defaults."""
    c = Client(context, address)
    assert c.counter == 0
    assert c.delay == 0
    assert c.maxlag == 10.0
    c.maxlag = 20
    assert c.maxlag == 20.0
    
def test_client_run(context, address, Publisher):
    """Test a client."""
    push = context.socket(zmq.PUSH)
    push.bind(address)
    
    c = Client(context, address, zmq.PULL)
    c.start()
    try:
        time.sleep(0.01)
        Publisher.publish(push)
        Publisher.publish(push)
        Publisher.publish(push)
        time.sleep(0.01)
    finally:
        c.stop()
    assert c.counter == 3
    assert len(c) == 3

def test_client_snail_death(context, address, Publisher):
    """Test client snail death."""
    pub = context.socket(zmq.PUB)
    pub.bind(address)
    
    c = Client(context, address, zmq.SUB)
    c.maxlag = 0.0
    c.start()
    time.sleep(0.01)
    try:
        # First message gets recieved
        Publisher.publish(pub, zmq.NOBLOCK)
        # Nth one should get dropped, b/c other side disconnects.
        Publisher.publish(pub, zmq.NOBLOCK)
        Publisher.publish(pub, zmq.NOBLOCK)
        time.sleep(0.01)
        assert c.state == 'PAUSE'
    finally:
        c.stop()
    assert c.counter == 1
    assert len(c) == 3
{'fraction_non_alphanumeric': 0.12055837563451777, 'fraction_numerical': 0.0194585448392555, 'mean_word_length': 2.4882005899705013, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2958131', 'n_tokens_mistral': 809, 'n_tokens_neox': 775, 'n_words': 199}